MEDIUM: frontend: move the fd-specific settings to session_accept_fd()
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.
diff --git a/src/frontend.c b/src/frontend.c
index b7f4e19..bb4383b 100644
--- a/src/frontend.c
+++ b/src/frontend.c
@@ -60,38 +60,6 @@
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 */
diff --git a/src/session.c b/src/session.c
index 6dcbadb..247e492 100644
--- a/src/session.c
+++ b/src/session.c
@@ -166,6 +166,35 @@
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;