aboutsummaryrefslogtreecommitdiff
path: root/networking/tftp.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-09-07 13:43:28 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-09-07 13:43:28 +0000
commit87f3b26b3a17369c12f4f9a70d6845796f8648d6 (patch)
tree2f7fe9fc910d5e97f695c902f848db497fec8bfd /networking/tftp.c
parent40f0bcf9d3f8f8a8d14a9b2cff51761019c75cf4 (diff)
downloadbusybox-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/tftp.c')
-rw-r--r--networking/tftp.c33
1 files changed, 15 insertions, 18 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: