From c4ab180a14a56a57317675480f2aae18a16f3d7d Mon Sep 17 00:00:00 2001 From: Michael Poole Date: Sat, 21 Oct 2006 16:06:47 +0000 Subject: [PATCH] Various I/O cleanups and fixes. src/ioset.c (ioset_add): Set FD_CLOEXEC flag on all managed sockets. (ioset_try_write): Tidy formatting. (ioset_close): Add another bit to "os_close". src/proto-common.c (close_socket): Pass the new bit to ioset_close(). git-archimport-id: srvx@srvx.net--2006/srvx--devo--1.3--patch-60 --- ChangeLog | 17 +++++++++++++++++ src/ioset.c | 10 +++++++--- src/proto-common.c | 2 +- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5110c3c..2e42b83 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,23 @@ # arch-tag: automatic-ChangeLog--srvx@srvx.net--2006/srvx--devo--1.3 # +2006-10-21 16:06:47 GMT Michael Poole patch-60 + + Summary: + Various I/O cleanups and fixes. + Revision: + srvx--devo--1.3--patch-60 + + src/ioset.c (ioset_add): Set FD_CLOEXEC flag on all managed sockets. + (ioset_try_write): Tidy formatting. + (ioset_close): Add another bit to "os_close". + + src/proto-common.c (close_socket): Pass the new bit to ioset_close(). + + modified files: + ChangeLog src/ioset.c src/proto-common.c + + 2006-10-21 16:04:19 GMT Michael Poole patch-59 Summary: diff --git a/src/ioset.c b/src/ioset.c index 6013232..444579e 100644 --- a/src/ioset.c +++ b/src/ioset.c @@ -144,6 +144,8 @@ ioset_add(int fd) { ioq_init(&res->recv, 1024); flags = fcntl(fd, F_GETFL); fcntl(fd, F_SETFL, flags|O_NONBLOCK); + flags = fcntl(fd, F_GETFD); + fcntl(fd, F_SETFD, flags|FD_CLOEXEC); engine->add(res); return res; } @@ -279,7 +281,9 @@ void ioset_update(struct io_fd *fd) { static void ioset_try_write(struct io_fd *fd) { int res; - unsigned int req = ioq_get_avail(&fd->send); + unsigned int req; + + req = ioq_get_avail(&fd->send); res = write(fd->fd, fd->send.buf+fd->send.get, req); if (res < 0) { switch (errno) { @@ -304,7 +308,7 @@ ioset_close(struct io_fd *fdp, int os_close) { active_fd = NULL; if (fdp->destroy_cb) fdp->destroy_cb(fdp); - if (fdp->send.get != fdp->send.put) { + if (fdp->send.get != fdp->send.put && (os_close & 2)) { int flags; flags = fcntl(fdp->fd, F_GETFL); @@ -316,7 +320,7 @@ ioset_close(struct io_fd *fdp, int os_close) { } free(fdp->send.buf); free(fdp->recv.buf); - if (os_close) + if (os_close & 1) close(fdp->fd); engine->remove(fdp); free(fdp); diff --git a/src/proto-common.c b/src/proto-common.c index abb3a91..daf4b86 100644 --- a/src/proto-common.c +++ b/src/proto-common.c @@ -274,7 +274,7 @@ close_socket(void) replay_connected = 0; socket_destroyed(socket_io_fd); } else { - ioset_close(socket_io_fd, 1); + ioset_close(socket_io_fd, 3); socket_io_fd = NULL; } } -- 2.20.1