Skip to content

Commit

Permalink
- Set "listener" to -1 after we close it so that the error-handler
Browse files Browse the repository at this point in the history
  doesn't try to re-close it.
- Set blocking I/O before the second (final) connect() call.
  • Loading branch information
Wayne Davison committed Sep 16, 2004
1 parent a20c989 commit ab217f7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ static int socketpair_tcp(int fd[2])
struct sockaddr_in sock;
struct sockaddr_in sock2;
socklen_t socklen = sizeof sock;
int connect_done = 0;
int errno_save, connect_done = 0;

fd[0] = fd[1] = listener = -1;

Expand Down Expand Up @@ -727,24 +727,28 @@ static int socketpair_tcp(int fd[2])
goto failed;

close(listener);
listener = -1;

set_blocking(fd[1]);

if (connect_done == 0) {
if (connect(fd[1], (struct sockaddr *)&sock, sizeof sock) != 0
&& errno != EISCONN)
goto failed;
}

set_blocking(fd[1]);

/* all OK! */
return 0;

failed:
errno_save = errno;
if (fd[0] != -1)
close(fd[0]);
if (fd[1] != -1)
close(fd[1]);
if (listener != -1)
close(listener);
errno = errno_save;
return -1;
}

Expand Down

0 comments on commit ab217f7

Please sign in to comment.