diff options
author | Martin Willi <martin@revosec.ch> | 2014-11-21 12:49:07 +0100 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2014-11-21 12:49:07 +0100 |
commit | f6f3b0db1154cf0f97f2b26757ae7c42f5629bf3 (patch) | |
tree | 5fdb42930d1c23d5ace96af3f74865571a90b234 /src/libtls/tls_socket.c | |
parent | e796b88e86a719c03d551318dda359b373496ce5 (diff) | |
parent | 89f19ef8763f2139b080efa2de019914e84f7cad (diff) | |
download | strongswan-f6f3b0db1154cf0f97f2b26757ae7c42f5629bf3.tar.bz2 strongswan-f6f3b0db1154cf0f97f2b26757ae7c42f5629bf3.tar.xz |
Merge branch 'poll'
Replace relevant uses of select() by poll(). poll(2) avoids the difficulties
we have with more than 1024 open file descriptors, and seems to be fairly
portable.
Fixes #757.
Diffstat (limited to 'src/libtls/tls_socket.c')
-rw-r--r-- | src/libtls/tls_socket.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/libtls/tls_socket.c b/src/libtls/tls_socket.c index 648771e75..9427b677c 100644 --- a/src/libtls/tls_socket.c +++ b/src/libtls/tls_socket.c @@ -291,25 +291,24 @@ METHOD(tls_socket_t, splice, bool, private_tls_socket_t *this, int rfd, int wfd) { char buf[PLAIN_BUF_SIZE], *pos; - fd_set set; ssize_t in, out; bool old, plain_eof = FALSE, crypto_eof = FALSE; + struct pollfd pfd[] = { + { .fd = this->fd, .events = POLLIN, }, + { .fd = rfd, .events = POLLIN, }, + }; while (!plain_eof && !crypto_eof) { - FD_ZERO(&set); - FD_SET(rfd, &set); - FD_SET(this->fd, &set); - old = thread_cancelability(TRUE); - in = select(max(rfd, this->fd) + 1, &set, NULL, NULL, NULL); + in = poll(pfd, countof(pfd), -1); thread_cancelability(old); if (in == -1) { DBG1(DBG_TLS, "TLS select error: %s", strerror(errno)); return FALSE; } - while (!plain_eof && FD_ISSET(this->fd, &set)) + while (!plain_eof && pfd[0].revents & POLLIN) { in = read_(this, buf, sizeof(buf), FALSE); switch (in) @@ -342,7 +341,7 @@ METHOD(tls_socket_t, splice, bool, } break; } - if (!crypto_eof && FD_ISSET(rfd, &set)) + if (!crypto_eof && pfd[1].revents & POLLIN) { in = read(rfd, buf, sizeof(buf)); switch (in) |