浏览代码

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

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 10 年前
父节点
当前提交
d1afe731ea
共有 2 个文件被更改,包括 14 次插入3 次删除
  1. 12
    1
      src/core/pinger.c
  2. 2
    2
      src/usr/pingmgmt.c

+ 12
- 1
src/core/pinger.c 查看文件

@@ -68,10 +68,12 @@ struct pinger {
68 68
 	size_t len;
69 69
 	/** Current sequence number */
70 70
 	uint16_t sequence;
71
+	/** Response for current sequence number is still pending */
72
+	int pending;
71 73
 
72 74
 	/** Callback function
73 75
 	 *
74
-	 * @v src		Source socket address
76
+	 * @v src		Source socket address, or NULL
75 77
 	 * @v sequence		Sequence number
76 78
 	 * @v len		Payload length
77 79
 	 * @v rc		Status code
@@ -159,6 +161,11 @@ static void pinger_expired ( struct retry_timer *timer, int over __unused ) {
159 161
 	struct io_buffer *iobuf;
160 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 169
 	/* Increase sequence number */
163 170
 	pinger->sequence++;
164 171
 
@@ -205,6 +212,10 @@ static int pinger_deliver ( struct pinger *pinger, struct io_buffer *iobuf,
205 212
 	uint16_t sequence = meta->offset;
206 213
 	int rc;
207 214
 
215
+	/* Clear response pending flag, if applicable */
216
+	if ( sequence == pinger->sequence )
217
+		pinger->pending = 0;
218
+
208 219
 	/* Check for errors */
209 220
 	if ( len != pinger->len ) {
210 221
 		DBGC ( pinger, "PINGER %p received incorrect length %zd "

+ 2
- 2
src/usr/pingmgmt.c 查看文件

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

正在加载...
取消
保存