Browse Source

ccan/io: use shutdown() before close.

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>
Rusty Russell 11 years ago
parent
commit
31df8231a0
1 changed files with 6 additions and 0 deletions
  1. 6 0
      ccan/io/poll.c

+ 6 - 0
ccan/io/poll.c

@@ -78,6 +78,12 @@ static void del_fd(struct fd *fd)
 	}
 	}
 	num_fds--;
 	num_fds--;
 	fd->backend_info = -1;
 	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);
 	close(fd->fd);
 }
 }