-
Notifications
You must be signed in to change notification settings - Fork 1.3k
修复ping时统计异常的问题 #385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
修复ping时统计异常的问题 #385
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -10,7 +10,7 @@ int ping(const char* host, int cnt) { | |||
| static uint16_t seq = 0; | ||||
| uint16_t pid16 = (uint16_t)getpid(); | ||||
| char ip[64] = {0}; | ||||
| uint32_t start_tick, end_tick; | ||||
| uint32_t start_tick, end_tick, cur_ping_start_tick; | ||||
| uint64_t start_hrtime, end_hrtime; | ||||
| int timeout = 0; | ||||
| int sendbytes = 64; | ||||
|
|
@@ -64,7 +64,9 @@ int ping(const char* host, int cnt) { | |||
| icmp_req->icmp_data[i] = i; | ||||
| } | ||||
| start_tick = gettick_ms(); | ||||
|
|
||||
| while (cnt-- > 0) { | ||||
| cur_ping_start_tick = gettick_ms(); | ||||
| // NOTE: checksum | ||||
| icmp_req->icmp_seq = ++seq; | ||||
| icmp_req->icmp_cksum = 0; | ||||
|
|
@@ -78,29 +80,38 @@ int ping(const char* host, int cnt) { | |||
| } | ||||
| ++send_cnt; | ||||
| addrlen = sizeof(peeraddr); | ||||
| _read_again: | ||||
| if(gettick_ms() - cur_ping_start_tick >= PING_TIMEOUT) { | ||||
| // recv timeout, send ping again. | ||||
| continue; | ||||
| } | ||||
|
|
||||
| int nrecv = recvfrom(sockfd, recvbuf, sizeof(recvbuf), 0, &peeraddr.sa, &addrlen); | ||||
| if (nrecv < 0) { | ||||
|
Comment on lines
+83
to
90
|
||||
| perror("recvfrom"); | ||||
| continue; | ||||
| goto _read_again; | ||||
|
Comment on lines
89
to
+92
|
||||
| } | ||||
| ++recv_cnt; | ||||
|
|
||||
| end_hrtime = gethrtime_us(); | ||||
|
||||
| end_hrtime = gethrtime_us(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的代码风格与本文件其他 if 语句不一致:使用了
if(而不是if (。建议保持一致的空格风格。