summaryrefslogtreecommitdiff
path: root/networking/udhcp/dhcpc.c
diff options
context:
space:
mode:
authorDenys Vlasenko2017-02-16 23:25:44 +0100
committerDenys Vlasenko2017-02-16 23:25:44 +0100
commit52a515d18724bbb34e3ccbbb0218efcc4eccc0a8 (patch)
tree16a5a05a328d7e0bd2b4b1bfbcaf543cf8a36d33 /networking/udhcp/dhcpc.c
parentdc207f669675a271812a21b0ddbe3b894adf8e4c (diff)
downloadbusybox-52a515d18724bbb34e3ccbbb0218efcc4eccc0a8.zip
busybox-52a515d18724bbb34e3ccbbb0218efcc4eccc0a8.tar.gz
udhcp: use poll() instead of select()
function old new delta udhcp_sp_read 65 46 -19 udhcp_sp_fd_set 79 54 -25 udhcpd_main 1530 1482 -48 udhcpc_main 2780 2730 -50 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-142) Total: -142 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/udhcp/dhcpc.c')
-rw-r--r--networking/udhcp/dhcpc.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 0e23626..8f7f59e 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -1281,9 +1281,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
unsigned already_waited_sec;
unsigned opt;
IF_FEATURE_UDHCPC_ARPING(unsigned arpping_ms;)
- int max_fd;
int retval;
- fd_set rfds;
setup_common_bufsiz();
@@ -1432,7 +1430,8 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
* "continue" statements in code below jump to the top of the loop.
*/
for (;;) {
- struct timeval tv;
+ int tv;
+ struct pollfd pfds[2];
struct dhcp_packet packet;
/* silence "uninitialized!" warning */
unsigned timestamp_before_wait = timestamp_before_wait;
@@ -1446,16 +1445,15 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
* to change_listen_mode(). Thus we open listen socket
* BEFORE we send renew request (see "case BOUND:"). */
- max_fd = udhcp_sp_fd_set(&rfds, sockfd);
+ udhcp_sp_fd_set(pfds, sockfd);
- tv.tv_sec = timeout - already_waited_sec;
- tv.tv_usec = 0;
+ tv = timeout - already_waited_sec;
retval = 0;
/* If we already timed out, fall through with retval = 0, else... */
- if ((int)tv.tv_sec > 0) {
- log1("waiting on select %u seconds", (int)tv.tv_sec);
+ if (tv > 0) {
+ log1("waiting on select %u seconds", tv);
timestamp_before_wait = (unsigned)monotonic_sec();
- retval = select(max_fd + 1, &rfds, NULL, NULL, &tv);
+ retval = poll(pfds, 2, tv * 1000);
if (retval < 0) {
/* EINTR? A signal was caught, don't panic */
if (errno == EINTR) {
@@ -1591,8 +1589,8 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
/* select() didn't timeout, something happened */
/* Is it a signal? */
- /* note: udhcp_sp_read checks FD_ISSET before reading */
- switch (udhcp_sp_read(&rfds)) {
+ /* note: udhcp_sp_read checks poll result before reading */
+ switch (udhcp_sp_read(pfds)) {
case SIGUSR1:
client_config.first_secs = 0; /* make secs field count from 0 */
already_waited_sec = 0;
@@ -1627,7 +1625,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
}
/* Is it a packet? */
- if (listen_mode == LISTEN_NONE || !FD_ISSET(sockfd, &rfds))
+ if (listen_mode == LISTEN_NONE || !pfds[1].revents)
continue; /* no */
{
@@ -1742,8 +1740,8 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
/* paranoia: must not be too small and not prone to overflows */
if (lease_seconds < 0x10)
lease_seconds = 0x10;
- if (lease_seconds >= 0x10000000)
- lease_seconds = 0x0fffffff;
+ if (lease_seconds > 0x7fffffff / 1000)
+ lease_seconds = 0x7fffffff / 1000;
}
#if ENABLE_FEATURE_UDHCPC_ARPING
if (opt & OPT_a) {