diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-09-07 13:43:28 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-09-07 13:43:28 +0000 |
commit | 87f3b26b3a17369c12f4f9a70d6845796f8648d6 (patch) | |
tree | 2f7fe9fc910d5e97f695c902f848db497fec8bfd /networking | |
parent | 40f0bcf9d3f8f8a8d14a9b2cff51761019c75cf4 (diff) | |
download | busybox-w32-87f3b26b3a17369c12f4f9a70d6845796f8648d6.tar.gz busybox-w32-87f3b26b3a17369c12f4f9a70d6845796f8648d6.tar.bz2 busybox-w32-87f3b26b3a17369c12f4f9a70d6845796f8648d6.zip |
*: replace select-for-one descriptor with poll, it's smaller.
$ ./.cmk bloatcheck
function old new delta
readit 406 364 -42
syslogd_main 1249 1206 -43
traceroute_main 4115 4060 -55
mysleep 112 45 -67
arpping 579 441 -138
tftp 1575 1182 -393
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/6 up/down: 0/-738) Total: -738 bytes
text data bss dec hex filename
770580 1051 10764 782395 bf03b busybox_old
769820 1051 10764 781635 bed43 busybox_unstripped
Diffstat (limited to 'networking')
-rw-r--r-- | networking/tftp.c | 33 | ||||
-rw-r--r-- | networking/traceroute.c | 24 | ||||
-rw-r--r-- | networking/udhcp/arpping.c | 29 |
3 files changed, 37 insertions, 49 deletions
diff --git a/networking/tftp.c b/networking/tftp.c index 0b25f752d..ac3a86afb 100644 --- a/networking/tftp.c +++ b/networking/tftp.c | |||
@@ -23,10 +23,10 @@ | |||
23 | 23 | ||
24 | #if ENABLE_FEATURE_TFTP_GET || ENABLE_FEATURE_TFTP_PUT | 24 | #if ENABLE_FEATURE_TFTP_GET || ENABLE_FEATURE_TFTP_PUT |
25 | 25 | ||
26 | #define TFTP_BLOCKSIZE_DEFAULT 512 /* according to RFC 1350, don't change */ | 26 | #define TFTP_BLOCKSIZE_DEFAULT 512 /* according to RFC 1350, don't change */ |
27 | #define TFTP_TIMEOUT 50000 /* 50ms, in microseconds */ | 27 | #define TFTP_TIMEOUT_MS 50 |
28 | #define TFTP_MAXTIMEOUT 999000 /* about 1 second, in microseconds */ | 28 | #define TFTP_MAXTIMEOUT_MS 2000 |
29 | #define TFTP_NUM_RETRIES 12 /* number of backed-off retries */ | 29 | #define TFTP_NUM_RETRIES 12 /* number of backed-off retries */ |
30 | 30 | ||
31 | /* opcodes we support */ | 31 | /* opcodes we support */ |
32 | #define TFTP_RRQ 1 | 32 | #define TFTP_RRQ 1 |
@@ -114,9 +114,8 @@ static int tftp( USE_GETPUT(const int cmd,) | |||
114 | const char *remotefile, const int localfd, | 114 | const char *remotefile, const int localfd, |
115 | unsigned port, int tftp_bufsize) | 115 | unsigned port, int tftp_bufsize) |
116 | { | 116 | { |
117 | struct timeval tv; | 117 | struct pollfd pfd[1]; |
118 | fd_set rfds; | 118 | #define socketfd (pfd[0].fd) |
119 | int socketfd; | ||
120 | int len; | 119 | int len; |
121 | int send_len; | 120 | int send_len; |
122 | USE_FEATURE_TFTP_BLOCKSIZE(smallint want_option_ack = 0;) | 121 | USE_FEATURE_TFTP_BLOCKSIZE(smallint want_option_ack = 0;) |
@@ -124,7 +123,7 @@ static int tftp( USE_GETPUT(const int cmd,) | |||
124 | uint16_t opcode; | 123 | uint16_t opcode; |
125 | uint16_t block_nr = 1; | 124 | uint16_t block_nr = 1; |
126 | uint16_t recv_blk; | 125 | uint16_t recv_blk; |
127 | int retries, waittime; | 126 | int retries, waittime_ms; |
128 | char *cp; | 127 | char *cp; |
129 | 128 | ||
130 | unsigned org_port; | 129 | unsigned org_port; |
@@ -208,7 +207,7 @@ static int tftp( USE_GETPUT(const int cmd,) | |||
208 | * for potential resend */ | 207 | * for potential resend */ |
209 | 208 | ||
210 | retries = TFTP_NUM_RETRIES; /* re-initialize */ | 209 | retries = TFTP_NUM_RETRIES; /* re-initialize */ |
211 | waittime = TFTP_TIMEOUT; | 210 | waittime_ms = TFTP_TIMEOUT_MS; |
212 | 211 | ||
213 | send_again: | 212 | send_again: |
214 | #if ENABLE_DEBUG_TFTP | 213 | #if ENABLE_DEBUG_TFTP |
@@ -224,11 +223,9 @@ static int tftp( USE_GETPUT(const int cmd,) | |||
224 | 223 | ||
225 | recv_again: | 224 | recv_again: |
226 | /* Receive packet */ | 225 | /* Receive packet */ |
227 | tv.tv_sec = 0; | 226 | /*pfd[0].fd = socketfd;*/ |
228 | tv.tv_usec = waittime; | 227 | pfd[0].events = POLLIN; |
229 | FD_ZERO(&rfds); | 228 | switch (poll(pfd, 1, waittime_ms)) { |
230 | FD_SET(socketfd, &rfds); | ||
231 | switch (select(socketfd + 1, &rfds, NULL, NULL, &tv)) { | ||
232 | unsigned from_port; | 229 | unsigned from_port; |
233 | case 1: | 230 | case 1: |
234 | from->len = peer_lsa->len; | 231 | from->len = peer_lsa->len; |
@@ -258,14 +255,14 @@ static int tftp( USE_GETPUT(const int cmd,) | |||
258 | } | 255 | } |
259 | 256 | ||
260 | /* exponential backoff with limit */ | 257 | /* exponential backoff with limit */ |
261 | waittime += waittime/2; | 258 | waittime_ms += waittime_ms/2; |
262 | if (waittime > TFTP_MAXTIMEOUT) { | 259 | if (waittime_ms > TFTP_MAXTIMEOUT_MS) { |
263 | waittime = TFTP_MAXTIMEOUT; | 260 | waittime_ms = TFTP_MAXTIMEOUT_MS; |
264 | } | 261 | } |
265 | 262 | ||
266 | goto send_again; /* resend last sent pkt */ | 263 | goto send_again; /* resend last sent pkt */ |
267 | default: | 264 | default: |
268 | bb_perror_msg("select"); | 265 | bb_perror_msg("poll"); |
269 | goto ret; | 266 | goto ret; |
270 | } | 267 | } |
271 | process_pkt: | 268 | process_pkt: |
diff --git a/networking/traceroute.c b/networking/traceroute.c index 236ddbdaf..21921e56d 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c | |||
@@ -346,10 +346,10 @@ static int optlen; /* length of ip options */ | |||
346 | 346 | ||
347 | 347 | ||
348 | struct globals { | 348 | struct globals { |
349 | /* last inbound (icmp) packet */ | ||
350 | unsigned char packet[512]; | ||
351 | struct sockaddr_storage whereto; /* Who to try to reach */ | 349 | struct sockaddr_storage whereto; /* Who to try to reach */ |
352 | struct sockaddr_storage wherefrom; /* Who we are */ | 350 | struct sockaddr_storage wherefrom; /* Who we are */ |
351 | /* last inbound (icmp) packet */ | ||
352 | unsigned char packet[512]; | ||
353 | #if ENABLE_FEATURE_TRACEROUTE_SOURCE_ROUTE | 353 | #if ENABLE_FEATURE_TRACEROUTE_SOURCE_ROUTE |
354 | /* Maximum number of gateways (include room for one noop) */ | 354 | /* Maximum number of gateways (include room for one noop) */ |
355 | #define NGATEWAYS ((int)((MAX_IPOPTLEN - IPOPT_MINOFF - 1) / sizeof(uint32_t))) | 355 | #define NGATEWAYS ((int)((MAX_IPOPTLEN - IPOPT_MINOFF - 1) / sizeof(uint32_t))) |
@@ -359,7 +359,7 @@ struct globals { | |||
359 | }; | 359 | }; |
360 | 360 | ||
361 | #define G (*ptr_to_globals) | 361 | #define G (*ptr_to_globals) |
362 | 362 | #define INIT_G() PTR_TO_GLOBALS = xzalloc(sizeof(G)) | |
363 | #define packet (G.packet ) | 363 | #define packet (G.packet ) |
364 | #define whereto (G.whereto ) | 364 | #define whereto (G.whereto ) |
365 | #define wherefrom (G.wherefrom) | 365 | #define wherefrom (G.wherefrom) |
@@ -537,21 +537,15 @@ findsaddr(const struct sockaddr_in *to, struct sockaddr_in *from) | |||
537 | static int | 537 | static int |
538 | wait_for_reply(int sock, struct sockaddr_in *fromp) | 538 | wait_for_reply(int sock, struct sockaddr_in *fromp) |
539 | { | 539 | { |
540 | fd_set fds; | 540 | struct pollfd pfd[1]; |
541 | struct timeval tvwait; | ||
542 | int cc = 0; | 541 | int cc = 0; |
543 | socklen_t fromlen = sizeof(*fromp); | 542 | socklen_t fromlen = sizeof(*fromp); |
544 | 543 | ||
545 | FD_ZERO(&fds); | 544 | pfd[0].fd = sock; |
546 | FD_SET(sock, &fds); | 545 | pfd[0].events = POLLIN; |
547 | 546 | if (poll(pfd, 1, waittime * 1000) > 0) | |
548 | tvwait.tv_sec = waittime; | 547 | cc = recvfrom(sock, packet, sizeof(packet), 0, |
549 | tvwait.tv_usec = 0; | ||
550 | |||
551 | if (select(sock + 1, &fds, NULL, NULL, &tvwait) > 0) | ||
552 | cc = recvfrom(sock, (char *)packet, sizeof(packet), 0, | ||
553 | (struct sockaddr *)fromp, &fromlen); | 548 | (struct sockaddr *)fromp, &fromlen); |
554 | |||
555 | return cc; | 549 | return cc; |
556 | } | 550 | } |
557 | 551 | ||
@@ -930,7 +924,7 @@ int traceroute_main(int argc, char **argv) | |||
930 | llist_t *source_route_list = NULL; | 924 | llist_t *source_route_list = NULL; |
931 | #endif | 925 | #endif |
932 | 926 | ||
933 | PTR_TO_GLOBALS = xzalloc(sizeof(G)); | 927 | INIT_G(); |
934 | from = (struct sockaddr_in *)&wherefrom; | 928 | from = (struct sockaddr_in *)&wherefrom; |
935 | to = (struct sockaddr_in *)&whereto; | 929 | to = (struct sockaddr_in *)&whereto; |
936 | 930 | ||
diff --git a/networking/udhcp/arpping.c b/networking/udhcp/arpping.c index 4ac52c640..33518077b 100644 --- a/networking/udhcp/arpping.c +++ b/networking/udhcp/arpping.c | |||
@@ -37,14 +37,12 @@ struct arpMsg { | |||
37 | 37 | ||
38 | int arpping(uint32_t test_ip, uint32_t from_ip, uint8_t *from_mac, const char *interface) | 38 | int arpping(uint32_t test_ip, uint32_t from_ip, uint8_t *from_mac, const char *interface) |
39 | { | 39 | { |
40 | int timeout = 2; | 40 | int timeout_ms = 2000; |
41 | int s; /* socket */ | 41 | struct pollfd pfd[1]; |
42 | #define s (pfd[0].fd) /* socket */ | ||
42 | int rv = 1; /* "no reply received" yet */ | 43 | int rv = 1; /* "no reply received" yet */ |
43 | struct sockaddr addr; /* for interface name */ | 44 | struct sockaddr addr; /* for interface name */ |
44 | struct arpMsg arp; | 45 | struct arpMsg arp; |
45 | fd_set fdset; | ||
46 | struct timeval tm; | ||
47 | unsigned prevTime; | ||
48 | 46 | ||
49 | s = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_ARP)); | 47 | s = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_ARP)); |
50 | if (s == -1) { | 48 | if (s == -1) { |
@@ -80,18 +78,17 @@ int arpping(uint32_t test_ip, uint32_t from_ip, uint8_t *from_mac, const char *i | |||
80 | /* wait for arp reply, and check it */ | 78 | /* wait for arp reply, and check it */ |
81 | do { | 79 | do { |
82 | int r; | 80 | int r; |
83 | prevTime = monotonic_sec(); | 81 | unsigned prevTime = monotonic_us(); |
84 | FD_ZERO(&fdset); | 82 | |
85 | FD_SET(s, &fdset); | 83 | pfd[0].events = POLLIN; |
86 | tm.tv_sec = timeout; | 84 | r = poll(pfd, 1, timeout_ms); |
87 | tm.tv_usec = 0; | ||
88 | r = select(s + 1, &fdset, NULL, NULL, &tm); | ||
89 | if (r < 0) { | 85 | if (r < 0) { |
90 | bb_perror_msg("error on ARPING request"); | 86 | if (errno != EINTR) { |
91 | if (errno != EINTR) | 87 | bb_perror_msg("poll"); |
92 | break; | 88 | break; |
89 | } | ||
93 | } else if (r) { | 90 | } else if (r) { |
94 | if (recv(s, &arp, sizeof(arp), 0) < 0) | 91 | if (read(s, &arp, sizeof(arp)) < 0) |
95 | break; | 92 | break; |
96 | if (arp.operation == htons(ARPOP_REPLY) | 93 | if (arp.operation == htons(ARPOP_REPLY) |
97 | && memcmp(arp.tHaddr, from_mac, 6) == 0 | 94 | && memcmp(arp.tHaddr, from_mac, 6) == 0 |
@@ -101,8 +98,8 @@ int arpping(uint32_t test_ip, uint32_t from_ip, uint8_t *from_mac, const char *i | |||
101 | break; | 98 | break; |
102 | } | 99 | } |
103 | } | 100 | } |
104 | timeout -= monotonic_sec() - prevTime; | 101 | timeout_ms -= (monotonic_us() - prevTime) / 1000; |
105 | } while (timeout > 0); | 102 | } while (timeout_ms > 0); |
106 | 103 | ||
107 | ret: | 104 | ret: |
108 | close(s); | 105 | close(s); |