mirror of
https://github.com/ossrs/srs.git
synced 2025-02-12 11:21:52 +00:00
set tcp keepalive for tcp socket (#1045)
This commit is contained in:
parent
a6bc53cb85
commit
a6871052af
3 changed files with 12 additions and 0 deletions
|
@ -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"
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue