REQUIRE(socketp != NULL && *socketp == NULL);
LOCK(&sock->lock);
+ REQUIRE(sock->references > 0);
sock->references++;
UNLOCK(&sock->lock);
LOCK(&sock->lock);
- REQUIRE(sock->references == 1);
REQUIRE(sock->fd >= 0 && sock->fd < (int)sock->manager->maxsocks);
INSIST(!sock->connecting);
unwatch_write = writeable;
goto unlock_fd;
}
+ if (SOCK_DEAD(sock)) { /* Sock is being closed, bail */
+ UNLOCK(&sock->lock);
+ UNLOCK(&thread->fdlock[lockid]);
+ return;
+ }
LOCK(&sock->lock);
sock->references++;
UNLOCK(&sock->lock);
if (readable) {
- if (!SOCK_DEAD(sock)) {
- if (sock->listener)
- internal_accept(sock);
- else
- internal_recv(sock);
- }
+ if (sock->listener)
+ internal_accept(sock);
+ else
+ internal_recv(sock);
unwatch_read = true;
}
if (writeable) {
- if (sock == NULL) {
- unwatch_write = true;
- goto unlock_fd;
- }
- if (!SOCK_DEAD(sock)) {
- if (sock->connecting)
- internal_connect(sock);
- else
- internal_send(sock);
- }
+ if (sock->connecting)
+ internal_connect(sock);
+ else
+ internal_send(sock);
unwatch_write = true;
}