Adam Tkac bd6af4
diff -up bind-9.5.0b2/lib/isc/unix/socket.c.recv bind-9.5.0b2/lib/isc/unix/socket.c
Adam Tkac bd6af4
--- bind-9.5.0b2/lib/isc/unix/socket.c.recv	2008-04-10 16:45:33.000000000 +0200
Adam Tkac bd6af4
+++ bind-9.5.0b2/lib/isc/unix/socket.c	2008-04-10 17:00:46.000000000 +0200
Adam Tkac bd6af4
@@ -261,10 +261,10 @@ static isc_result_t allocate_socket(isc_
Adam Tkac bd6af4
 static void destroy(isc_socket_t **);
Adam Tkac bd6af4
 static void internal_accept(isc_task_t *, isc_event_t *);
Adam Tkac bd6af4
 static void internal_connect(isc_task_t *, isc_event_t *);
Adam Tkac bd6af4
-static void internal_recv(isc_task_t *, isc_event_t *);
Adam Tkac bd6af4
+static void internal_recv(isc_event_t *);
Adam Tkac bd6af4
 static void internal_send(isc_task_t *, isc_event_t *);
Adam Tkac bd6af4
 static void internal_fdwatch_write(isc_task_t *, isc_event_t *);
Adam Tkac bd6af4
-static void internal_fdwatch_read(isc_task_t *, isc_event_t *);
Adam Tkac bd6af4
+static void internal_fdwatch_read(isc_event_t *);
Adam Tkac bd6af4
 static void process_cmsg(isc_socket_t *, struct msghdr *, isc_socketevent_t *);
Adam Tkac bd6af4
 static void build_msghdr_send(isc_socket_t *, isc_socketevent_t *,
Adam Tkac bd6af4
 			      struct msghdr *, struct iovec *, size_t *);
Adam Tkac bd6af4
@@ -1830,7 +1830,7 @@ isc_socket_detach(isc_socket_t **socketp
Adam Tkac bd6af4
  *
Adam Tkac bd6af4
  * The socket and manager must be locked before calling this function.
Adam Tkac bd6af4
  */
Adam Tkac bd6af4
-static void
Adam Tkac bd6af4
+static isc_boolean_t
Adam Tkac bd6af4
 dispatch_recv(isc_socket_t *sock) {
Adam Tkac bd6af4
 	intev_t *iev;
Adam Tkac bd6af4
 	isc_socketevent_t *ev;
Adam Tkac bd6af4
@@ -1841,7 +1841,7 @@ dispatch_recv(isc_socket_t *sock) {
Adam Tkac bd6af4
 	if (sock->type != isc_sockettype_fdwatch) {
Adam Tkac bd6af4
 		ev = ISC_LIST_HEAD(sock->recv_list);
Adam Tkac bd6af4
 		if (ev == NULL)
Adam Tkac bd6af4
-			return;
Adam Tkac bd6af4
+			return ISC_FALSE;
Adam Tkac bd6af4
 		socket_log(sock, NULL, EVENT, NULL, 0, 0,
Adam Tkac bd6af4
 			   "dispatch_recv:  event %p -> task %p",
Adam Tkac bd6af4
 			   ev, ev->ev_sender);
Adam Tkac bd6af4
@@ -1855,13 +1855,16 @@ dispatch_recv(isc_socket_t *sock) {
Adam Tkac bd6af4
 
Adam Tkac bd6af4
 	sock->references++;
Adam Tkac bd6af4
 	iev->ev_sender = sock;
Adam Tkac bd6af4
+	iev->ev_arg = sock;
Adam Tkac bd6af4
 	if (sock->type == isc_sockettype_fdwatch)
Adam Tkac bd6af4
-		iev->ev_action = internal_fdwatch_read;
Adam Tkac bd6af4
+		internal_fdwatch_read (iev);
Adam Tkac bd6af4
 	else
Adam Tkac bd6af4
-		iev->ev_action = internal_recv;
Adam Tkac bd6af4
-	iev->ev_arg = sock;
Adam Tkac bd6af4
+		internal_recv (iev);
Adam Tkac bd6af4
 
Adam Tkac bd6af4
-	isc_task_send(sender, (isc_event_t **)&iev;;
Adam Tkac bd6af4
+	if (sock->references == 0)
Adam Tkac bd6af4
+		return ISC_TRUE;
Adam Tkac bd6af4
+
Adam Tkac bd6af4
+	return ISC_FALSE;
Adam Tkac bd6af4
 }
Adam Tkac bd6af4
 
Adam Tkac bd6af4
 static void
Adam Tkac bd6af4
@@ -2228,7 +2231,7 @@ internal_accept(isc_task_t *me, isc_even
Adam Tkac bd6af4
 }
Adam Tkac bd6af4
 
Adam Tkac bd6af4
 static void
Adam Tkac bd6af4
-internal_recv(isc_task_t *me, isc_event_t *ev) {
Adam Tkac bd6af4
+internal_recv(isc_event_t *ev) {
Adam Tkac bd6af4
 	isc_socketevent_t *dev;
Adam Tkac bd6af4
 	isc_socket_t *sock;
Adam Tkac bd6af4
 
Adam Tkac bd6af4
@@ -2237,21 +2240,13 @@ internal_recv(isc_task_t *me, isc_event_
Adam Tkac bd6af4
 	sock = ev->ev_sender;
Adam Tkac bd6af4
 	INSIST(VALID_SOCKET(sock));
Adam Tkac bd6af4
 
Adam Tkac bd6af4
-	LOCK(&sock->lock);
Adam Tkac bd6af4
-	socket_log(sock, NULL, IOEVENT,
Adam Tkac bd6af4
-		   isc_msgcat, ISC_MSGSET_SOCKET, ISC_MSG_INTERNALRECV,
Adam Tkac bd6af4
-		   "internal_recv: task %p got event %p", me, ev);
Adam Tkac bd6af4
-
Adam Tkac bd6af4
 	INSIST(sock->pending_recv == 1);
Adam Tkac bd6af4
 	sock->pending_recv = 0;
Adam Tkac bd6af4
 
Adam Tkac bd6af4
 	INSIST(sock->references > 0);
Adam Tkac bd6af4
 	sock->references--;  /* the internal event is done with this socket */
Adam Tkac bd6af4
-	if (sock->references == 0) {
Adam Tkac bd6af4
-		UNLOCK(&sock->lock);
Adam Tkac bd6af4
-		destroy(&sock);
Adam Tkac bd6af4
+	if (sock->references == 0)
Adam Tkac bd6af4
 		return;
Adam Tkac bd6af4
-	}
Adam Tkac bd6af4
 
Adam Tkac bd6af4
 	/*
Adam Tkac bd6af4
 	 * Try to do as much I/O as possible on this socket.  There are no
Adam Tkac bd6af4
@@ -2289,7 +2284,6 @@ internal_recv(isc_task_t *me, isc_event_
Adam Tkac bd6af4
 	if (!ISC_LIST_EMPTY(sock->recv_list))
Adam Tkac bd6af4
 		select_poke(sock->manager, sock->fd, SELECT_POKE_READ);
Adam Tkac bd6af4
 
Adam Tkac bd6af4
-	UNLOCK(&sock->lock);
Adam Tkac bd6af4
 }
Adam Tkac bd6af4
 
Adam Tkac bd6af4
 static void
Adam Tkac bd6af4
@@ -2388,7 +2382,7 @@ internal_fdwatch_write(isc_task_t *me, i
Adam Tkac bd6af4
 }
Adam Tkac bd6af4
 
Adam Tkac bd6af4
 static void
Adam Tkac bd6af4
-internal_fdwatch_read(isc_task_t *me, isc_event_t *ev) {
Adam Tkac bd6af4
+internal_fdwatch_read(isc_event_t *ev) {
Adam Tkac bd6af4
 	isc_socket_t *sock;
Adam Tkac bd6af4
 	int more_data;
Adam Tkac bd6af4
 
Adam Tkac bd6af4
@@ -2400,31 +2394,19 @@ internal_fdwatch_read(isc_task_t *me, is
Adam Tkac bd6af4
 	sock = (isc_socket_t *)ev->ev_sender;
Adam Tkac bd6af4
 	INSIST(VALID_SOCKET(sock));
Adam Tkac bd6af4
 
Adam Tkac bd6af4
-	LOCK(&sock->lock);
Adam Tkac bd6af4
-	socket_log(sock, NULL, IOEVENT,
Adam Tkac bd6af4
-		   isc_msgcat, ISC_MSGSET_SOCKET, ISC_MSG_INTERNALRECV,
Adam Tkac bd6af4
-		   "internal_fdwatch_read: task %p got event %p", me, ev);
Adam Tkac bd6af4
-
Adam Tkac bd6af4
 	INSIST(sock->pending_recv == 1);
Adam Tkac bd6af4
 
Adam Tkac bd6af4
-	UNLOCK(&sock->lock);
Adam Tkac bd6af4
-	more_data = (sock->fdwatchcb)(me, sock, sock->fdwatcharg);
Adam Tkac bd6af4
-	LOCK(&sock->lock);
Adam Tkac bd6af4
+	INSIST(0); /* We should not be here */
Adam Tkac bd6af4
 
Adam Tkac bd6af4
 	sock->pending_recv = 0;
Adam Tkac bd6af4
 
Adam Tkac bd6af4
 	INSIST(sock->references > 0);
Adam Tkac bd6af4
 	sock->references--;  /* the internal event is done with this socket */
Adam Tkac bd6af4
-	if (sock->references == 0) {
Adam Tkac bd6af4
-		UNLOCK(&sock->lock);
Adam Tkac bd6af4
-		destroy(&sock);
Adam Tkac bd6af4
+	if (sock->references == 0)
Adam Tkac bd6af4
 		return;
Adam Tkac bd6af4
-	}
Adam Tkac bd6af4
 
Adam Tkac bd6af4
 	if (more_data)
Adam Tkac bd6af4
 		select_poke(sock->manager, sock->fd, SELECT_POKE_READ);
Adam Tkac bd6af4
-
Adam Tkac bd6af4
-	UNLOCK(&sock->lock);
Adam Tkac bd6af4
 }
Adam Tkac bd6af4
 
Adam Tkac bd6af4
 static void
Adam Tkac bd6af4
@@ -2434,6 +2416,7 @@ process_fds(isc_socketmgr_t *manager, in
Adam Tkac bd6af4
 	int i;
Adam Tkac bd6af4
 	isc_socket_t *sock;
Adam Tkac bd6af4
 	isc_boolean_t unlock_sock;
Adam Tkac bd6af4
+	isc_boolean_t destroy_sock;
Adam Tkac bd6af4
 
Adam Tkac bd6af4
 	REQUIRE(maxfd <= (int)FD_SETSIZE);
Adam Tkac bd6af4
 
Adam Tkac bd6af4
@@ -2462,6 +2445,7 @@ process_fds(isc_socketmgr_t *manager, in
Adam Tkac bd6af4
 
Adam Tkac bd6af4
 		sock = manager->fds[i];
Adam Tkac bd6af4
 		unlock_sock = ISC_FALSE;
Adam Tkac bd6af4
+		destroy_sock = ISC_FALSE;
Adam Tkac bd6af4
 		if (FD_ISSET(i, readfds)) {
Adam Tkac bd6af4
 			if (sock == NULL) {
Adam Tkac bd6af4
 				FD_CLR(i, &manager->read_fds);
Adam Tkac bd6af4
@@ -2473,7 +2457,7 @@ process_fds(isc_socketmgr_t *manager, in
Adam Tkac bd6af4
 				if (sock->listener)
Adam Tkac bd6af4
 					dispatch_accept(sock);
Adam Tkac bd6af4
 				else
Adam Tkac bd6af4
-					dispatch_recv(sock);
Adam Tkac bd6af4
+					destroy_sock = dispatch_recv(sock);
Adam Tkac bd6af4
 			}
Adam Tkac bd6af4
 			FD_CLR(i, &manager->read_fds);
Adam Tkac bd6af4
 		}
Adam Tkac bd6af4
@@ -2497,6 +2481,8 @@ process_fds(isc_socketmgr_t *manager, in
Adam Tkac bd6af4
 		}
Adam Tkac bd6af4
 		if (unlock_sock)
Adam Tkac bd6af4
 			UNLOCK(&sock->lock);
Adam Tkac bd6af4
+		if (destroy_sock)
Adam Tkac bd6af4
+			destroy(&sock);
Adam Tkac bd6af4
 	}
Adam Tkac bd6af4
 }
Adam Tkac bd6af4