Browse Source

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

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 10 years ago
parent
commit
d1afe731ea
2 changed files with 14 additions and 3 deletions
  1. 12
    1
      src/core/pinger.c
  2. 2
    2
      src/usr/pingmgmt.c

+ 12
- 1
src/core/pinger.c View File

68
 	size_t len;
68
 	size_t len;
69
 	/** Current sequence number */
69
 	/** Current sequence number */
70
 	uint16_t sequence;
70
 	uint16_t sequence;
71
+	/** Response for current sequence number is still pending */
72
+	int pending;
71
 
73
 
72
 	/** Callback function
74
 	/** Callback function
73
 	 *
75
 	 *
74
-	 * @v src		Source socket address
76
+	 * @v src		Source socket address, or NULL
75
 	 * @v sequence		Sequence number
77
 	 * @v sequence		Sequence number
76
 	 * @v len		Payload length
78
 	 * @v len		Payload length
77
 	 * @v rc		Status code
79
 	 * @v rc		Status code
159
 	struct io_buffer *iobuf;
161
 	struct io_buffer *iobuf;
160
 	int rc;
162
 	int rc;
161
 
163
 
164
+	/* If no response has been received, notify the callback function */
165
+	if ( pinger->pending )
166
+		pinger->callback ( NULL, pinger->sequence, 0, -ETIMEDOUT );
167
+	pinger->pending = 1;
168
+
162
 	/* Increase sequence number */
169
 	/* Increase sequence number */
163
 	pinger->sequence++;
170
 	pinger->sequence++;
164
 
171
 
205
 	uint16_t sequence = meta->offset;
212
 	uint16_t sequence = meta->offset;
206
 	int rc;
213
 	int rc;
207
 
214
 
215
+	/* Clear response pending flag, if applicable */
216
+	if ( sequence == pinger->sequence )
217
+		pinger->pending = 0;
218
+
208
 	/* Check for errors */
219
 	/* Check for errors */
209
 	if ( len != pinger->len ) {
220
 	if ( len != pinger->len ) {
210
 		DBGC ( pinger, "PINGER %p received incorrect length %zd "
221
 		DBGC ( pinger, "PINGER %p received incorrect length %zd "

+ 2
- 2
src/usr/pingmgmt.c View File

36
 /**
36
 /**
37
  * Display ping result
37
  * Display ping result
38
  *
38
  *
39
- * @v src		Source socket address
39
+ * @v src		Source socket address, or NULL
40
  * @v sequence		Sequence number
40
  * @v sequence		Sequence number
41
  * @v len		Payload length
41
  * @v len		Payload length
42
  * @v rc		Status code
42
  * @v rc		Status code
46
 
46
 
47
 	/* Display ping response */
47
 	/* Display ping response */
48
 	printf ( "%zd bytes from %s: seq=%d",
48
 	printf ( "%zd bytes from %s: seq=%d",
49
-		 len, sock_ntoa ( peer ), sequence );
49
+		 len, ( peer ? sock_ntoa ( peer ) : "<none>" ), sequence );
50
 	if ( rc != 0 )
50
 	if ( rc != 0 )
51
 		printf ( ": %s", strerror ( rc ) );
51
 		printf ( ": %s", strerror ( rc ) );
52
 	printf ( "\n" );
52
 	printf ( "\n" );

Loading…
Cancel
Save