aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/dhcpd.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-02-16 23:25:44 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2017-02-16 23:25:44 +0100
commit52a515d18724bbb34e3ccbbb0218efcc4eccc0a8 (patch)
tree16a5a05a328d7e0bd2b4b1bfbcaf543cf8a36d33 /networking/udhcp/dhcpd.c
parentdc207f669675a271812a21b0ddbe3b894adf8e4c (diff)
downloadbusybox-w32-52a515d18724bbb34e3ccbbb0218efcc4eccc0a8.tar.gz
busybox-w32-52a515d18724bbb34e3ccbbb0218efcc4eccc0a8.tar.bz2
busybox-w32-52a515d18724bbb34e3ccbbb0218efcc4eccc0a8.zip
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/dhcpd.c')
-rw-r--r--networking/udhcp/dhcpd.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c
index e116ba3af..5eff026bc 100644
--- a/networking/udhcp/dhcpd.c
+++ b/networking/udhcp/dhcpd.c
@@ -794,7 +794,7 @@ static NOINLINE void send_inform(struct dhcp_packet *oldpacket)
794int udhcpd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 794int udhcpd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
795int udhcpd_main(int argc UNUSED_PARAM, char **argv) 795int udhcpd_main(int argc UNUSED_PARAM, char **argv)
796{ 796{
797 int server_socket = -1, retval, max_sock; 797 int server_socket = -1, retval;
798 uint8_t *state; 798 uint8_t *state;
799 unsigned timeout_end; 799 unsigned timeout_end;
800 unsigned num_ips; 800 unsigned num_ips;
@@ -891,10 +891,10 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
891 continue_with_autotime: 891 continue_with_autotime:
892 timeout_end = monotonic_sec() + server_config.auto_time; 892 timeout_end = monotonic_sec() + server_config.auto_time;
893 while (1) { /* loop until universe collapses */ 893 while (1) { /* loop until universe collapses */
894 fd_set rfds; 894 struct pollfd pfds[2];
895 struct dhcp_packet packet; 895 struct dhcp_packet packet;
896 int bytes; 896 int bytes;
897 struct timeval tv; 897 int tv;
898 uint8_t *server_id_opt; 898 uint8_t *server_id_opt;
899 uint8_t *requested_ip_opt; 899 uint8_t *requested_ip_opt;
900 uint32_t requested_nip = requested_nip; /* for compiler */ 900 uint32_t requested_nip = requested_nip; /* for compiler */
@@ -906,16 +906,11 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
906 server_config.interface); 906 server_config.interface);
907 } 907 }
908 908
909 max_sock = udhcp_sp_fd_set(&rfds, server_socket); 909 udhcp_sp_fd_set(pfds, server_socket);
910 if (server_config.auto_time) { 910 tv = timeout_end - monotonic_sec();
911 /* cast to signed is essential if tv_sec is wider than int */
912 tv.tv_sec = (int)(timeout_end - monotonic_sec());
913 tv.tv_usec = 0;
914 }
915 retval = 0; 911 retval = 0;
916 if (!server_config.auto_time || tv.tv_sec > 0) { 912 if (!server_config.auto_time || tv > 0) {
917 retval = select(max_sock + 1, &rfds, NULL, NULL, 913 retval = poll(pfds, 2, server_config.auto_time ? tv * 1000 : -1);
918 server_config.auto_time ? &tv : NULL);
919 } 914 }
920 if (retval == 0) { 915 if (retval == 0) {
921 write_leases(); 916 write_leases();
@@ -926,7 +921,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
926 continue; 921 continue;
927 } 922 }
928 923
929 switch (udhcp_sp_read(&rfds)) { 924 switch (udhcp_sp_read(pfds)) {
930 case SIGUSR1: 925 case SIGUSR1:
931 bb_error_msg("received %s", "SIGUSR1"); 926 bb_error_msg("received %s", "SIGUSR1");
932 write_leases(); 927 write_leases();