OSDN Git Service

Change intervals between keep alive packets.
[ffftp/ffftp.git] / connect.c
index 3914924..a931db0 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -38,6 +38,8 @@
 // IPv6対応\r
 //#include <winsock.h>\r
 #include <winsock2.h>\r
+// 切断対策\r
+#include <mstcpip.h>\r
 #include <windowsx.h>\r
 #include <commctrl.h>\r
 \r
@@ -102,6 +104,8 @@ extern int FwallLower;
 extern int FwallDelimiter;\r
 extern int PasvDefault;\r
 extern int QuickAnonymous;\r
+// 切断対策\r
+extern int TimeOut;\r
 \r
 /*===== ローカルなワーク =====*/\r
 \r
@@ -1437,6 +1441,8 @@ static SOCKET DoConnectCrypt(int CryptMode, HOSTDATA* HostData, char *Host, char
        static const char *SiteTbl[4] = { "SITE", "site", "OPEN", "open" };\r
        char TmpBuf[ONELINE_BUF_SIZE];\r
        struct linger LingerOpt;\r
+       struct tcp_keepalive KeepAlive;\r
+       DWORD dwTmp;\r
 \r
        // 暗号化通信対応\r
        ContSock = INVALID_SOCKET;\r
@@ -1510,6 +1516,12 @@ static SOCKET DoConnectCrypt(int CryptMode, HOSTDATA* HostData, char *Host, char
                                        Flg = 1;\r
                                        if(setsockopt(ContSock, SOL_SOCKET, SO_KEEPALIVE, (LPSTR)&Flg, sizeof(Flg)) == SOCKET_ERROR)\r
                                                ReportWSError("setsockopt", WSAGetLastError());\r
+                                       // 切断対策\r
+                                       KeepAlive.onoff = 1;\r
+                                       KeepAlive.keepalivetime = TimeOut * 1000;\r
+                                       KeepAlive.keepaliveinterval = 1000;\r
+                                       if(WSAIoctl(ContSock, SIO_KEEPALIVE_VALS, &KeepAlive, sizeof(struct tcp_keepalive), NULL, 0, &dwTmp, NULL, NULL) == SOCKET_ERROR)\r
+                                               ReportWSError("WSAIoctl", WSAGetLastError());\r
                                        LingerOpt.l_onoff = 1;\r
                                        LingerOpt.l_linger = 90;\r
                                        if(setsockopt(ContSock, SOL_SOCKET, SO_LINGER, (LPSTR)&LingerOpt, sizeof(LingerOpt)) == SOCKET_ERROR)\r