diff options
author | Lorenzo Colitti <lorenzo@google.com> | 2014-08-26 18:24:00 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-08-26 18:24:00 +0000 |
commit | cca70d8b359709a1fb6989f30f278c4a9e86deb9 (patch) | |
tree | ff51ef9f8db56e4b676bae8b0f3a83a73811d254 | |
parent | 8a20092a0781bab6bbe61df53c0f876655d047da (diff) | |
parent | dce3ddf54083ccd0e3752c4c08013688f79baa7a (diff) | |
download | platform_external_android-clat-cca70d8b359709a1fb6989f30f278c4a9e86deb9.tar.gz platform_external_android-clat-cca70d8b359709a1fb6989f30f278c4a9e86deb9.tar.bz2 platform_external_android-clat-cca70d8b359709a1fb6989f30f278c4a9e86deb9.zip |
am dce3ddf5: Call read on any event, not just on POLLIN.
* commit 'dce3ddf54083ccd0e3752c4c08013688f79baa7a':
Call read on any event, not just on POLLIN.
-rw-r--r-- | clatd.c | 23 | ||||
-rw-r--r-- | clatd.h | 2 |
2 files changed, 14 insertions, 11 deletions
@@ -375,27 +375,28 @@ void read_packet(int active_fd, const struct tun_data *tunnel) { */ void event_loop(const struct tun_data *tunnel) { time_t last_interface_poll; - struct pollfd wait_fd[2]; + struct pollfd wait_fd[] = { + { tunnel->read_fd6, POLLIN, 0 }, + { tunnel->fd4, POLLIN, 0 }, + }; // start the poll timer last_interface_poll = time(NULL); - wait_fd[0].fd = tunnel->read_fd6; - wait_fd[0].events = POLLIN; - wait_fd[0].revents = 0; - wait_fd[1].fd = tunnel->fd4; - wait_fd[1].events = POLLIN; - wait_fd[1].revents = 0; - while(running) { if(poll(wait_fd, 2, NO_TRAFFIC_INTERFACE_POLL_FREQUENCY*1000) == -1) { if(errno != EINTR) { logmsg(ANDROID_LOG_WARN,"event_loop/poll returned an error: %s",strerror(errno)); } } else { - int i; - for(i = 0; i < 2; i++) { - if((wait_fd[i].revents & POLLIN) != 0) { + size_t i; + for(i = 0; i < ARRAY_SIZE(wait_fd); i++) { + // Call read_packet if the socket has data to be read, but also if an + // error is waiting. If we don't call read() after getting POLLERR, a + // subsequent poll() will return immediately with POLLERR again, + // causing this code to spin in a loop. Calling read() will clear the + // socket error flag instead. + if(wait_fd[i].revents != 0) { read_packet(wait_fd[i].fd,tunnel); } } @@ -25,6 +25,8 @@ #define PACKETLEN (MAXMTU+sizeof(struct tun_pi)) #define CLATD_VERSION "1.3" +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + // how frequently (in seconds) to poll for an address change while traffic is passing #define INTERFACE_POLL_FREQUENCY 30 |