unix: fix uv_pipe_connect() with existing fd
Don't create a new socket descriptor if one has been previously assigned with uv_pipe_open().
This commit is contained in:
parent
e3a28508b2
commit
ff59525c7e
@ -170,16 +170,17 @@ void uv_pipe_connect(uv_connect_t* req,
|
||||
uv_connect_cb cb) {
|
||||
struct sockaddr_un saddr;
|
||||
int saved_errno;
|
||||
int sockfd;
|
||||
int new_sock;
|
||||
int err;
|
||||
int r;
|
||||
|
||||
saved_errno = errno;
|
||||
sockfd = -1;
|
||||
new_sock = (handle->fd == -1);
|
||||
err = -1;
|
||||
|
||||
if ((sockfd = uv__socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
|
||||
goto out;
|
||||
if (new_sock)
|
||||
if ((handle->fd = uv__socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
|
||||
goto out;
|
||||
|
||||
memset(&saddr, 0, sizeof saddr);
|
||||
uv_strlcpy(saddr.sun_path, name, sizeof(saddr.sun_path));
|
||||
@ -189,19 +190,19 @@ void uv_pipe_connect(uv_connect_t* req,
|
||||
* is either there or not.
|
||||
*/
|
||||
do {
|
||||
r = connect(sockfd, (struct sockaddr*)&saddr, sizeof saddr);
|
||||
r = connect(handle->fd, (struct sockaddr*)&saddr, sizeof saddr);
|
||||
}
|
||||
while (r == -1 && errno == EINTR);
|
||||
|
||||
if (r == -1) {
|
||||
err = errno;
|
||||
close(sockfd);
|
||||
if (r == -1)
|
||||
goto out;
|
||||
}
|
||||
|
||||
uv__stream_open((uv_stream_t*)handle,
|
||||
sockfd,
|
||||
UV_STREAM_READABLE | UV_STREAM_WRITABLE);
|
||||
if (new_sock)
|
||||
if (uv__stream_open((uv_stream_t*)handle,
|
||||
handle->fd,
|
||||
UV_STREAM_READABLE | UV_STREAM_WRITABLE))
|
||||
goto out;
|
||||
|
||||
uv__io_start(handle->loop, &handle->read_watcher);
|
||||
uv__io_start(handle->loop, &handle->write_watcher);
|
||||
err = 0;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user