diff options
author | Denis Vlasenko | 2007-09-07 13:43:28 +0000 |
---|---|---|
committer | Denis Vlasenko | 2007-09-07 13:43:28 +0000 |
commit | 87f3b26b3a17369c12f4f9a70d6845796f8648d6 (patch) | |
tree | 2f7fe9fc910d5e97f695c902f848db497fec8bfd /networking/tftp.c | |
parent | 40f0bcf9d3f8f8a8d14a9b2cff51761019c75cf4 (diff) | |
download | busybox-87f3b26b3a17369c12f4f9a70d6845796f8648d6.zip busybox-87f3b26b3a17369c12f4f9a70d6845796f8648d6.tar.gz |
*: 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/tftp.c')
-rw-r--r-- | networking/tftp.c | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/networking/tftp.c b/networking/tftp.c index 0b25f75..ac3a86a 100644 --- a/networking/tftp.c +++ b/networking/tftp.c @@ -23,10 +23,10 @@ #if ENABLE_FEATURE_TFTP_GET || ENABLE_FEATURE_TFTP_PUT -#define TFTP_BLOCKSIZE_DEFAULT 512 /* according to RFC 1350, don't change */ -#define TFTP_TIMEOUT 50000 /* 50ms, in microseconds */ -#define TFTP_MAXTIMEOUT 999000 /* about 1 second, in microseconds */ -#define TFTP_NUM_RETRIES 12 /* number of backed-off retries */ +#define TFTP_BLOCKSIZE_DEFAULT 512 /* according to RFC 1350, don't change */ +#define TFTP_TIMEOUT_MS 50 +#define TFTP_MAXTIMEOUT_MS 2000 +#define TFTP_NUM_RETRIES 12 /* number of backed-off retries */ /* opcodes we support */ #define TFTP_RRQ 1 @@ -114,9 +114,8 @@ static int tftp( USE_GETPUT(const int cmd,) const char *remotefile, const int localfd, unsigned port, int tftp_bufsize) { - struct timeval tv; - fd_set rfds; - int socketfd; + struct pollfd pfd[1]; +#define socketfd (pfd[0].fd) int len; int send_len; USE_FEATURE_TFTP_BLOCKSIZE(smallint want_option_ack = 0;) @@ -124,7 +123,7 @@ static int tftp( USE_GETPUT(const int cmd,) uint16_t opcode; uint16_t block_nr = 1; uint16_t recv_blk; - int retries, waittime; + int retries, waittime_ms; char *cp; unsigned org_port; @@ -208,7 +207,7 @@ static int tftp( USE_GETPUT(const int cmd,) * for potential resend */ retries = TFTP_NUM_RETRIES; /* re-initialize */ - waittime = TFTP_TIMEOUT; + waittime_ms = TFTP_TIMEOUT_MS; send_again: #if ENABLE_DEBUG_TFTP @@ -224,11 +223,9 @@ static int tftp( USE_GETPUT(const int cmd,) recv_again: /* Receive packet */ - tv.tv_sec = 0; - tv.tv_usec = waittime; - FD_ZERO(&rfds); - FD_SET(socketfd, &rfds); - switch (select(socketfd + 1, &rfds, NULL, NULL, &tv)) { + /*pfd[0].fd = socketfd;*/ + pfd[0].events = POLLIN; + switch (poll(pfd, 1, waittime_ms)) { unsigned from_port; case 1: from->len = peer_lsa->len; @@ -258,14 +255,14 @@ static int tftp( USE_GETPUT(const int cmd,) } /* exponential backoff with limit */ - waittime += waittime/2; - if (waittime > TFTP_MAXTIMEOUT) { - waittime = TFTP_MAXTIMEOUT; + waittime_ms += waittime_ms/2; + if (waittime_ms > TFTP_MAXTIMEOUT_MS) { + waittime_ms = TFTP_MAXTIMEOUT_MS; } goto send_again; /* resend last sent pkt */ default: - bb_perror_msg("select"); + bb_perror_msg("poll"); goto ret; } process_pkt: |