*: 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
This commit is contained in:
Denis Vlasenko
2007-09-07 13:43:28 +00:00
parent 40f0bcf9d3
commit 87f3b26b3a
6 changed files with 61 additions and 82 deletions

View File

@ -346,10 +346,10 @@ static int optlen; /* length of ip options */
struct globals {
/* last inbound (icmp) packet */
unsigned char packet[512];
struct sockaddr_storage whereto; /* Who to try to reach */
struct sockaddr_storage wherefrom; /* Who we are */
/* last inbound (icmp) packet */
unsigned char packet[512];
#if ENABLE_FEATURE_TRACEROUTE_SOURCE_ROUTE
/* Maximum number of gateways (include room for one noop) */
#define NGATEWAYS ((int)((MAX_IPOPTLEN - IPOPT_MINOFF - 1) / sizeof(uint32_t)))
@ -359,7 +359,7 @@ struct globals {
};
#define G (*ptr_to_globals)
#define INIT_G() PTR_TO_GLOBALS = xzalloc(sizeof(G))
#define packet (G.packet )
#define whereto (G.whereto )
#define wherefrom (G.wherefrom)
@ -537,21 +537,15 @@ findsaddr(const struct sockaddr_in *to, struct sockaddr_in *from)
static int
wait_for_reply(int sock, struct sockaddr_in *fromp)
{
fd_set fds;
struct timeval tvwait;
struct pollfd pfd[1];
int cc = 0;
socklen_t fromlen = sizeof(*fromp);
FD_ZERO(&fds);
FD_SET(sock, &fds);
tvwait.tv_sec = waittime;
tvwait.tv_usec = 0;
if (select(sock + 1, &fds, NULL, NULL, &tvwait) > 0)
cc = recvfrom(sock, (char *)packet, sizeof(packet), 0,
pfd[0].fd = sock;
pfd[0].events = POLLIN;
if (poll(pfd, 1, waittime * 1000) > 0)
cc = recvfrom(sock, packet, sizeof(packet), 0,
(struct sockaddr *)fromp, &fromlen);
return cc;
}
@ -930,7 +924,7 @@ int traceroute_main(int argc, char **argv)
llist_t *source_route_list = NULL;
#endif
PTR_TO_GLOBALS = xzalloc(sizeof(G));
INIT_G();
from = (struct sockaddr_in *)&wherefrom;
to = (struct sockaddr_in *)&whereto;