]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: frontend: move the fd-specific settings to session_accept_fd()
authorWilly Tarreau <w@1wt.eu>
Sun, 5 Apr 2015 15:56:47 +0000 (17:56 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 6 Apr 2015 09:37:35 +0000 (11:37 +0200)
The frontend is generic and does not depend on a file descriptor,
so applying some socket options to the incoming fd is not its role.
Let's move the setsockopt() calls earlier in session_accept_fd()
where others are done as well.

src/frontend.c
src/session.c

index b7f4e194c630568ca4b528c0770c45821ed5b95a..bb4383b2dd8c1aa548213a8115984d79fd483753 100644 (file)
@@ -60,38 +60,6 @@ int frontend_accept(struct stream *s)
 
        int cfd = conn->t.sock.fd;
 
-       /* Adjust some socket options */
-       if (l->addr.ss_family == AF_INET || l->addr.ss_family == AF_INET6) {
-               if (setsockopt(cfd, IPPROTO_TCP, TCP_NODELAY,
-                              (char *) &one, sizeof(one)) == -1)
-                       goto out_return;
-
-               if (fe->options & PR_O_TCP_CLI_KA)
-                       setsockopt(cfd, SOL_SOCKET, SO_KEEPALIVE,
-                                  (char *) &one, sizeof(one));
-
-               if (fe->options & PR_O_TCP_NOLING)
-                       fdtab[cfd].linger_risk = 1;
-
-#if defined(TCP_MAXSEG)
-               if (l->maxseg < 0) {
-                       /* we just want to reduce the current MSS by that value */
-                       int mss;
-                       socklen_t mss_len = sizeof(mss);
-                       if (getsockopt(cfd, IPPROTO_TCP, TCP_MAXSEG, &mss, &mss_len) == 0) {
-                               mss += l->maxseg; /* remember, it's < 0 */
-                               setsockopt(cfd, IPPROTO_TCP, TCP_MAXSEG, &mss, sizeof(mss));
-                       }
-               }
-#endif
-       }
-
-       if (global.tune.client_sndbuf)
-               setsockopt(cfd, SOL_SOCKET, SO_SNDBUF, &global.tune.client_sndbuf, sizeof(global.tune.client_sndbuf));
-
-       if (global.tune.client_rcvbuf)
-               setsockopt(cfd, SOL_SOCKET, SO_RCVBUF, &global.tune.client_rcvbuf, sizeof(global.tune.client_rcvbuf));
-
        if (unlikely(fe->nb_req_cap > 0)) {
                if ((s->req_cap = pool_alloc2(fe->req_cap_pool)) == NULL)
                        goto out_return;        /* no memory */
index 6dcbadb4c8381a10f612e953d0eacb31ac693b03..247e4927dcb41cb044ca7805d8c364685e14de6c 100644 (file)
@@ -166,6 +166,35 @@ int session_accept_fd(struct listener *l, int cfd, struct sockaddr_storage *addr
                goto out_free_sess;
        }
 
+       /* Adjust some socket options */
+       if (l->addr.ss_family == AF_INET || l->addr.ss_family == AF_INET6) {
+               setsockopt(cfd, IPPROTO_TCP, TCP_NODELAY, (char *) &one, sizeof(one));
+
+               if (p->options & PR_O_TCP_CLI_KA)
+                       setsockopt(cfd, SOL_SOCKET, SO_KEEPALIVE, (char *) &one, sizeof(one));
+
+               if (p->options & PR_O_TCP_NOLING)
+                       fdtab[cfd].linger_risk = 1;
+
+#if defined(TCP_MAXSEG)
+               if (l->maxseg < 0) {
+                       /* we just want to reduce the current MSS by that value */
+                       int mss;
+                       socklen_t mss_len = sizeof(mss);
+                       if (getsockopt(cfd, IPPROTO_TCP, TCP_MAXSEG, &mss, &mss_len) == 0) {
+                               mss += l->maxseg; /* remember, it's < 0 */
+                               setsockopt(cfd, IPPROTO_TCP, TCP_MAXSEG, &mss, sizeof(mss));
+                       }
+               }
+#endif
+       }
+
+       if (global.tune.client_sndbuf)
+               setsockopt(cfd, SOL_SOCKET, SO_SNDBUF, &global.tune.client_sndbuf, sizeof(global.tune.client_sndbuf));
+
+       if (global.tune.client_rcvbuf)
+               setsockopt(cfd, SOL_SOCKET, SO_RCVBUF, &global.tune.client_rcvbuf, sizeof(global.tune.client_rcvbuf));
+
        if (unlikely((t = task_new()) == NULL))
                goto out_free_sess;