unix: don't pass sockaddr to accept()
Shaves a few nanoseconds off the accept() syscall.
This commit is contained in:
parent
cff2221fbf
commit
752ac30ec8
@ -445,14 +445,18 @@ out:
|
||||
}
|
||||
|
||||
|
||||
int uv__accept(int sockfd, struct sockaddr* saddr, socklen_t slen) {
|
||||
int uv__accept(int sockfd) {
|
||||
int peerfd;
|
||||
|
||||
assert(sockfd >= 0);
|
||||
|
||||
while (1) {
|
||||
#if __linux__
|
||||
peerfd = uv__accept4(sockfd, saddr, &slen, UV__SOCK_NONBLOCK|UV__SOCK_CLOEXEC);
|
||||
peerfd = uv__accept4(sockfd,
|
||||
NULL,
|
||||
NULL,
|
||||
UV__SOCK_NONBLOCK|UV__SOCK_CLOEXEC);
|
||||
|
||||
if (peerfd != -1)
|
||||
break;
|
||||
|
||||
@ -463,7 +467,9 @@ int uv__accept(int sockfd, struct sockaddr* saddr, socklen_t slen) {
|
||||
break;
|
||||
#endif
|
||||
|
||||
if ((peerfd = accept(sockfd, saddr, &slen)) == -1) {
|
||||
peerfd = accept(sockfd, NULL, NULL);
|
||||
|
||||
if (peerfd == -1) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
else
|
||||
|
||||
@ -156,7 +156,7 @@ void uv__stream_init(uv_loop_t* loop, uv_stream_t* stream,
|
||||
int uv__stream_open(uv_stream_t*, int fd, int flags);
|
||||
void uv__stream_destroy(uv_stream_t* stream);
|
||||
void uv__server_io(uv_loop_t* loop, uv__io_t* watcher, int events);
|
||||
int uv__accept(int sockfd, struct sockaddr* saddr, socklen_t len);
|
||||
int uv__accept(int sockfd);
|
||||
int uv__connect(uv_connect_t* req, uv_stream_t* stream, struct sockaddr* addr,
|
||||
socklen_t addrlen, uv_connect_cb cb);
|
||||
|
||||
|
||||
@ -229,7 +229,6 @@ out:
|
||||
|
||||
/* TODO merge with uv__server_io()? */
|
||||
static void uv__pipe_accept(uv_loop_t* loop, uv__io_t* w, int events) {
|
||||
struct sockaddr_un saddr;
|
||||
uv_pipe_t* pipe;
|
||||
int saved_errno;
|
||||
int sockfd;
|
||||
@ -239,7 +238,7 @@ static void uv__pipe_accept(uv_loop_t* loop, uv__io_t* w, int events) {
|
||||
|
||||
assert(pipe->type == UV_NAMED_PIPE);
|
||||
|
||||
sockfd = uv__accept(pipe->fd, (struct sockaddr *)&saddr, sizeof saddr);
|
||||
sockfd = uv__accept(pipe->fd);
|
||||
if (sockfd == -1) {
|
||||
if (errno != EAGAIN && errno != EWOULDBLOCK) {
|
||||
uv__set_sys_error(pipe->loop, errno);
|
||||
|
||||
@ -165,7 +165,6 @@ void uv__stream_destroy(uv_stream_t* stream) {
|
||||
|
||||
void uv__server_io(uv_loop_t* loop, uv__io_t* w, int events) {
|
||||
int fd;
|
||||
struct sockaddr_storage addr;
|
||||
uv_stream_t* stream = container_of(w, uv_stream_t, read_watcher);
|
||||
|
||||
assert(events == UV__IO_READ);
|
||||
@ -181,7 +180,7 @@ void uv__server_io(uv_loop_t* loop, uv__io_t* w, int events) {
|
||||
*/
|
||||
while (stream->fd != -1) {
|
||||
assert(stream->accepted_fd < 0);
|
||||
fd = uv__accept(stream->fd, (struct sockaddr*)&addr, sizeof addr);
|
||||
fd = uv__accept(stream->fd);
|
||||
|
||||
if (fd < 0) {
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user