Added support for TCP Keepalive.

This commit is contained in:
Vincent Richard 2016-02-28 20:43:43 +01:00
parent 156edf5cba
commit baec395c8c
3 changed files with 13 additions and 0 deletions

View File

@ -975,6 +975,8 @@ CHECK_FUNCTION_EXISTS(gettid VMIME_HAVE_GETTID)
CHECK_FUNCTION_EXISTS(syscall VMIME_HAVE_SYSCALL)
CHECK_SYMBOL_EXISTS(SYS_gettid sys/syscall.h VMIME_HAVE_SYSCALL_GETTID)
CHECK_SYMBOL_EXISTS(SO_KEEPALIVE sys/socket.h VMIME_HAVE_SO_KEEPALIVE)
FIND_PACKAGE(Threads)
IF(VMIME_BUILD_SHARED_LIBRARY)

View File

@ -84,6 +84,7 @@ typedef unsigned @VMIME_64BIT_TYPE@ vmime_uint64;
#cmakedefine01 VMIME_HAVE_LOCALTIME_S
#cmakedefine01 VMIME_HAVE_LOCALTIME_R
#cmakedefine01 VMIME_HAVE_MLANG
#cmakedefine01 VMIME_HAVE_SO_KEEPALIVE
#cmakedefine01 VMIME_SHARED_PTR_USE_CXX
#cmakedefine01 VMIME_SHARED_PTR_USE_BOOST

View File

@ -138,6 +138,16 @@ void posixSocket::connect(const vmime::string& address, const vmime::port_t port
continue; // try next
}
#if VMIME_HAVE_SO_KEEPALIVE
// Enable TCP Keepalive
int keepAlive_optval = 1;
socklen_t keepAlive_optlen = sizeof(keepAlive_optval);
::setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &keepAlive_optval, keepAlive_optlen);
#endif // VMIME_HAVE_SO_KEEPALIVE
if (m_timeoutHandler != NULL)
{
::fcntl(sock, F_SETFL, ::fcntl(sock, F_GETFL) | O_NONBLOCK);