david/ipxe
david
/
ipxe
Archived
1
0
Fork 0

[ping] Report timed-out pings via the callback function

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown 2014-10-23 15:04:10 +01:00
parent af17abf67f
commit d1afe731ea
2 changed files with 14 additions and 3 deletions

View File

@ -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
@ -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++;
@ -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 "

View File

@ -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
@ -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" );