[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>
This commit is contained in:
Michael Brown
2013-11-01 02:22:12 +00:00
parent b15dbc9cc6
commit 5e1fa5cd40
12 changed files with 46 additions and 27 deletions
+3 -4
View File
@@ -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;