diff options
author | Michael Brown | 2013-11-01 03:22:12 +0100 |
---|---|---|
committer | Michael Brown | 2013-11-01 03:26:19 +0100 |
commit | 5e1fa5cd4090f229a40903f13abf328e86271717 (patch) | |
tree | 77a6302aeeb86f6c86fe95fb757a952a4ef7490e /src/usr | |
parent | [ipv6] Add ndp_tx_router_solicitation() to send router solicitations (diff) | |
download | ipxe-5e1fa5cd4090f229a40903f13abf328e86271717.tar.gz ipxe-5e1fa5cd4090f229a40903f13abf328e86271717.tar.xz ipxe-5e1fa5cd4090f229a40903f13abf328e86271717.zip |
[parseopt] Add parse_timeout()
Parsing a timeout value (specified in milliseconds) into an internal
timeout value measured in timer ticks is a common operation. Provide
a parse_timeout() value to carry out this conversion automatically.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/usr')
-rw-r--r-- | src/usr/pingmgmt.c | 7 | ||||
-rw-r--r-- | src/usr/prompt.c | 7 |
2 files changed, 6 insertions, 8 deletions
diff --git a/src/usr/pingmgmt.c b/src/usr/pingmgmt.c index e4559382..0db10c21 100644 --- a/src/usr/pingmgmt.c +++ b/src/usr/pingmgmt.c @@ -56,16 +56,15 @@ static void ping_callback ( struct sockaddr *peer, unsigned int sequence, * Ping a host * * @v hostname Hostname - * @v timeout_ms Timeout between pings, in ms + * @v timeout Timeout between pings, in ticks * @v len Payload length * @ret rc Return status code */ -int ping ( const char *hostname, unsigned long timeout_ms, size_t len ) { +int ping ( const char *hostname, unsigned long timeout, size_t len ) { int rc; /* Create pinger */ - if ( ( rc = create_pinger ( &monojob, hostname, - ( ( timeout_ms * TICKS_PER_SEC ) / 1000 ), + if ( ( rc = create_pinger ( &monojob, hostname, timeout, len, ping_callback ) ) != 0 ) { printf ( "Could not start ping: %s\n", strerror ( rc ) ); return rc; diff --git a/src/usr/prompt.c b/src/usr/prompt.c index ede03745..957b4ab3 100644 --- a/src/usr/prompt.c +++ b/src/usr/prompt.c @@ -28,28 +28,27 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include <errno.h> #include <stdio.h> #include <ipxe/console.h> -#include <ipxe/timer.h> #include <usr/prompt.h> /** * Prompt for keypress * * @v text Prompt string - * @v wait_ms Time to wait, in milliseconds (0=indefinite) + * @v timeout Timeout period, in ticks (0=indefinite) * @v key Key to wait for (0=any key) * @ret rc Return status code * * Returns success if the specified key was pressed within the * specified timeout period. */ -int prompt ( const char *text, unsigned int wait_ms, int key ) { +int prompt ( const char *text, unsigned long timeout, int key ) { int key_pressed; /* Display prompt */ printf ( "%s", text ); /* Wait for key */ - key_pressed = getkey ( ( wait_ms * TICKS_PER_SEC ) / 1000 ); + key_pressed = getkey ( timeout ); /* Clear the prompt line */ while ( *(text++) ) |