Skip to content

Commit

Permalink
set tcp keepalive for tcp socket (#1045)
Browse files Browse the repository at this point in the history
  • Loading branch information
juntaoliu authored and winlinvip committed Jan 7, 2018
1 parent a6bc53c commit a687105
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ CONTRIBUTORS ordered by first contribution.
* lovecat<littlefawn@163.com> "Bug fixed"
* panda1986<542638787@qq.com> "Bug fixed"
* YueHonghui<hongf.yue@hotmail.com> "Bug fixed"
* JuntaoLiu<juntliu@gmail.com> "Bug fixed"

10 changes: 10 additions & 0 deletions trunk/src/app/srs_app_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ int SrsTcpListener::listen()
}
srs_verbose("setsockopt reuse-addr success. port=%d, fd=%d", port, _fd);

#ifdef SO_KEEPALIVE
int tcp_keepalive = 1;
if (setsockopt(_fd, SOL_SOCKET, SO_KEEPALIVE, &tcp_keepalive, sizeof(int)) == -1) {
ret = ERROR_SOCKET_SETKEEPALIVE;
srs_error("setsockopt SO_KEEPALIVE[%d]error. port=%d, ret=%d", tcp_keepalive, port, ret);
return ret;
}
srs_verbose("setsockopt SO_KEEPALIVE[%d]success. port=%d", tcp_keepalive, port);
#endif

sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
Expand Down
1 change: 1 addition & 0 deletions trunk/src/kernel/srs_kernel_error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define ERROR_SYSTEM_CREATE_DIR 1057
#define ERROR_SYSTEM_KILL 1058
#define ERROR_SYSTEM_DNS_RESOLVE 1059
#define ERROR_SOCKET_SETKEEPALIVE 1060

///////////////////////////////////////////////////////
// RTMP protocol error.
Expand Down

0 comments on commit a687105

Please sign in to comment.