浏览代码

Merge pull request #101 from beinvisible/master

enable TCP keepalive
scandum 3 年之前
父节点
当前提交
f10d67801c
共有 1 个文件被更改,包括 6 次插入0 次删除
  1. 6 0
      src/net.c

+ 6 - 0
src/net.c

@@ -145,6 +145,12 @@ int connect_mud(struct session *ses, char *host, char *port)
 		return -1;
 	}
 
+	int optval = 1;
+	if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(optval)) < 0)
+	{
+		syserr_printf(ses, "connect_mud: unable to use tcp keepalive, continuing without");
+	}
+
 	ses->connect_error = connect(sock, address->ai_addr, address->ai_addrlen);
 
 	if (fcntl(sock, F_SETFL, O_NDELAY|O_NONBLOCK) == -1)