ext/libuv/src/unix/tcp.c in libuv-0.10.2 vs ext/libuv/src/unix/tcp.c in libuv-0.10.3

- old
+ new

@@ -46,47 +46,48 @@ return err; sockfd = err; err = uv__stream_open((uv_stream_t*) handle, sockfd, flags); if (err) { - close(sockfd); + uv__close(sockfd); return err; } return 0; } -static int uv__bind(uv_tcp_t* tcp, - int domain, - struct sockaddr* addr, - int addrsize) { +int uv__tcp_bind(uv_tcp_t* tcp, + const struct sockaddr* addr, + unsigned int addrlen) { int err; int on; - err = maybe_new_socket(tcp, domain, UV_STREAM_READABLE | UV_STREAM_WRITABLE); + err = maybe_new_socket(tcp, + addr->sa_family, + UV_STREAM_READABLE | UV_STREAM_WRITABLE); if (err) return err; on = 1; if (setsockopt(tcp->io_watcher.fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on))) return -errno; errno = 0; - if (bind(tcp->io_watcher.fd, addr, addrsize) && errno != EADDRINUSE) + if (bind(tcp->io_watcher.fd, addr, addrlen) && errno != EADDRINUSE) return -errno; tcp->delayed_error = -errno; return 0; } -static int uv__connect(uv_connect_t* req, - uv_tcp_t* handle, - struct sockaddr* addr, - socklen_t addrlen, - uv_connect_cb cb) { +int uv__tcp_connect(uv_connect_t* req, + uv_tcp_t* handle, + const struct sockaddr* addr, + unsigned int addrlen, + uv_connect_cb cb) { int err; int r; assert(handle->type == UV_TCP); @@ -131,26 +132,10 @@ return 0; } -int uv__tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr) { - return uv__bind(handle, - AF_INET, - (struct sockaddr*)&addr, - sizeof(struct sockaddr_in)); -} - - -int uv__tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6 addr) { - return uv__bind(handle, - AF_INET6, - (struct sockaddr*)&addr, - sizeof(struct sockaddr_in6)); -} - - int uv_tcp_open(uv_tcp_t* handle, uv_os_sock_t sock) { return uv__stream_open((uv_stream_t*)handle, sock, UV_STREAM_READABLE | UV_STREAM_WRITABLE); } @@ -227,25 +212,9 @@ /* Start listening for connections. */ tcp->io_watcher.cb = uv__server_io; uv__io_start(tcp->loop, &tcp->io_watcher, UV__POLLIN); return 0; -} - - -int uv__tcp_connect(uv_connect_t* req, - uv_tcp_t* handle, - struct sockaddr_in addr, - uv_connect_cb cb) { - return uv__connect(req, handle, (struct sockaddr*) &addr, sizeof addr, cb); -} - - -int uv__tcp_connect6(uv_connect_t* req, - uv_tcp_t* handle, - struct sockaddr_in6 addr, - uv_connect_cb cb) { - return uv__connect(req, handle, (struct sockaddr*) &addr, sizeof addr, cb); } int uv__tcp_nodelay(int fd, int on) { return setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on));