diff options
| author | Bernie Innocenti <codewiz@google.com> | 2018-05-23 15:45:40 +0900 |
|---|---|---|
| committer | Bernie Innocenti <codewiz@google.com> | 2018-05-23 15:50:19 +0900 |
| commit | 23bf92700c0b2e893f657e91850aa40009997b62 (patch) | |
| tree | de7bcf79273719cc3114c597555e336acae277de /server/ndc.cpp | |
| parent | aa77e4c9c7bb2faeee062403b3700a2316327482 (diff) | |
| download | platform_system_netd-23bf92700c0b2e893f657e91850aa40009997b62.tar.gz platform_system_netd-23bf92700c0b2e893f657e91850aa40009997b62.tar.bz2 platform_system_netd-23bf92700c0b2e893f657e91850aa40009997b62.zip | |
netd: Remove remaining usages of select() in netd.
Bug: 79838856
Test: as follows:
- m ndc
- copy ndc binary to device
- adb shell ndc monitor
- cause some netd activity by re-associating to wifi
Change-Id: I7c641114d16a6b2b95dedc9edfaf8964f5bb9412
Diffstat (limited to 'server/ndc.cpp')
| -rw-r--r-- | server/ndc.cpp | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/server/ndc.cpp b/server/ndc.cpp index 14f6654cb..c86e53e5b 100644 --- a/server/ndc.cpp +++ b/server/ndc.cpp @@ -22,8 +22,8 @@ #include <errno.h> #include <fcntl.h> +#include <sys/poll.h> #include <sys/socket.h> -#include <sys/select.h> #include <sys/time.h> #include <sys/types.h> #include <sys/un.h> @@ -121,27 +121,20 @@ static int do_monitor(int sock, int stop_after_cmd) { printf("[Connected to Netd]\n"); while(1) { - fd_set read_fds; - struct timeval to; int rc = 0; - - to.tv_sec = 10; - to.tv_usec = 0; - - FD_ZERO(&read_fds); - FD_SET(sock, &read_fds); - - rc = TEMP_FAILURE_RETRY(select(sock +1, &read_fds, NULL, NULL, &to)); + struct pollfd fds = { .fd = sock, .events = POLLIN }; + const int timeout_msecs = 10 * 1000; + rc = TEMP_FAILURE_RETRY(poll(&fds, 1, timeout_msecs)); if (rc < 0) { int res = errno; - fprintf(stderr, "Error in select (%s)\n", strerror(res)); + fprintf(stderr, "Error in poll(): %s\n", strerror(res)); free(buffer); return res; } if (rc == 0) { continue; } - if (!FD_ISSET(sock, &read_fds)) { + if (!(fds.revents & (POLLIN | POLLERR))) { continue; } |
