Skip to content

Commit

Permalink
[ping] Report timed-out pings via the callback function
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
mcb30 committed Oct 23, 2014
1 parent af17abf commit d1afe73
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/core/pinger.c
Expand Up @@ -68,10 +68,12 @@ struct pinger {
size_t len;
/** Current sequence number */
uint16_t sequence;
/** Response for current sequence number is still pending */
int pending;

/** Callback function
*
* @v src Source socket address
* @v src Source socket address, or NULL
* @v sequence Sequence number
* @v len Payload length
* @v rc Status code
Expand Down Expand Up @@ -159,6 +161,11 @@ static void pinger_expired ( struct retry_timer *timer, int over __unused ) {
struct io_buffer *iobuf;
int rc;

/* If no response has been received, notify the callback function */
if ( pinger->pending )
pinger->callback ( NULL, pinger->sequence, 0, -ETIMEDOUT );
pinger->pending = 1;

/* Increase sequence number */
pinger->sequence++;

Expand Down Expand Up @@ -205,6 +212,10 @@ static int pinger_deliver ( struct pinger *pinger, struct io_buffer *iobuf,
uint16_t sequence = meta->offset;
int rc;

/* Clear response pending flag, if applicable */
if ( sequence == pinger->sequence )
pinger->pending = 0;

/* Check for errors */
if ( len != pinger->len ) {
DBGC ( pinger, "PINGER %p received incorrect length %zd "
Expand Down
4 changes: 2 additions & 2 deletions src/usr/pingmgmt.c
Expand Up @@ -36,7 +36,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
/**
* Display ping result
*
* @v src Source socket address
* @v src Source socket address, or NULL
* @v sequence Sequence number
* @v len Payload length
* @v rc Status code
Expand All @@ -46,7 +46,7 @@ static void ping_callback ( struct sockaddr *peer, unsigned int sequence,

/* Display ping response */
printf ( "%zd bytes from %s: seq=%d",
len, sock_ntoa ( peer ), sequence );
len, ( peer ? sock_ntoa ( peer ) : "<none>" ), sequence );
if ( rc != 0 )
printf ( ": %s", strerror ( rc ) );
printf ( "\n" );
Expand Down

0 comments on commit d1afe73

Please sign in to comment.