summaryrefslogtreecommitdiffstats
path: root/src/proto_tcp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/proto_tcp.c')
-rw-r--r--src/proto_tcp.c66
1 files changed, 6 insertions, 60 deletions
diff --git a/src/proto_tcp.c b/src/proto_tcp.c
index 45ce27f..63be775 100644
--- a/src/proto_tcp.c
+++ b/src/proto_tcp.c
@@ -265,7 +265,7 @@ int tcp_bind_socket(int fd, int flags, struct sockaddr_storage *local, struct so
int tcp_connect_server(struct connection *conn, int flags)
{
- int fd;
+ int fd, stream_err;
struct server *srv;
struct proxy *be;
struct conn_src *src;
@@ -298,68 +298,14 @@ int tcp_connect_server(struct connection *conn, int flags)
return SF_ERR_INTERNAL;
}
- fd = conn->handle.fd = sock_create_server_socket(conn);
- if (fd == -1) {
- qfprintf(stderr, "Cannot get a server socket.\n");
- if (errno == ENFILE) {
- conn->err_code = CO_ER_SYS_FDLIM;
- send_log(be, LOG_EMERG,
- "Proxy %s reached system FD limit (maxsock=%d). Please check system tunables.\n",
- be->id, global.maxsock);
- }
- else if (errno == EMFILE) {
- conn->err_code = CO_ER_PROC_FDLIM;
- send_log(be, LOG_EMERG,
- "Proxy %s reached process FD limit (maxsock=%d). Please check 'ulimit-n' and restart.\n",
- be->id, global.maxsock);
- }
- else if (errno == ENOBUFS || errno == ENOMEM) {
- conn->err_code = CO_ER_SYS_MEMLIM;
- send_log(be, LOG_EMERG,
- "Proxy %s reached system memory limit (maxsock=%d). Please check system tunables.\n",
- be->id, global.maxsock);
- }
- else if (errno == EAFNOSUPPORT || errno == EPROTONOSUPPORT) {
- conn->err_code = CO_ER_NOPROTO;
- }
- else
- conn->err_code = CO_ER_SOCK_ERR;
-
- /* this is a resource error */
- conn->flags |= CO_FL_ERROR;
- return SF_ERR_RESOURCE;
- }
-
- if (fd >= global.maxsock) {
- /* do not log anything there, it's a normal condition when this option
- * is used to serialize connections to a server !
- */
- ha_alert("socket(): not enough free sockets. Raise -n argument. Giving up.\n");
- close(fd);
- conn->err_code = CO_ER_CONF_FDLIM;
- conn->flags |= CO_FL_ERROR;
- return SF_ERR_PRXCOND; /* it is a configuration limit */
- }
-
- if (fd_set_nonblock(fd) == -1 ||
- (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one)) == -1)) {
- qfprintf(stderr,"Cannot set client socket to non blocking mode.\n");
- close(fd);
- conn->err_code = CO_ER_SOCK_ERR;
- conn->flags |= CO_FL_ERROR;
- return SF_ERR_INTERNAL;
- }
-
- if (master == 1 && fd_set_cloexec(fd) == -1) {
- ha_alert("Cannot set CLOEXEC on client socket.\n");
- close(fd);
- conn->err_code = CO_ER_SOCK_ERR;
- conn->flags |= CO_FL_ERROR;
- return SF_ERR_INTERNAL;
- }
+ /* perform common checks on obtained socket FD, return appropriate Stream Error Flag in case of failure */
+ fd = conn->handle.fd = sock_create_server_socket(conn, be, &stream_err);
+ if (fd == -1)
+ return stream_err;
+ /* FD is OK, continue with protocol specific settings */
if (be->options & PR_O_TCP_SRV_KA) {
setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &one, sizeof(one));