This repository has been archived by the owner on May 4, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Windows: the correct way to make TCP_KEEPALIVE work on MinGW
- Loading branch information
1 parent
99b512e
commit c0792e5
Showing
2 changed files
with
5 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c0792e5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello,
Would you mind point me to the right MSDN documentation of
TCP_KEEPALIVE
? I've tried find any reference to it on MSDN without success, onlySO_KEEPALIVE
exists.When run tests with
SO_KEEPALIVE
nothing failed, so I assumed was correct, seems I was not :-(Will be great to bring these missing definitions back to mingw and mingw-w64 projects.
Thank you.
c0792e5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
Calling setsockopt with IPPROTO_TCP and TCP_KEEPALIVE on Windows does not setting keep-alive timeout.
it just enable or disalbe TCP keep-alive option.
To set the keep-alive timeout, you must call WSAIoctl with SIO_KEEPALIVE_VALS and tcp_keepalive struncture.
Refer to http://msdn.microsoft.com/en-us/library/windows/desktop/dd877220(v=vs.85).aspx
http://pgbouncer.sourcearchive.com/documentation/1.4/socket_8h_aa4bb40aa83a8fa42bfa5dff63c46c0fc.html
c0792e5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, IPPROTO_TCP + TCP_KEEPALIVE does map to SIO_KEEPALIVE_VALS + tcp_keepalive.keepalivetime (for API compatibility). You can try setting keep-alive delay through WSAIoctl, and then read it with getsockopt(IPPROTO_TCP,TCP_KEEPALIVE). But yeah we should use winsock WSAIoctl function instead as recommended by MSDN.