ccan/io: use shutdown() before close.
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 5 Aug 2014 11:07:44 +0000 (20:37 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 5 Aug 2014 11:07:44 +0000 (20:37 +0930)
During a debugging session, I wondered why poll() wasn't exiting
when I killed a (local) peer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/io/poll.c

index 078de1403ff8a886db059f14b2437799bab7edf3..8f77dd42d7c888acfb5dca50aea510304592b403 100644 (file)
@@ -78,6 +78,12 @@ static void del_fd(struct fd *fd)
        }
        num_fds--;
        fd->backend_info = -1;
+
+       /* Closing a local socket doesn't wake poll() because other end
+        * has them open.  See 2.6.  When should I use shutdown()?
+        * in http://www.faqs.org/faqs/unix-faq/socket/ */
+       shutdown(fd->fd, SHUT_RDWR);
+
        close(fd->fd);
 }