Various I/O cleanups and fixes.
authorMichael Poole <mdpoole@troilus.org>
Sat, 21 Oct 2006 16:06:47 +0000 (16:06 +0000)
committerMichael Poole <mdpoole@troilus.org>
Sat, 21 Oct 2006 16:06:47 +0000 (16:06 +0000)
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
src/ioset.c
src/proto-common.c

index 5110c3c93fc2cc18891f007dc736c96cbac5b5db..2e42b83d9a75e2fc9900f88eb77640a2cc36a31c 100644 (file)
--- 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 <mdpoole@troilus.org>     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 <mdpoole@troilus.org>     patch-59
 
     Summary:
index 6013232653b3839f3909361c97787651e2c32dbf..444579e9c46d7fb84d58eb75a65f047096a3f1f6 100644 (file)
@@ -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);
index abb3a91cd74491dc560b70362e753f860d3efab4..daf4b868d558f971ce2f62283697be6b8190d0c1 100644 (file)
@@ -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;
     }
 }