OSDN Git Service

Modify documents.
[ffftp/ffftp.git] / socket.c
index 605abaf..1da9215 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -1,6 +1,6 @@
-/*=============================================================================\r
+/*=============================================================================\r
 *\r
-*                                                                      \83\\83P\83b\83g\r
+*                                                                      ソケット\r
 *\r
 ===============================================================================\r
 / Copyright (C) 1997-2007 Sota. All rights reserved.\r
@@ -28,6 +28,8 @@
 /============================================================================*/\r
 \r
 #define        STRICT\r
+// IPv6対応\r
+#include <winsock2.h>\r
 #include <windows.h>\r
 #include <stdio.h>\r
 #include <stdlib.h>\r
 \r
 \r
 \r
-#define FD_CONNECT_BIT         0x0001\r
-#define FD_CLOSE_BIT           0x0002\r
-#define FD_ACCEPT_BIT          0x0004\r
-#define FD_READ_BIT                    0x0008\r
-#define FD_WRITE_BIT           0x0010\r
+// Winsock2で定義される定数と名前が重複し値が異なるため使用不可\r
+//#define FD_CONNECT_BIT               0x0001\r
+//#define FD_CLOSE_BIT         0x0002\r
+//#define FD_ACCEPT_BIT                0x0004\r
+//#define FD_READ_BIT                  0x0008\r
+//#define FD_WRITE_BIT         0x0010\r
 \r
 \r
 \r
@@ -63,6 +66,11 @@ typedef struct {
        int FdRead;\r
        int FdWrite;\r
        int Error;\r
+       // ソケットにデータを付与\r
+       struct sockaddr_in HostAddrIPv4;\r
+       struct sockaddr_in SocksAddrIPv4;\r
+       struct sockaddr_in6 HostAddrIPv6;\r
+       struct sockaddr_in6 SocksAddrIPv6;\r
 } ASYNCSIGNAL;\r
 \r
 \r
@@ -73,33 +81,33 @@ typedef struct {
 } ASYNCSIGNALDATABASE;\r
 \r
 \r
-// \83X\83\8c\83b\83h\8fÕ\93Ë\82Ì\83o\83O\8fC\90³\r
-// \94O\82Ì\82½\82ß\83e\81[\83u\83\8b\82ð\91\9d\97Ê\r
+// スレッド衝突のバグ修正\r
+// 念のためテーブルを増量\r
 //#define MAX_SIGNAL_ENTRY             10\r
 //#define MAX_SIGNAL_ENTRY_DBASE       5\r
-#define MAX_SIGNAL_ENTRY               100\r
-#define MAX_SIGNAL_ENTRY_DBASE 50\r
+#define MAX_SIGNAL_ENTRY               16\r
+#define MAX_SIGNAL_ENTRY_DBASE 16\r
 \r
 \r
 \r
 \r
-/*===== \83v\83\8d\83g\83^\83C\83v =====*/\r
+/*===== プロトタイプ =====*/\r
 \r
 static LRESULT CALLBACK SocketWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);\r
 static int AskAsyncDone(SOCKET s, int *Error, int Mask);\r
 static int AskAsyncDoneDbase(HANDLE Async, int *Error);\r
-static int RegistAsyncTable(SOCKET s);\r
-static int RegistAsyncTableDbase(HANDLE Async);\r
-static int UnRegistAsyncTable(SOCKET s);\r
-static int UnRegistAsyncTableDbase(HANDLE Async);\r
+static int RegisterAsyncTable(SOCKET s);\r
+static int RegisterAsyncTableDbase(HANDLE Async);\r
+static int UnregisterAsyncTable(SOCKET s);\r
+static int UnregisterAsyncTableDbase(HANDLE Async);\r
 \r
 \r
-/*===== \8aO\95\94\8eQ\8fÆ =====*/\r
+/*===== 外部参照 =====*/\r
 \r
 extern int TimeOut;\r
 \r
 \r
-/*===== \83\8d\81[\83J\83\8b\82È\83\8f\81[\83N =====*/\r
+/*===== ローカルなワーク =====*/\r
 \r
 static const char SocketWndClass[] = "FFFTPSocketWnd";\r
 static HWND hWndSocket;\r
@@ -108,7 +116,7 @@ static ASYNCSIGNAL Signal[MAX_SIGNAL_ENTRY];
 static ASYNCSIGNALDATABASE SignalDbase[MAX_SIGNAL_ENTRY_DBASE];\r
 \r
 //static HANDLE hAsyncTblAccMutex;\r
-// \83X\83\8c\83b\83h\8fÕ\93Ë\82Ì\83o\83O\8fC\90³\r
+// スレッド衝突のバグ修正\r
 static HANDLE hAsyncTblAccMutex;\r
 \r
 \r
@@ -120,8 +128,8 @@ static HANDLE hAsyncTblAccMutex;
 *      Parameter\r
 *\r
 *      Return Value\r
-*              int \83X\83e\81[\83^\83X\r
-*                      SUCCESS/FAIL\r
+*              int ステータス\r
+*                      FFFTP_SUCCESS/FFFTP_FAIL\r
 *----------------------------------------------------------------------------*/\r
 \r
 int MakeSocketWin(HWND hWnd, HINSTANCE hInst)\r
@@ -144,7 +152,7 @@ int MakeSocketWin(HWND hWnd, HINSTANCE hInst)
        wClass.hIconSm       = NULL;\r
        RegisterClassEx(&wClass);\r
 \r
-       Sts = FAIL;\r
+       Sts = FFFTP_FAIL;\r
        hWndSocket = CreateWindowEx(0, SocketWndClass, NULL,\r
                        WS_BORDER | WS_POPUP,\r
                        0, 0, 0, 0,\r
@@ -154,7 +162,7 @@ int MakeSocketWin(HWND hWnd, HINSTANCE hInst)
        {\r
 //             hAsyncTblAccMutex = CreateMutex(NULL, FALSE, NULL);\r
 \r
-               // \83X\83\8c\83b\83h\8fÕ\93Ë\82Ì\83o\83O\8fC\90³\r
+               // スレッド衝突のバグ修正\r
 //             for(i = 0; i < MAX_SIGNAL_ENTRY; i++)\r
 //                     Signal[i].Socket = INVALID_SOCKET;\r
 //             for(i = 0; i < MAX_SIGNAL_ENTRY_DBASE; i++)\r
@@ -166,7 +174,7 @@ int MakeSocketWin(HWND hWnd, HINSTANCE hInst)
                        for(i = 0; i < MAX_SIGNAL_ENTRY_DBASE; i++)\r
                                SignalDbase[i].Async = 0;\r
                }\r
-               Sts = SUCCESS;\r
+               Sts = FFFTP_SUCCESS;\r
        }\r
        return(Sts);\r
 }\r
@@ -175,16 +183,16 @@ int MakeSocketWin(HWND hWnd, HINSTANCE hInst)
 /*----- \r
 *\r
 *      Parameter\r
-*              \82È\82µ\r
+*              なし\r
 *\r
 *      Return Value\r
-*              \82È\82µ\r
+*              なし\r
 *----------------------------------------------------------------------------*/\r
 \r
 void DeleteSocketWin(void)\r
 {\r
 //     CloseHandle(hAsyncTblAccMutex);\r
-       // \83X\83\8c\83b\83h\8fÕ\93Ë\82Ì\83o\83O\8fC\90³\r
+       // スレッド衝突のバグ修正\r
        CloseHandle(hAsyncTblAccMutex);\r
        hAsyncTblAccMutex = NULL;\r
 \r
@@ -197,10 +205,10 @@ void DeleteSocketWin(void)
 /*----- \r
 *\r
 *      Parameter\r
-*              HWND hWnd : \83E\83C\83\93\83h\83E\83n\83\93\83h\83\8b\r
-*              UINT message : \83\81\83b\83Z\81[\83W\94Ô\8d\86\r
-*              WPARAM wParam : \83\81\83b\83Z\81[\83W\82Ì WPARAM \88ø\90\94\r
-*              LPARAM lParam : \83\81\83b\83Z\81[\83W\82Ì LPARAM \88ø\90\94\r
+*              HWND hWnd : ウインドウハンドル\r
+*              UINT message : メッセージ番号\r
+*              WPARAM wParam : メッセージの WPARAM 引数\r
+*              LPARAM lParam : メッセージの LPARAM 引数\r
 *\r
 *      Return Value\r
 *              BOOL TRUE/FALSE\r
@@ -213,7 +221,7 @@ static LRESULT CALLBACK SocketWndProc(HWND hWnd, UINT message, WPARAM wParam, LP
        switch(message)\r
        {\r
                case WM_ASYNC_SOCKET :\r
-                       // \83X\83\8c\83b\83h\8fÕ\93Ë\82Ì\83o\83O\8fC\90³\r
+                       // スレッド衝突のバグ修正\r
                        WaitForSingleObject(hAsyncTblAccMutex, INFINITE);\r
                        for(Pos = 0; Pos < MAX_SIGNAL_ENTRY; Pos++)\r
                        {\r
@@ -266,12 +274,14 @@ static LRESULT CALLBACK SocketWndProc(HWND hWnd, UINT message, WPARAM wParam, LP
                                        break;\r
                                }\r
                        }\r
-                       // \83X\83\8c\83b\83h\8fÕ\93Ë\82Ì\83o\83O\8fC\90³\r
+                       // スレッド衝突のバグ修正\r
                        ReleaseMutex(hAsyncTblAccMutex);\r
                        break;\r
 \r
                case WM_ASYNC_DBASE :\r
-                       // \83X\83\8c\83b\83h\8fÕ\93Ë\82Ì\83o\83O\8fC\90³\r
+                       // APIの仕様上ハンドルが登録される前にウィンドウメッセージが呼び出される可能性あり\r
+                       RegisterAsyncTableDbase((HANDLE)wParam);\r
+                       // スレッド衝突のバグ修正\r
                        WaitForSingleObject(hAsyncTblAccMutex, INFINITE);\r
                        for(Pos = 0; Pos < MAX_SIGNAL_ENTRY_DBASE; Pos++)\r
                        {\r
@@ -291,7 +301,7 @@ static LRESULT CALLBACK SocketWndProc(HWND hWnd, UINT message, WPARAM wParam, LP
                                        break;\r
                                }\r
                        }\r
-                       // \83X\83\8c\83b\83h\8fÕ\93Ë\82Ì\83o\83O\8fC\90³\r
+                       // スレッド衝突のバグ修正\r
                        ReleaseMutex(hAsyncTblAccMutex);\r
                        break;\r
 \r
@@ -318,7 +328,7 @@ static int AskAsyncDone(SOCKET s, int *Error, int Mask)
        int Sts;\r
        int Pos;\r
 \r
-       // \83X\83\8c\83b\83h\8fÕ\93Ë\82Ì\83o\83O\8fC\90³\r
+       // スレッド衝突のバグ修正\r
        WaitForSingleObject(hAsyncTblAccMutex, INFINITE);\r
        Sts = NO;\r
        *Error = 0;\r
@@ -329,22 +339,22 @@ static int AskAsyncDone(SOCKET s, int *Error, int Mask)
                        *Error = Signal[Pos].Error;\r
                        if(Signal[Pos].Error != 0)\r
                                Sts = YES;\r
-                       if((Mask & FD_CONNECT_BIT) && (Signal[Pos].FdConnect != 0))\r
+                       if((Mask & FD_CONNECT) && (Signal[Pos].FdConnect != 0))\r
                        {\r
                                Sts = YES;\r
 #if DBG_MSG\r
                                DoPrintf("### Ask: connect (Sts=%d, Error=%d)", Sts, *Error);\r
 #endif\r
                        }\r
-                       if((Mask & FD_CLOSE_BIT) && (Signal[Pos].FdClose != 0))\r
-//                     if(Mask & FD_CLOSE_BIT)\r
+                       if((Mask & FD_CLOSE) && (Signal[Pos].FdClose != 0))\r
+//                     if(Mask & FD_CLOSE)\r
                        {\r
                                Sts = YES;\r
 #if DBG_MSG\r
                                DoPrintf("### Ask: close (Sts=%d, Error=%d)", Sts, *Error);\r
 #endif\r
                        }\r
-                       if((Mask & FD_ACCEPT_BIT) && (Signal[Pos].FdAccept != 0))\r
+                       if((Mask & FD_ACCEPT) && (Signal[Pos].FdAccept != 0))\r
                        {\r
                                Signal[Pos].FdAccept = 0;\r
                                Sts = YES;\r
@@ -352,7 +362,7 @@ static int AskAsyncDone(SOCKET s, int *Error, int Mask)
                                DoPrintf("### Ask: accept (Sts=%d, Error=%d)", Sts, *Error);\r
 #endif\r
                        }\r
-                       if((Mask & FD_READ_BIT) && (Signal[Pos].FdRead != 0))\r
+                       if((Mask & FD_READ) && (Signal[Pos].FdRead != 0))\r
                        {\r
                                Signal[Pos].FdRead = 0;\r
                                Sts = YES;\r
@@ -360,7 +370,7 @@ static int AskAsyncDone(SOCKET s, int *Error, int Mask)
                                DoPrintf("### Ask: read (Sts=%d, Error=%d)", Sts, *Error);\r
 #endif\r
                        }\r
-                       if((Mask & FD_WRITE_BIT) && (Signal[Pos].FdWrite != 0))\r
+                       if((Mask & FD_WRITE) && (Signal[Pos].FdWrite != 0))\r
                        {\r
                                Signal[Pos].FdWrite = 0;\r
                                Sts = YES;\r
@@ -371,12 +381,12 @@ static int AskAsyncDone(SOCKET s, int *Error, int Mask)
                        break;\r
                }\r
        }\r
-       // \83X\83\8c\83b\83h\8fÕ\93Ë\82Ì\83o\83O\8fC\90³\r
+       // スレッド衝突のバグ修正\r
        ReleaseMutex(hAsyncTblAccMutex);\r
 \r
        if(Pos == MAX_SIGNAL_ENTRY)\r
        {\r
-               if(Mask & FD_CLOSE_BIT)\r
+               if(Mask & FD_CLOSE)\r
                {\r
                                Sts = YES;\r
                }\r
@@ -404,7 +414,7 @@ static int AskAsyncDoneDbase(HANDLE Async, int *Error)
        int Sts;\r
        int Pos;\r
 \r
-       // \83X\83\8c\83b\83h\8fÕ\93Ë\82Ì\83o\83O\8fC\90³\r
+       // スレッド衝突のバグ修正\r
        WaitForSingleObject(hAsyncTblAccMutex, INFINITE);\r
        Sts = NO;\r
        *Error = 0;\r
@@ -423,7 +433,7 @@ static int AskAsyncDoneDbase(HANDLE Async, int *Error)
                        break;\r
                }\r
        }\r
-       // \83X\83\8c\83b\83h\8fÕ\93Ë\82Ì\83o\83O\8fC\90³\r
+       // スレッド衝突のバグ修正\r
        ReleaseMutex(hAsyncTblAccMutex);\r
 \r
        if(Pos == MAX_SIGNAL_ENTRY_DBASE)\r
@@ -445,28 +455,30 @@ static int AskAsyncDoneDbase(HANDLE Async, int *Error)
 *              \r
 *----------------------------------------------------------------------------*/\r
 \r
-static int RegistAsyncTable(SOCKET s)\r
+static int RegisterAsyncTable(SOCKET s)\r
 {\r
        int Sts;\r
        int Pos;\r
 \r
-       // \83X\83\8c\83b\83h\8fÕ\93Ë\82Ì\83o\83O\8fC\90³\r
+       // スレッド衝突のバグ修正\r
        WaitForSingleObject(hAsyncTblAccMutex, INFINITE);\r
        Sts = NO;\r
        for(Pos = 0; Pos < MAX_SIGNAL_ENTRY; Pos++)\r
        {\r
                if(Signal[Pos].Socket == s)\r
                {\r
-                       MessageBox(GetMainHwnd(), "Async socket already registerd.", "FFFTP inner error", MB_OK);\r
-                       break;\r
+                       // 強制的に閉じられたソケットがあると重複する可能性あり\r
+//                     MessageBox(GetMainHwnd(), "Async socket already registerd.", "FFFTP inner error", MB_OK);\r
+//                     break;\r
+                       Signal[Pos].Socket = INVALID_SOCKET;\r
                }\r
        }\r
-       // \83X\83\8c\83b\83h\8fÕ\93Ë\82Ì\83o\83O\8fC\90³\r
+       // スレッド衝突のバグ修正\r
        ReleaseMutex(hAsyncTblAccMutex);\r
 \r
        if(Pos == MAX_SIGNAL_ENTRY)\r
        {\r
-               // \83X\83\8c\83b\83h\8fÕ\93Ë\82Ì\83o\83O\8fC\90³\r
+               // スレッド衝突のバグ修正\r
                WaitForSingleObject(hAsyncTblAccMutex, INFINITE);\r
                for(Pos = 0; Pos < MAX_SIGNAL_ENTRY; Pos++)\r
                {\r
@@ -482,11 +494,16 @@ static int RegistAsyncTable(SOCKET s)
                                Signal[Pos].FdAccept = 0;\r
                                Signal[Pos].FdRead = 0;\r
                                Signal[Pos].FdWrite = 0;\r
+                               // ソケットにデータを付与\r
+                               memset(&Signal[Pos].HostAddrIPv4, 0, sizeof(struct sockaddr_in));\r
+                               memset(&Signal[Pos].SocksAddrIPv4, 0, sizeof(struct sockaddr_in));\r
+                               memset(&Signal[Pos].HostAddrIPv6, 0, sizeof(struct sockaddr_in6));\r
+                               memset(&Signal[Pos].SocksAddrIPv6, 0, sizeof(struct sockaddr_in6));\r
                                Sts = YES;\r
                                break;\r
                        }\r
                }\r
-               // \83X\83\8c\83b\83h\8fÕ\93Ë\82Ì\83o\83O\8fC\90³\r
+               // スレッド衝突のバグ修正\r
                ReleaseMutex(hAsyncTblAccMutex);\r
 \r
                if(Pos == MAX_SIGNAL_ENTRY)\r
@@ -509,28 +526,30 @@ static int RegistAsyncTable(SOCKET s)
 *              \r
 *----------------------------------------------------------------------------*/\r
 \r
-static int RegistAsyncTableDbase(HANDLE Async)\r
+static int RegisterAsyncTableDbase(HANDLE Async)\r
 {\r
        int Sts;\r
        int Pos;\r
 \r
-       // \83X\83\8c\83b\83h\8fÕ\93Ë\82Ì\83o\83O\8fC\90³\r
+       // スレッド衝突のバグ修正\r
        WaitForSingleObject(hAsyncTblAccMutex, INFINITE);\r
        Sts = NO;\r
        for(Pos = 0; Pos < MAX_SIGNAL_ENTRY_DBASE; Pos++)\r
        {\r
                if(SignalDbase[Pos].Async == Async)\r
                {\r
-                       MessageBox(GetMainHwnd(), "Async handle already registerd.", "FFFTP inner error", MB_OK);\r
+                       // 強制的に閉じられたハンドルがあると重複する可能性あり\r
+//                     MessageBox(GetMainHwnd(), "Async handle already registerd.", "FFFTP inner error", MB_OK);\r
+                       // APIの仕様上ハンドルが登録される前にウィンドウメッセージが呼び出される可能性あり\r
                        break;\r
                }\r
        }\r
-       // \83X\83\8c\83b\83h\8fÕ\93Ë\82Ì\83o\83O\8fC\90³\r
+       // スレッド衝突のバグ修正\r
        ReleaseMutex(hAsyncTblAccMutex);\r
 \r
        if(Pos == MAX_SIGNAL_ENTRY_DBASE)\r
        {\r
-               // \83X\83\8c\83b\83h\8fÕ\93Ë\82Ì\83o\83O\8fC\90³\r
+               // スレッド衝突のバグ修正\r
                WaitForSingleObject(hAsyncTblAccMutex, INFINITE);\r
                for(Pos = 0; Pos < MAX_SIGNAL_ENTRY; Pos++)\r
                {\r
@@ -546,7 +565,7 @@ static int RegistAsyncTableDbase(HANDLE Async)
                                break;\r
                        }\r
                }\r
-               // \83X\83\8c\83b\83h\8fÕ\93Ë\82Ì\83o\83O\8fC\90³\r
+               // スレッド衝突のバグ修正\r
                ReleaseMutex(hAsyncTblAccMutex);\r
 \r
                if(Pos == MAX_SIGNAL_ENTRY_DBASE)\r
@@ -569,12 +588,12 @@ static int RegistAsyncTableDbase(HANDLE Async)
 *              \r
 *----------------------------------------------------------------------------*/\r
 \r
-static int UnRegistAsyncTable(SOCKET s)\r
+static int UnregisterAsyncTable(SOCKET s)\r
 {\r
        int Sts;\r
        int Pos;\r
 \r
-       // \83X\83\8c\83b\83h\8fÕ\93Ë\82Ì\83o\83O\8fC\90³\r
+       // スレッド衝突のバグ修正\r
        WaitForSingleObject(hAsyncTblAccMutex, INFINITE);\r
        Sts = NO;\r
        for(Pos = 0; Pos < MAX_SIGNAL_ENTRY; Pos++)\r
@@ -589,7 +608,7 @@ static int UnRegistAsyncTable(SOCKET s)
                        break;\r
                }\r
        }\r
-       // \83X\83\8c\83b\83h\8fÕ\93Ë\82Ì\83o\83O\8fC\90³\r
+       // スレッド衝突のバグ修正\r
        ReleaseMutex(hAsyncTblAccMutex);\r
        return(Sts);\r
 }\r
@@ -604,12 +623,12 @@ static int UnRegistAsyncTable(SOCKET s)
 *              \r
 *----------------------------------------------------------------------------*/\r
 \r
-static int UnRegistAsyncTableDbase(HANDLE Async)\r
+static int UnregisterAsyncTableDbase(HANDLE Async)\r
 {\r
        int Sts;\r
        int Pos;\r
 \r
-       // \83X\83\8c\83b\83h\8fÕ\93Ë\82Ì\83o\83O\8fC\90³\r
+       // スレッド衝突のバグ修正\r
        WaitForSingleObject(hAsyncTblAccMutex, INFINITE);\r
        Sts = NO;\r
        for(Pos = 0; Pos < MAX_SIGNAL_ENTRY_DBASE; Pos++)\r
@@ -624,11 +643,109 @@ static int UnRegistAsyncTableDbase(HANDLE Async)
                        break;\r
                }\r
        }\r
-       // \83X\83\8c\83b\83h\8fÕ\93Ë\82Ì\83o\83O\8fC\90³\r
+       // スレッド衝突のバグ修正\r
+       ReleaseMutex(hAsyncTblAccMutex);\r
+       return(Sts);\r
+}\r
+\r
+\r
+// ソケットにデータを付与\r
+\r
+int SetAsyncTableDataIPv4(SOCKET s, struct sockaddr_in* Host, struct sockaddr_in* Socks)\r
+{\r
+       int Sts;\r
+       int Pos;\r
+\r
+       WaitForSingleObject(hAsyncTblAccMutex, INFINITE);\r
+       Sts = NO;\r
+       for(Pos = 0; Pos < MAX_SIGNAL_ENTRY; Pos++)\r
+       {\r
+               if(Signal[Pos].Socket == s)\r
+               {\r
+                       if(Host != NULL)\r
+                               memcpy(&Signal[Pos].HostAddrIPv4, Host, sizeof(struct sockaddr_in));\r
+                       if(Socks != NULL)\r
+                               memcpy(&Signal[Pos].SocksAddrIPv4, Socks, sizeof(struct sockaddr_in));\r
+                       Sts = YES;\r
+                       break;\r
+               }\r
+       }\r
+       ReleaseMutex(hAsyncTblAccMutex);\r
+\r
+       return(Sts);\r
+}\r
+\r
+int SetAsyncTableDataIPv6(SOCKET s, struct sockaddr_in6* Host, struct sockaddr_in6* Socks)\r
+{\r
+       int Sts;\r
+       int Pos;\r
+\r
+       WaitForSingleObject(hAsyncTblAccMutex, INFINITE);\r
+       Sts = NO;\r
+       for(Pos = 0; Pos < MAX_SIGNAL_ENTRY; Pos++)\r
+       {\r
+               if(Signal[Pos].Socket == s)\r
+               {\r
+                       if(Host != NULL)\r
+                               memcpy(&Signal[Pos].HostAddrIPv6, Host, sizeof(struct sockaddr_in6));\r
+                       if(Socks != NULL)\r
+                               memcpy(&Signal[Pos].SocksAddrIPv6, Socks, sizeof(struct sockaddr_in6));\r
+                       Sts = YES;\r
+                       break;\r
+               }\r
+       }\r
+       ReleaseMutex(hAsyncTblAccMutex);\r
+\r
+       return(Sts);\r
+}\r
+\r
+int GetAsyncTableDataIPv4(SOCKET s, struct sockaddr_in* Host, struct sockaddr_in* Socks)\r
+{\r
+       int Sts;\r
+       int Pos;\r
+\r
+       WaitForSingleObject(hAsyncTblAccMutex, INFINITE);\r
+       Sts = NO;\r
+       for(Pos = 0; Pos < MAX_SIGNAL_ENTRY; Pos++)\r
+       {\r
+               if(Signal[Pos].Socket == s)\r
+               {\r
+                       if(Host != NULL)\r
+                               memcpy(Host, &Signal[Pos].HostAddrIPv4, sizeof(struct sockaddr_in));\r
+                       if(Socks != NULL)\r
+                               memcpy(Socks, &Signal[Pos].SocksAddrIPv4, sizeof(struct sockaddr_in));\r
+                       Sts = YES;\r
+                       break;\r
+               }\r
+       }\r
        ReleaseMutex(hAsyncTblAccMutex);\r
+\r
        return(Sts);\r
 }\r
 \r
+int GetAsyncTableDataIPv6(SOCKET s, struct sockaddr_in6* Host, struct sockaddr_in6* Socks)\r
+{\r
+       int Sts;\r
+       int Pos;\r
+\r
+       WaitForSingleObject(hAsyncTblAccMutex, INFINITE);\r
+       Sts = NO;\r
+       for(Pos = 0; Pos < MAX_SIGNAL_ENTRY; Pos++)\r
+       {\r
+               if(Signal[Pos].Socket == s)\r
+               {\r
+                       if(Host != NULL)\r
+                               memcpy(Host, &Signal[Pos].HostAddrIPv6, sizeof(struct sockaddr_in6));\r
+                       if(Socks != NULL)\r
+                               memcpy(Socks, &Signal[Pos].SocksAddrIPv6, sizeof(struct sockaddr_in6));\r
+                       Sts = YES;\r
+                       break;\r
+               }\r
+       }\r
+       ReleaseMutex(hAsyncTblAccMutex);\r
+\r
+       return(Sts);\r
+}\r
 \r
 \r
 \r
@@ -636,7 +753,9 @@ static int UnRegistAsyncTableDbase(HANDLE Async)
 \r
 \r
 \r
-struct hostent *do_gethostbyname(const char *Name, char *Buf, int Len, int *CancelCheckWork)\r
+// IPv6対応\r
+//struct hostent *do_gethostbyname(const char *Name, char *Buf, int Len, int *CancelCheckWork)\r
+struct hostent *do_gethostbynameIPv4(const char *Name, char *Buf, int Len, int *CancelCheckWork)\r
 {\r
 #if USE_THIS\r
        struct hostent *Ret;\r
@@ -647,12 +766,15 @@ struct hostent *do_gethostbyname(const char *Name, char *Buf, int Len, int *Canc
        DoPrintf("# Start gethostbyname");\r
 #endif\r
        Ret = NULL;\r
-       *CancelCheckWork = NO;\r
+       // 同時接続対応\r
+//     *CancelCheckWork = NO;\r
 \r
-       hAsync = WSAAsyncGetHostByName(hWndSocket, WM_ASYNC_DBASE, Name, Buf, Len);\r
+       // UTF-8対応\r
+//     hAsync = WSAAsyncGetHostByName(hWndSocket, WM_ASYNC_DBASE, Name, Buf, Len);\r
+       hAsync = WSAAsyncGetHostByNameM(hWndSocket, WM_ASYNC_DBASE, Name, Buf, Len);\r
        if(hAsync != NULL)\r
        {\r
-               RegistAsyncTableDbase(hAsync);\r
+               RegisterAsyncTableDbase(hAsync);\r
                while((*CancelCheckWork == NO) && (AskAsyncDoneDbase(hAsync, &Error) != YES))\r
                {\r
                        Sleep(1);\r
@@ -668,7 +790,51 @@ struct hostent *do_gethostbyname(const char *Name, char *Buf, int Len, int *Canc
                {\r
                        Ret = (struct hostent *)Buf;\r
                }\r
-               UnRegistAsyncTableDbase(hAsync);\r
+               UnregisterAsyncTableDbase(hAsync);\r
+       }\r
+       return(Ret);\r
+#else\r
+       return(gethostbyname(Name));\r
+#endif\r
+}\r
+\r
+\r
+struct hostent *do_gethostbynameIPv6(const char *Name, char *Buf, int Len, int *CancelCheckWork)\r
+{\r
+#if USE_THIS\r
+       struct hostent *Ret;\r
+       HANDLE hAsync;\r
+       int Error;\r
+\r
+#if DBG_MSG\r
+       DoPrintf("# Start gethostbyname");\r
+#endif\r
+       Ret = NULL;\r
+       // 同時接続対応\r
+//     *CancelCheckWork = NO;\r
+\r
+       // UTF-8対応\r
+//     hAsync = WSAAsyncGetHostByName(hWndSocket, WM_ASYNC_DBASE, Name, Buf, Len);\r
+       hAsync = WSAAsyncGetHostByNameIPv6M(hWndSocket, WM_ASYNC_DBASE, Name, Buf, Len, AF_INET6);\r
+       if(hAsync != NULL)\r
+       {\r
+               RegisterAsyncTableDbase(hAsync);\r
+               while((*CancelCheckWork == NO) && (AskAsyncDoneDbase(hAsync, &Error) != YES))\r
+               {\r
+                       Sleep(1);\r
+                       if(BackgrndMessageProc() == YES)\r
+                               *CancelCheckWork = YES;\r
+               }\r
+\r
+               if(*CancelCheckWork == YES)\r
+               {\r
+                       WSACancelAsyncRequestIPv6(hAsync);\r
+               }\r
+               else if(Error == 0)\r
+               {\r
+                       Ret = (struct hostent *)Buf;\r
+               }\r
+               UnregisterAsyncTableDbase(hAsync);\r
        }\r
        return(Ret);\r
 #else\r
@@ -687,7 +853,7 @@ SOCKET do_socket(int af, int type, int protocol)
        Ret = socket(af, type, protocol);\r
        if(Ret != INVALID_SOCKET)\r
        {\r
-               RegistAsyncTable(Ret);\r
+               RegisterAsyncTable(Ret);\r
        }\r
 #if DBG_MSG\r
        DoPrintf("# do_socket (S=%x)", Ret);\r
@@ -709,16 +875,16 @@ int do_closesocket(SOCKET s)
 #endif\r
        CancelCheckWork = NO;\r
 \r
-       // FTPS\91Î\89\9e\r
+       // スレッド衝突のバグ修正\r
+       WSAAsyncSelect(s, hWndSocket, WM_ASYNC_SOCKET, 0);\r
+       UnregisterAsyncTable(s);\r
+       // FTPS対応\r
 //     Ret = closesocket(s);\r
-       if(AskCryptMode() == CRYPT_FTPES || AskCryptMode() == CRYPT_FTPIS)\r
-               Ret = closesocketS(s);\r
-       else\r
-               Ret = closesocket(s);\r
+       Ret = FTPS_closesocket(s);\r
        if(Ret == SOCKET_ERROR)\r
        {\r
                Error = 0;\r
-               while((CancelCheckWork == NO) && (AskAsyncDone(s, &Error, FD_CLOSE_BIT) != YES))\r
+               while((CancelCheckWork == NO) && (AskAsyncDone(s, &Error, FD_CLOSE) != YES))\r
                {\r
                        Sleep(1);\r
                        if(BackgrndMessageProc() == YES)\r
@@ -729,10 +895,12 @@ int do_closesocket(SOCKET s)
                        Ret = 0;\r
        }\r
 \r
-       WSAAsyncSelect(s, hWndSocket, WM_ASYNC_SOCKET, 0);\r
+       // スレッド衝突のバグ修正\r
+//     WSAAsyncSelect(s, hWndSocket, WM_ASYNC_SOCKET, 0);\r
        if(BackgrndMessageProc() == YES)\r
                CancelCheckWork = YES;\r
-       UnRegistAsyncTable(s);\r
+       // スレッド衝突のバグ修正\r
+//     UnregisterAsyncTable(s);\r
 \r
 #if DBG_MSG\r
        DoPrintf("# Exit close");\r
@@ -757,26 +925,24 @@ int do_connect(SOCKET s, const struct sockaddr *name, int namelen, int *CancelCh
 #if DBG_MSG\r
        DoPrintf("# Start connect (S=%x)", s);\r
 #endif\r
-       *CancelCheckWork = NO;\r
+       // 同時接続対応\r
+//     *CancelCheckWork = NO;\r
 \r
 #if DBG_MSG\r
        DoPrintf("## Async set: FD_CONNECT|FD_CLOSE|FD_ACCEPT|FD_READ|FD_WRITE");\r
 #endif\r
-       Ret = WSAAsyncSelect(s, hWndSocket, WM_ASYNC_SOCKET, FD_CONNECT | FD_CLOSE | FD_ACCEPT | FD_READ | FD_WRITE);\r
+       // 高速化のためFD_READとFD_WRITEを使用しない\r
+//     Ret = WSAAsyncSelect(s, hWndSocket, WM_ASYNC_SOCKET, FD_CONNECT | FD_CLOSE | FD_ACCEPT | FD_READ | FD_WRITE);\r
+       Ret = WSAAsyncSelect(s, hWndSocket, WM_ASYNC_SOCKET, FD_CONNECT | FD_CLOSE | FD_ACCEPT);\r
        if(Ret != SOCKET_ERROR)\r
        {\r
-               // FTPS\91Î\89\9e\r
-//             Ret = connect(s, name, namelen);\r
-               if(AskCryptMode() == CRYPT_FTPIS)\r
-                       Ret = connectS(s, name, namelen);\r
-               else\r
-                       Ret = connect(s, name, namelen);\r
+               Ret = connect(s, name, namelen);\r
                if(Ret == SOCKET_ERROR)\r
                {\r
                        do\r
                        {\r
                                Error = 0;\r
-                               while((*CancelCheckWork == NO) && (AskAsyncDone(s, &Error, FD_CONNECT_BIT) != YES))\r
+                               while((*CancelCheckWork == NO) && (AskAsyncDone(s, &Error, FD_CONNECT) != YES))\r
                                {\r
                                        Sleep(1);\r
                                        if(BackgrndMessageProc() == YES)\r
@@ -848,9 +1014,9 @@ SOCKET do_accept(SOCKET s, struct sockaddr *addr, int *addrlen)
        Ret2 = INVALID_SOCKET;\r
        Error = 0;\r
 \r
-       while((CancelCheckWork == NO) && (AskAsyncDone(s, &Error, FD_ACCEPT_BIT) != YES))\r
+       while((CancelCheckWork == NO) && (AskAsyncDone(s, &Error, FD_ACCEPT) != YES))\r
        {\r
-               if(AskAsyncDone(s, &Error, FD_CLOSE_BIT) == YES)\r
+               if(AskAsyncDone(s, &Error, FD_CLOSE) == YES)\r
                {\r
                        Error = 1;\r
                        break;\r
@@ -864,20 +1030,17 @@ SOCKET do_accept(SOCKET s, struct sockaddr *addr, int *addrlen)
        {\r
                do\r
                {\r
-                       // FTPS\91Î\89\9e\r
-//                     Ret2 = accept(s, addr, addrlen);\r
-                       if(AskCryptMode() == CRYPT_FTPIS)\r
-                               Ret2 = acceptS(s, addr, addrlen);\r
-                       else\r
-                               Ret2 = accept(s, addr, addrlen);\r
+                       Ret2 = accept(s, addr, addrlen);\r
                        if(Ret2 != INVALID_SOCKET)\r
                        {\r
 #if DBG_MSG\r
                                DoPrintf("## do_sccept (S=%x)", Ret2);\r
                                DoPrintf("## Async set: FD_CONNECT|FD_CLOSE|FD_ACCEPT|FD_READ|FD_WRITE");\r
 #endif\r
-                               RegistAsyncTable(Ret2);\r
-                               if(WSAAsyncSelect(Ret2, hWndSocket, WM_ASYNC_SOCKET, FD_CONNECT | FD_CLOSE | FD_ACCEPT | FD_READ | FD_WRITE) == SOCKET_ERROR)\r
+                               RegisterAsyncTable(Ret2);\r
+                               // 高速化のためFD_READとFD_WRITEを使用しない\r
+//                             if(WSAAsyncSelect(Ret2, hWndSocket, WM_ASYNC_SOCKET, FD_CONNECT | FD_CLOSE | FD_ACCEPT | FD_READ | FD_WRITE) == SOCKET_ERROR)\r
+                               if(WSAAsyncSelect(Ret2, hWndSocket, WM_ASYNC_SOCKET, FD_CONNECT | FD_CLOSE | FD_ACCEPT) == SOCKET_ERROR)\r
                                {\r
                                        do_closesocket(Ret2);\r
                                        Ret2 = INVALID_SOCKET;\r
@@ -904,20 +1067,20 @@ SOCKET do_accept(SOCKET s, struct sockaddr *addr, int *addrlen)
 \r
 \r
 \r
-/*----- recv\91\8a\93\96\82Ì\8aÖ\90\94 --------------------------------------------------------\r
+/*----- recv相当の関数 --------------------------------------------------------\r
 *\r
 *      Parameter\r
-*              SOCKET s : \83\\83P\83b\83g\r
-*              char *buf : \83f\81[\83^\82ð\93Ç\82Ý\8d\9e\82Þ\83o\83b\83t\83@\r
-*              int len : \92·\82³\r
-*              int flags : recv\82É\97^\82¦\82é\83t\83\89\83O\r
-*              int *TimeOutErr : \83^\83C\83\80\83A\83E\83g\82µ\82½\82©\82Ç\82¤\82©\82ð\95Ô\82·\83\8f\81[\83N\r
+*              SOCKET s : ソケット\r
+*              char *buf : データを読み込むバッファ\r
+*              int len : 長さ\r
+*              int flags : recvに与えるフラグ\r
+*              int *TimeOutErr : タイムアウトしたかどうかを返すワーク\r
 *\r
 *      Return Value\r
-*              int : recv\82Ì\96ß\82è\92l\82Æ\93¯\82\r
+*              int : recvの戻り値と同じ\r
 *\r
 *      Note\r
-*              \83^\83C\83\80\83A\83E\83g\82Ì\8e\9e\82Í TimeOut=YES\81ARet=SOCKET_ERROR \82É\82È\82é\r
+*              タイムアウトの時は TimeOut=YES、Ret=SOCKET_ERROR になる\r
 *----------------------------------------------------------------------------*/\r
 int do_recv(SOCKET s, char *buf, int len, int flags, int *TimeOutErr, int *CancelCheckWork)\r
 {\r
@@ -931,38 +1094,40 @@ int do_recv(SOCKET s, char *buf, int len, int flags, int *TimeOutErr, int *Cance
        DoPrintf("# Start recv (S=%x)", s);\r
 #endif\r
        *TimeOutErr = NO;\r
-       *CancelCheckWork = NO;\r
+       // 同時接続対応\r
+//     *CancelCheckWork = NO;\r
        Ret = SOCKET_ERROR;\r
        Error = 0;\r
 \r
        if(TimeOut != 0)\r
                time(&StartTime);\r
 \r
-       // FTPS\91Î\89\9e\r
-       // OpenSSL\82Å\82Í\8eó\90M\8am\94F\82ÍFD_READ\82ª\95¡\90\94\89ñ\8eó\90M\82³\82ê\82é\89Â\94\\90«\82ª\82 \82é\r
-//     while((*CancelCheckWork == NO) && (AskAsyncDone(s, &Error, FD_READ_BIT) != YES))\r
-       while(AskCryptMode() == CRYPT_NONE && (*CancelCheckWork == NO) && (AskAsyncDone(s, &Error, FD_READ_BIT) != YES))\r
-       {\r
-               if(AskAsyncDone(s, &Error, FD_CLOSE_BIT) == YES)\r
-               {\r
-                       Ret = 0;\r
-                       break;\r
-               }\r
-               Sleep(1);\r
-               if(BackgrndMessageProc() == YES)\r
-                       *CancelCheckWork = YES;\r
-               else if(TimeOut != 0)\r
-               {\r
-                       time(&ElapseTime);\r
-                       ElapseTime -= StartTime;\r
-                       if(ElapseTime >= TimeOut)\r
-                       {\r
-                               DoPrintf("do_recv timed out");\r
-                               *TimeOutErr = YES;\r
-                               *CancelCheckWork = YES;\r
-                       }\r
-               }\r
-       }\r
+       // FTPS対応\r
+       // OpenSSLでは受信確認はFD_READが複数回受信される可能性がある\r
+//     while((*CancelCheckWork == NO) && (AskAsyncDone(s, &Error, FD_READ) != YES))\r
+       // 短時間にFD_READが2回以上通知される対策\r
+//     while(!IsSSLAttached(s) && (*CancelCheckWork == NO) && (AskAsyncDone(s, &Error, FD_READ) != YES))\r
+//     {\r
+//             if(AskAsyncDone(s, &Error, FD_CLOSE) == YES)\r
+//             {\r
+//                     Ret = 0;\r
+//                     break;\r
+//             }\r
+//             Sleep(1);\r
+//             if(BackgrndMessageProc() == YES)\r
+//                     *CancelCheckWork = YES;\r
+//             else if(TimeOut != 0)\r
+//             {\r
+//                     time(&ElapseTime);\r
+//                     ElapseTime -= StartTime;\r
+//                     if(ElapseTime >= TimeOut)\r
+//                     {\r
+//                             DoPrintf("do_recv timed out");\r
+//                             *TimeOutErr = YES;\r
+//                             *CancelCheckWork = YES;\r
+//                     }\r
+//             }\r
+//     }\r
 \r
        if(/*(Ret != 0) && */(Error == 0) && (*CancelCheckWork == NO) && (*TimeOutErr == NO))\r
        {\r
@@ -972,25 +1137,19 @@ int do_recv(SOCKET s, char *buf, int len, int flags, int *TimeOutErr, int *Cance
                        DoPrintf("## recv()");\r
 #endif\r
 \r
-                       // FTPS\91Î\89\9e\r
+                       // FTPS対応\r
 //                     Ret = recv(s, buf, len, flags);\r
-                       if(AskCryptMode() == CRYPT_FTPES || AskCryptMode() == CRYPT_FTPIS)\r
-                               Ret = recvS(s, buf, len, flags);\r
-                       else\r
-                               Ret = recv(s, buf, len, flags);\r
+                       Ret = FTPS_recv(s, buf, len, flags);\r
                        if(Ret != SOCKET_ERROR)\r
                                break;\r
                        Error = WSAGetLastError();\r
                        Sleep(1);\r
                        if(BackgrndMessageProc() == YES)\r
                                break;\r
-                       // FTPS\91Î\89\9e\r
-                       // \8eó\90M\8am\94F\82ð\83o\83C\83p\83X\82µ\82½\82½\82ß\82±\82±\82Å\83^\83C\83\80\83A\83E\83g\82Ì\8am\94F\r
-                       if(AskCryptMode() == CRYPT_FTPES || AskCryptMode() == CRYPT_FTPIS)\r
-                       {\r
-                               if(BackgrndMessageProc() == YES)\r
-                                       *CancelCheckWork = YES;\r
-                       }\r
+                       // FTPS対応\r
+                       // 受信確認をバイパスしたためここでタイムアウトの確認\r
+                       if(BackgrndMessageProc() == YES)\r
+                               *CancelCheckWork = YES;\r
                        else if(TimeOut != 0)\r
                        {\r
                                time(&ElapseTime);\r
@@ -1034,7 +1193,8 @@ int do_send(SOCKET s, const char *buf, int len, int flags, int *TimeOutErr, int
        DoPrintf("# Start send (S=%x)", s);\r
 #endif\r
        *TimeOutErr = NO;\r
-       *CancelCheckWork = NO;\r
+       // 同時接続対応\r
+//     *CancelCheckWork = NO;\r
        Ret = SOCKET_ERROR;\r
        Error = 0;\r
 \r
@@ -1044,36 +1204,40 @@ int do_send(SOCKET s, const char *buf, int len, int flags, int *TimeOutErr, int
 #if DBG_MSG\r
        DoPrintf("## Async set: FD_CONNECT|FD_CLOSE|FD_ACCEPT|FD_READ|FD_WRITE");\r
 #endif\r
-       WSAAsyncSelect(s, hWndSocket, WM_ASYNC_SOCKET, FD_CONNECT | FD_CLOSE | FD_ACCEPT | FD_READ | FD_WRITE);\r
+       // Windows 2000でFD_WRITEが通知されないことがあるバグ修正\r
+       // 毎回通知されたのはNT 4.0までのバグであり仕様ではない\r
+       // XP以降は互換性のためか毎回通知される\r
+//     WSAAsyncSelect(s, hWndSocket, WM_ASYNC_SOCKET, FD_CONNECT | FD_CLOSE | FD_ACCEPT | FD_READ | FD_WRITE);\r
        if(BackgrndMessageProc() == YES)\r
                *CancelCheckWork = YES;\r
 \r
-       // FTPS\91Î\89\9e\r
-       // \91\97\90M\83o\83b\83t\83@\82Ì\8bó\82«\8am\94F\82É\82Í\89e\8b¿\82µ\82È\82¢\82ª\94O\82Ì\82½\82ß\r
-//     while((*CancelCheckWork == NO) && (AskAsyncDone(s, &Error, FD_WRITE_BIT) != YES))\r
-       while(AskCryptMode() == CRYPT_NONE && (*CancelCheckWork == NO) && (AskAsyncDone(s, &Error, FD_WRITE_BIT) != YES))\r
-       {\r
-               if(AskAsyncDone(s, &Error, FD_CLOSE_BIT) == YES)\r
-               {\r
-                       Error = 1;\r
-                       break;\r
-               }\r
-\r
-               Sleep(1);\r
-               if(BackgrndMessageProc() == YES)\r
-                       *CancelCheckWork = YES;\r
-               else if(TimeOut != 0)\r
-               {\r
-                       time(&ElapseTime);\r
-                       ElapseTime -= StartTime;\r
-                       if(ElapseTime >= TimeOut)\r
-                       {\r
-                               DoPrintf("do_write timed out");\r
-                               *TimeOutErr = YES;\r
-                               *CancelCheckWork = YES;\r
-                       }\r
-               }\r
-       }\r
+       // FTPS対応\r
+       // 送信バッファの空き確認には影響しないが念のため\r
+//     while((*CancelCheckWork == NO) && (AskAsyncDone(s, &Error, FD_WRITE) != YES))\r
+       // Windows 2000でFD_WRITEが通知されないことがあるバグ修正\r
+//     while(!IsSSLAttached(s) && (*CancelCheckWork == NO) && (AskAsyncDone(s, &Error, FD_WRITE) != YES))\r
+//     {\r
+//             if(AskAsyncDone(s, &Error, FD_CLOSE) == YES)\r
+//             {\r
+//                     Error = 1;\r
+//                     break;\r
+//             }\r
+//\r
+//             Sleep(1);\r
+//             if(BackgrndMessageProc() == YES)\r
+//                     *CancelCheckWork = YES;\r
+//             else if(TimeOut != 0)\r
+//             {\r
+//                     time(&ElapseTime);\r
+//                     ElapseTime -= StartTime;\r
+//                     if(ElapseTime >= TimeOut)\r
+//                     {\r
+//                             DoPrintf("do_write timed out");\r
+//                             *TimeOutErr = YES;\r
+//                             *CancelCheckWork = YES;\r
+//                     }\r
+//             }\r
+//     }\r
 \r
        if((Error == 0) && (*CancelCheckWork == NO) && (*TimeOutErr == NO))\r
        {\r
@@ -1083,12 +1247,9 @@ int do_send(SOCKET s, const char *buf, int len, int flags, int *TimeOutErr, int
                        DoPrintf("## send()");\r
 #endif\r
 \r
-                       // FTPS\91Î\89\9e\r
+                       // FTPS対応\r
 //                     Ret = send(s, buf, len, flags);\r
-                       if(AskCryptMode() == CRYPT_FTPES || AskCryptMode() == CRYPT_FTPIS)\r
-                               Ret = sendS(s, buf, len, flags);\r
-                       else\r
-                               Ret = send(s, buf, len, flags);\r
+                       Ret = FTPS_send(s, buf, len, flags);\r
                        if(Ret != SOCKET_ERROR)\r
                        {\r
 #if DBG_MSG\r
@@ -1100,13 +1261,10 @@ int do_send(SOCKET s, const char *buf, int len, int flags, int *TimeOutErr, int
                        Sleep(1);\r
                        if(BackgrndMessageProc() == YES)\r
                                break;\r
-                       // FTPS\91Î\89\9e\r
-                       // \91\97\90M\83o\83b\83t\83@\8am\94F\82ð\83o\83C\83p\83X\82µ\82½\82½\82ß\82±\82±\82Å\83^\83C\83\80\83A\83E\83g\82Ì\8am\94F\r
-                       if(AskCryptMode() == CRYPT_FTPES || AskCryptMode() == CRYPT_FTPIS)\r
-                       {\r
-                               if(BackgrndMessageProc() == YES)\r
-                                       *CancelCheckWork = YES;\r
-                       }\r
+                       // FTPS対応\r
+                       // 送信バッファ確認をバイパスしたためここでタイムアウトの確認\r
+                       if(BackgrndMessageProc() == YES)\r
+                               *CancelCheckWork = YES;\r
                        else if(TimeOut != 0)\r
                        {\r
                                time(&ElapseTime);\r
@@ -1137,13 +1295,27 @@ int do_send(SOCKET s, const char *buf, int len, int flags, int *TimeOutErr, int
 }\r
 \r
 \r
+// 同時接続対応\r
+void RemoveReceivedData(SOCKET s)\r
+{\r
+       char buf[1024];\r
+       int len;\r
+//     int Error;\r
+       while((len = FTPS_recv(s, buf, sizeof(buf), MSG_PEEK)) > 0)\r
+       {\r
+//             AskAsyncDone(s, &Error, FD_READ);\r
+               FTPS_recv(s, buf, len, 0);\r
+       }\r
+}\r
+\r
+\r
 /*----- \r
 *\r
 *      Parameter\r
 *\r
 *      Return Value\r
-*              int \83X\83e\81[\83^\83X\r
-*                      SUCCESS/FAIL\r
+*              int ステータス\r
+*                      FFFTP_SUCCESS/FFFTP_FAIL\r
 *----------------------------------------------------------------------------*/\r
 \r
 int CheckClosedAndReconnect(void)\r
@@ -1153,8 +1325,8 @@ int CheckClosedAndReconnect(void)
 \r
 //SetTaskMsg("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");\r
 \r
-       Sts = SUCCESS;\r
-       if(AskAsyncDone(AskCmdCtrlSkt(), &Error, FD_CLOSE_BIT) == YES)\r
+       Sts = FFFTP_SUCCESS;\r
+       if(AskAsyncDone(AskCmdCtrlSkt(), &Error, FD_CLOSE) == YES)\r
        {\r
                Sts = ReConnectCmdSkt();\r
        }\r
@@ -1163,3 +1335,19 @@ int CheckClosedAndReconnect(void)
 \r
 \r
 \r
+// 同時接続対応\r
+int CheckClosedAndReconnectTrnSkt(SOCKET *Skt, int *CancelCheckWork)\r
+{\r
+       int Error;\r
+       int Sts;\r
+\r
+//SetTaskMsg("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");\r
+\r
+       Sts = FFFTP_SUCCESS;\r
+       if(AskAsyncDone(*Skt, &Error, FD_CLOSE) == YES)\r
+       {\r
+               Sts = ReConnectTrnSkt(Skt, CancelCheckWork);\r
+       }\r
+       return(Sts);\r
+}\r
+\r