Skip to content

Commit

Permalink
TCP Fast Open Support
Browse files Browse the repository at this point in the history
Fixes #185
  • Loading branch information
dmatetelki committed Jan 16, 2019
1 parent d42b3e4 commit c168aa7
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
9 changes: 9 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ List of changes
This file contains the running log of changes applied to each released hitch
version.

hitch-xxx (unreleased)
------------------------

* Support for TCP Fast Open. Sinnce kernel version 3.13 Fast Open is enabled by
default (Issue: 185_)

.. _185: https://github.com/varnish/hitch/issues/185


hitch-1.5.0 (2018-12-17)
------------------------

Expand Down
31 changes: 31 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,37 @@ if test "$ac_cv_so_reuseport_works" = yes; then
AC_DEFINE([SO_REUSEPORT_WORKS], [1], [Define if SO_REUSEPORT works])
fi

AC_ARG_ENABLE(tfo,
AC_HELP_STRING([--enable-tfo],
[Enable TCP Fast Open. (default is yes)]),
[use_tfo="$enableval"],
[use_tfo=yes])

if test x"$use_tfo" != xno; then
AC_CACHE_CHECK([whether SO_TFO works],
[ac_cv_so_tfo],
[AC_RUN_IFELSE(
[AC_LANG_PROGRAM([[
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/tcp.h>
]], [[
int s = socket(AF_INET, SOCK_STREAM, 0);
int i = 5;
if (setsockopt(s, SOL_TCP, TCP_FASTOPEN, &i, sizeof i) < 0)
return (1);
return (0);
]])],
[ac_cv_so_tfo=yes],
[ac_cv_so_tfo=no])
]
)
if test "$ac_cv_so_tfo" != yes; then
AC_MSG_ERROR([Socket option TCP_FASTOPEN is not supported by the kernel])
fi
AC_DEFINE([SO_TFO_WORKS], [1], [TCP Fast Open is enabled])
fi

SH_TESTS="$(cd $srcdir/src && echo tests/test*.sh)"
AC_SUBST(SH_TESTS)

Expand Down
11 changes: 11 additions & 0 deletions src/hitch.c
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,17 @@ frontend_listen(const struct front_arg *fa, struct listen_sock_head *slist)
goto creat_frontend_err;
}
#endif

#ifdef SO_TFO_WORKS
if (setsockopt(ls->sock, SOL_TCP, TCP_FASTOPEN,
&t, sizeof(int))
< 0) {
ERR("{setsockopt-tcp_fastopen}: %s: %s\n", strerror(errno),
fa->pspec);
goto creat_frontend_err;
}
#endif

if(setnonblocking(ls->sock) < 0) {
ERR("{listen sock: setnonblocking}: %s: %s\n",
strerror(errno), fa->pspec);
Expand Down

0 comments on commit c168aa7

Please sign in to comment.