/* accept new client */
fd = net_accept(fd_listen, NULL, NULL);
- if (fd == -1)
+ if (fd == -1) {
+ if (!NET_ACCEPT_ENOCONN(errno))
+ i_fatal("test server: accept() failed: %m");
return;
- if (fd == -2)
- i_fatal("test server: accept() failed: %m");
+ }
server_connection_init(fd);
}
/* accept new client */
fd = net_accept(fd_listen, NULL, NULL);
- if (fd == -1)
+ if (fd == -1) {
+ if (!NET_ACCEPT_ENOCONN(errno))
+ i_fatal("test server: accept() failed: %m");
return;
- if (fd == -2) {
- i_fatal("test server: accept() failed: %m");
}
server_connection_init(fd);
/* accept new client */
fd = net_accept(fd_listen, NULL, NULL);
- if (fd == -1)
+ if (fd == -1) {
+ if (!NET_ACCEPT_ENOCONN(errno))
+ i_fatal("test server: accept() failed: %m");
return;
- if (fd == -2) {
- i_fatal("test server: accept() failed: %m");
}
server_connection_init(fd);
/* accept new client */
fd = net_accept(fd_listen, NULL, NULL);
- if (fd == -1)
+ if (fd == -1) {
+ if (!NET_ACCEPT_ENOCONN(errno))
+ i_fatal("test server: accept() failed: %m");
return;
- if (fd == -2) {
- i_fatal("test server: accept() failed: %m");
}
(void)http_server_connection_create(http_server, fd, fd, FALSE,
int fd;
fd = net_accept(fd_listen, &client_ip, &client_port);
- if (fd == -1)
+ if (fd == -1) {
+ if (!NET_ACCEPT_ENOCONN(errno))
+ i_fatal("accept() failed: %m");
return;
- if (fd == -2)
- i_fatal("accept() failed: %m");
+ }
client_init(fd, &client_ip, client_port);
}
/* accept new client */
fd = net_accept(fd_listen, NULL, NULL);
- if (fd == -1)
+ if (fd == -1) {
+ if (!NET_ACCEPT_ENOCONN(errno))
+ i_fatal("test server: accept() failed: %m");
return;
- if (fd == -2) {
- i_fatal("test server: accept() failed: %m");
}
server_connection_init(fd);
/* accept new client */
fd = net_accept(fd_listen, NULL, NULL);
- if (fd == -1)
+ if (fd == -1) {
+ if (!NET_ACCEPT_ENOCONN(errno))
+ i_fatal("test server: accept() failed: %m");
return;
- if (fd == -2)
- i_fatal("test server: accept() failed: %m");
+ }
server_connection_init(fd);
}
i_zero(&conn);
conn.listen_fd = l->fd;
conn.fd = net_accept(l->fd, &conn.remote_ip, &conn.remote_port);
- if (conn.fd < 0) {
+ if (conn.fd == -1) {
struct stat st;
int orig_errno = errno;
- if (conn.fd == -1)
+ if (NET_ACCEPT_ENOCONN(errno))
return;
if (errno == ENOTSOCK) {
/* accept new client */
fd = net_accept(fd_listen, NULL, NULL);
- if (fd == -1)
+ if (fd == -1) {
+ if (!NET_ACCEPT_ENOCONN(errno))
+ i_fatal("test server: accept() failed: %m");
return;
- if (fd == -2)
- i_fatal("test server: accept() failed: %m");
+ }
server_connection_init(fd);
}
/* accept new client */
fd = net_accept(fd_listen, NULL, NULL);
- if (fd == -1)
+ if (fd == -1) {
+ if (!NET_ACCEPT_ENOCONN(errno))
+ i_fatal("test server: accept() failed: %m");
return;
- if (fd == -2) {
- i_fatal("test server: accept() failed: %m");
}
if (debug)
/* accept new client */
fd = net_accept(fd_listen, NULL, NULL);
- if (fd == -1)
+ if (fd == -1) {
+ if (!NET_ACCEPT_ENOCONN(errno))
+ i_fatal("test server: accept() failed: %m");
return;
- if (fd == -2) {
- i_fatal("test server: accept() failed: %m");
}
server_connection_init(fd);
addrlen = sizeof(so);
ret = accept(fd, &so.sa, &addrlen);
- if (ret < 0) {
- if (errno == EAGAIN || errno == ECONNABORTED)
- return -1;
- else
- return -2;
- }
+ if (ret < 0)
+ return -1;
if (so.sin.sin_family == AF_UNIX) {
if (addr_r != NULL)
i_zero(addr_r);
If it fails with ECONNREFUSED, unlink the socket and try creating it
again. */
int net_listen_unix_unlink_stale(const char *path, int backlog);
-/* Accept a connection on a socket. Returns -1 if the connection got closed,
- -2 for other failures. For UNIX sockets addr_r->family=port=0. */
+/* Accept a connection on a socket. Returns the new connection's fd, or -1 on
+ error. Check the failure with NET_ACCEPT_ENOCONN(errno). For UNIX sockets
+ addr_r->family=port=0. */
int net_accept(int fd, struct ip_addr *addr_r, in_port_t *port_r)
ATTR_NULL(2, 3);
+/* Returns TRUE if the connection was already closed or was accepted by another
+ process, i.e. normal failures that shouldn't be logged. */
+#define NET_ACCEPT_ENOCONN(err) \
+ ((err) == EAGAIN || (err) == ECONNABORTED)
/* Read data from socket, return number of bytes read,
-1 = error, -2 = disconnected */
int fd;
fd = net_accept(service_list->master_fd, NULL, NULL);
- if (fd < 0) {
- if (fd == -2)
+ if (fd == -1) {
+ if (!NET_ACCEPT_ENOCONN(errno))
e_error(service_list->event, "net_accept() failed: %m");
return;
}