OSDN Git Service

Fix bugs of simultaneous connection.
[ffftp/ffftp.git] / getput.c
index 888af3c..949a069 100644 (file)
--- a/getput.c
+++ b/getput.c
@@ -537,7 +537,7 @@ static void EraseTransFileList(void)
        TRANSPACKET *New;\r
        TRANSPACKET *Next;\r
        TRANSPACKET *NotDel;\r
-       TRANSPACKET Pkt;\r
+//     TRANSPACKET Pkt;\r
 \r
        NotDel = NULL;\r
 \r
@@ -582,8 +582,9 @@ static void EraseTransFileList(void)
        // 同時接続対応\r
        WaitForMainThread = NO;\r
 \r
-       strcpy(Pkt.Cmd, "GOQUIT");\r
-       AddTransFileList(&Pkt);\r
+       // 同時接続対応\r
+//     strcpy(Pkt.Cmd, "GOQUIT");\r
+//     AddTransFileList(&Pkt);\r
        return;\r
 }\r
 \r
@@ -742,6 +743,8 @@ static ULONG WINAPI TransferThread(void *Dummy)
                        Pos = TransPacketBase;\r
                        TransPacketBase = TransPacketBase->Next;\r
                        free(Pos);\r
+                       if(TransPacketBase == NULL)\r
+                               GoExit = YES;\r
                }\r
                NewCmdSkt = AskCmdCtrlSkt();\r
                if(AskReuseCmdSkt() == YES && ThreadCount == 0)\r
@@ -759,9 +762,7 @@ static ULONG WINAPI TransferThread(void *Dummy)
                                else\r
                                        CheckClosedAndReconnectTrnSkt(&TrnSkt, &Canceled[ThreadCount]);\r
                                // 同時ログイン数制限対策\r
-                               if(TrnSkt != INVALID_SOCKET)\r
-                                       LastUsed = timeGetTime();\r
-                               else\r
+                               if(TrnSkt == INVALID_SOCKET)\r
                                {\r
                                        // 同時ログイン数制限に引っかかった可能性あり\r
                                        // 負荷を下げるために約10秒間待機\r
@@ -773,6 +774,7 @@ static ULONG WINAPI TransferThread(void *Dummy)
                                                i--;\r
                                        }\r
                                }\r
+                               LastUsed = timeGetTime();\r
 //                             WaitForSingleObject(hListAccMutex, INFINITE);\r
                                while(WaitForSingleObject(hListAccMutex, 0) == WAIT_TIMEOUT)\r
                                {\r
@@ -786,7 +788,7 @@ static ULONG WINAPI TransferThread(void *Dummy)
                                {\r
                                        // 同時ログイン数制限対策\r
                                        // 60秒間使用されなければログアウト\r
-                                       if(timeGetTime() - LastUsed > 60000)\r
+                                       if(timeGetTime() - LastUsed > 60000 || NewCmdSkt == INVALID_SOCKET)\r
                                        {\r
                                                ReleaseMutex(hListAccMutex);\r
                                                SendData(TrnSkt, "QUIT\r\n", 6, 0, &Canceled[ThreadCount]);\r
@@ -806,13 +808,6 @@ static ULONG WINAPI TransferThread(void *Dummy)
 //             if(TransPacketBase != NULL)\r
                if(TrnSkt != INVALID_SOCKET && NextTransPacketBase != NULL)\r
                {\r
-                       if(strcmp(NextTransPacketBase->Cmd, "GOQUIT") == 0 && NextTransPacketBase != TransPacketBase)\r
-                       {\r
-                               ReleaseMutex(hListAccMutex);\r
-                               BackgrndMessageProc();\r
-                               Sleep(1);\r
-                               continue;\r
-                       }\r
                        Pos = NextTransPacketBase;\r
                        NextTransPacketBase = NextTransPacketBase->Next;\r
                        // ディレクトリ操作は非同期で行わない\r
@@ -841,6 +836,7 @@ static ULONG WINAPI TransferThread(void *Dummy)
 //                     TransPacketBase->hWndTrans = hWndTrans;\r
                        Pos->hWndTrans = hWndTrans;\r
                        Pos->ctrl_skt = TrnSkt;\r
+                       Pos->Abort = ABORT_NONE;\r
                        Pos->ThreadCount = ThreadCount;\r
 \r
                        if(hWndTrans != NULL)\r
@@ -856,6 +852,9 @@ static ULONG WINAPI TransferThread(void *Dummy)
 //                             SendMessage(hWndTrans, WM_SET_PACKET, 0, (LPARAM)TransPacketBase);\r
                                SendMessage(hWndTrans, WM_SET_PACKET, 0, (LPARAM)Pos);\r
 \r
+                       // 中断後に受信バッファに応答が残っていると次のコマンドの応答が正しく処理できない\r
+                       RemoveReceivedData(TrnSkt);\r
+\r
                        /* ダウンロード */\r
 //                     if(strncmp(TransPacketBase->Cmd, "RETR", 4) == 0)\r
                        if(strncmp(Pos->Cmd, "RETR", 4) == 0)\r
@@ -1110,11 +1109,11 @@ static ULONG WINAPI TransferThread(void *Dummy)
                        }\r
                        /* 自動終了のための通知 */\r
 //                     else if(strcmp(TransPacketBase->Cmd, "GOQUIT") == 0)\r
-                       else if(strcmp(Pos->Cmd, "GOQUIT") == 0)\r
-                       {\r
-                               ReleaseMutex(hListAccMutex);\r
-                               GoExit = YES;\r
-                       }\r
+//                     else if(strcmp(Pos->Cmd, "GOQUIT") == 0)\r
+//                     {\r
+//                             ReleaseMutex(hListAccMutex);\r
+//                             GoExit = YES;\r
+//                     }\r
                        else\r
                                ReleaseMutex(hListAccMutex);\r
 \r
@@ -1134,6 +1133,7 @@ static ULONG WINAPI TransferThread(void *Dummy)
                                        for(i = 0; i < MAX_DATA_CONNECTION; i++)\r
                                                Canceled[i] = YES;\r
                                        EraseTransFileList();\r
+                                       GoExit = YES;\r
                                        Pos = NULL;\r
                                }\r
                                else\r
@@ -1152,7 +1152,7 @@ static ULONG WINAPI TransferThread(void *Dummy)
 //                                     TransPacketBase = TransPacketBase->Next;\r
 //                                     free(Pos);\r
                                }\r
-                               ClearAll = NO;\r
+//                             ClearAll = NO;\r
                                ReleaseMutex(hListAccMutex);\r
 \r
                                if(BackgrndMessageProc() == YES)\r
@@ -1171,8 +1171,25 @@ static ULONG WINAPI TransferThread(void *Dummy)
 //             else\r
                else if(TransPacketBase == NULL)\r
                {\r
+                       ClearAll = NO;\r
                        DelNotify = NO;\r
 \r
+                       if(GoExit == YES)\r
+                       {\r
+                               SoundPlay(SND_TRANS);\r
+                               if(AskAutoExit() == NO)\r
+                               {\r
+                                       if(Down == YES)\r
+                                               PostMessage(GetMainHwnd(), WM_REFRESH_LOCAL_FLG, 0, 0);\r
+                                       if(Up == YES)\r
+                                               PostMessage(GetMainHwnd(), WM_REFRESH_REMOTE_FLG, 0, 0);\r
+                               }\r
+                               Down = NO;\r
+                               Up = NO;\r
+                               PostMessage(GetMainHwnd(), WM_COMMAND, MAKEWPARAM(MENU_AUTO_EXIT, 0), 0);\r
+                               GoExit = NO;\r
+                       }\r
+\r
                        ReleaseMutex(hListAccMutex);\r
                        if(KeepDlg == NO)\r
                        {\r
@@ -1201,22 +1218,6 @@ static ULONG WINAPI TransferThread(void *Dummy)
 //                     Sleep(1);\r
                        Sleep(100);\r
 \r
-                       if(GoExit == YES)\r
-                       {\r
-                               SoundPlay(SND_TRANS);\r
-                               if(AskAutoExit() == NO)\r
-                               {\r
-                                       if(Down == YES)\r
-                                               PostMessage(GetMainHwnd(), WM_REFRESH_LOCAL_FLG, 0, 0);\r
-                                       if(Up == YES)\r
-                                               PostMessage(GetMainHwnd(), WM_REFRESH_REMOTE_FLG, 0, 0);\r
-                               }\r
-                               Down = NO;\r
-                               Up = NO;\r
-                               PostMessage(GetMainHwnd(), WM_COMMAND, MAKEWPARAM(MENU_AUTO_EXIT, 0), 0);\r
-                               GoExit = NO;\r
-                       }\r
-\r
                        // 再転送対応\r
                        TransferErrorMode = AskTransferErrorMode();\r
                        TransferErrorNotify = AskTransferErrorNotify();\r
@@ -1346,6 +1347,8 @@ int DoDownLoad(SOCKET cSkt, TRANSPACKET *Pkt, int DirList, int *CancelCheckWork)
                }\r
                else\r
                        SetErrorMsg(Reply);\r
+               // エラーによってはダイアログが表示されない場合があるバグ対策\r
+               DispDownloadFinishMsg(Pkt, iRetCode);\r
        }\r
        else\r
        {\r
@@ -1353,8 +1356,6 @@ int DoDownLoad(SOCKET cSkt, TRANSPACKET *Pkt, int DirList, int *CancelCheckWork)
                SetTaskMsg(MSGJPN089, Pkt->RemoteFile);\r
                iRetCode = 200;\r
        }\r
-       // エラーによってはダイアログが表示されない場合があるバグ対策\r
-       DispDownloadFinishMsg(Pkt, iRetCode);\r
        return(iRetCode);\r
 }\r
 \r
@@ -2281,6 +2282,8 @@ static void DispDownloadFinishMsg(TRANSPACKET *Pkt, int iRetCode)
 {\r
        char Fname[FMAX_PATH+1];\r
 \r
+       // 同時接続対応\r
+       ReleaseMutex(hListAccMutex);\r
        if(ForceAbort == NO)\r
        {\r
                if((iRetCode/100) >= FTP_CONTINUE)\r
@@ -2300,7 +2303,9 @@ static void DispDownloadFinishMsg(TRANSPACKET *Pkt, int iRetCode)
                                return;\r
 #endif\r
 \r
-                       if((strncmp(Pkt->Cmd, "NLST", 4) == 0) || (strncmp(Pkt->Cmd, "LIST", 4) == 0))\r
+                       // MLSD対応\r
+//                     if((strncmp(Pkt->Cmd, "NLST", 4) == 0) || (strncmp(Pkt->Cmd, "LIST", 4) == 0))\r
+                       if((strncmp(Pkt->Cmd, "NLST", 4) == 0) || (strncmp(Pkt->Cmd, "LIST", 4) == 0) || (strncmp(Pkt->Cmd, "MLSD", 4) == 0))\r
                        {\r
                                SetTaskMsg(MSGJPN097);\r
                                strcpy(Fname, MSGJPN098);\r
@@ -2337,7 +2342,9 @@ static void DispDownloadFinishMsg(TRANSPACKET *Pkt, int iRetCode)
                }\r
                else\r
                {\r
-                       if((strncmp(Pkt->Cmd, "NLST", 4) == 0) || (strncmp(Pkt->Cmd, "LIST", 4) == 0))\r
+                       // MLSD対応\r
+//                     if((strncmp(Pkt->Cmd, "NLST", 4) == 0) || (strncmp(Pkt->Cmd, "LIST", 4) == 0))\r
+                       if((strncmp(Pkt->Cmd, "NLST", 4) == 0) || (strncmp(Pkt->Cmd, "LIST", 4) == 0) || (strncmp(Pkt->Cmd, "MLSD", 4) == 0))\r
                                SetTaskMsg(MSGJPN101, Pkt->ExistSize);\r
                        // 同時接続対応\r
 //                     else if((Pkt->hWndTrans != NULL) && (TimeStart != 0))\r
@@ -2610,6 +2617,8 @@ static int DoUpLoad(SOCKET cSkt, TRANSPACKET *Pkt)
                        // エラーによってはダイアログが表示されない場合があるバグ対策\r
 //                     DispUploadFinishMsg(Pkt, iRetCode);\r
                }\r
+               // エラーによってはダイアログが表示されない場合があるバグ対策\r
+               DispUploadFinishMsg(Pkt, iRetCode);\r
        }\r
        else\r
        {\r
@@ -2617,8 +2626,6 @@ static int DoUpLoad(SOCKET cSkt, TRANSPACKET *Pkt)
                SetTaskMsg(MSGJPN107, Pkt->LocalFile);\r
                iRetCode = 200;\r
        }\r
-       // エラーによってはダイアログが表示されない場合があるバグ対策\r
-       DispUploadFinishMsg(Pkt, iRetCode);\r
        return(iRetCode);\r
 }\r
 \r
@@ -3579,6 +3586,8 @@ static int TermCodeConvAndSend(TERMCODECONVINFO *tInfo, SOCKET Skt, char *Data,
 \r
 static void DispUploadFinishMsg(TRANSPACKET *Pkt, int iRetCode)\r
 {\r
+       // 同時接続対応\r
+       ReleaseMutex(hListAccMutex);\r
        if(ForceAbort == NO)\r
        {\r
                if((iRetCode/100) >= FTP_CONTINUE)\r
@@ -3738,8 +3747,6 @@ static LRESULT CALLBACK TransDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM
 //                             if(!(Pkt = (TRANSPACKET*)GetWindowLong(hDlg, GWL_USERDATA)))\r
                                if(!(Pkt = (TRANSPACKET*)GetWindowLongPtr(hDlg, GWLP_USERDATA)))\r
                                        break;\r
-                               if(Canceled[Pkt->ThreadCount] == YES)\r
-                                       Pkt->Abort = ABORT_USER;\r
                                DispTransferStatus(hDlg, NO, Pkt);\r
                                SetTimer(hDlg, TIMER_DISPLAY, DISPLAY_TIMING, NULL);\r
                        }\r