Develop and Download Open Source Software

Browse Subversion Repository

Diff of /branches/ttcomtester/teraterm/teraterm/commlib.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 6662 by doda, Mon Apr 3 12:51:37 2017 UTC revision 6738 by maya, Sat May 20 06:38:01 2017 UTC
# Line 16  Line 16 
16  #include "ttplug.h" /* TTPLUG */  #include "ttplug.h" /* TTPLUG */
17    
18  #include "commlib.h"  #include "commlib.h"
 #ifndef NO_INET6  
19  #include <winsock2.h>  #include <winsock2.h>
20  #include <ws2tcpip.h>  #include <ws2tcpip.h>
 #endif /* NO_INET6 */  
21  #include <stdio.h> /* for _snprintf() */  #include <stdio.h> /* for _snprintf() */
22  #include <time.h>  #include <time.h>
23  #include <locale.h>  #include <locale.h>
24    
 #ifndef NO_INET6  
25  static SOCKET OpenSocket(PComVar);  static SOCKET OpenSocket(PComVar);
26  static void AsyncConnect(PComVar);  static void AsyncConnect(PComVar);
27  static int CloseSocket(SOCKET);  static int CloseSocket(SOCKET);
# Line 74  static int CloseSocket(SOCKET s) Line 71  static int CloseSocket(SOCKET s)
71  {  {
72          return Pclosesocket(s);          return Pclosesocket(s);
73  }  }
 #endif /* NO_INET6 */  
74    
75  #define CommInQueSize 8192  #define CommInQueSize 8192
76  #define CommOutQueSize 2048  #define CommOutQueSize 2048
# Line 258  error: Line 254  error:
254    
255  void CommOpen(HWND HW, PTTSet ts, PComVar cv)  void CommOpen(HWND HW, PTTSet ts, PComVar cv)
256  {  {
 #ifdef NO_INET6  
         int Err;  
 #endif /* NO_INET6 */  
257          char ErrMsg[21+256];          char ErrMsg[21+256];
258          char P[50+256];          char P[50+256];
259    
260          MSG Msg;          MSG Msg;
 #ifndef NO_INET6  
261          ADDRINFO hints;          ADDRINFO hints;
262          char pname[NI_MAXSERV];          char pname[NI_MAXSERV];
 #else  
         char HEntBuff[MAXGETHOSTSTRUCT];  
         u_long addr;  
         SOCKADDR_IN saddr;  
 #endif /* NO_INET6 */  
263    
264          BOOL InvalidHost;          BOOL InvalidHost;
 #ifdef NO_INET6  
         BOOL BBuf;  
 #endif /* NO_INET6 */  
265    
266          char uimsg[MAX_UIMSG];          char uimsg[MAX_UIMSG];
267    
# Line 299  void CommOpen(HWND HW, PTTSet ts, PComVa Line 283  void CommOpen(HWND HW, PTTSet ts, PComVa
283          cv->PortType = ts->PortType;          cv->PortType = ts->PortType;
284          cv->ComPort = 0;          cv->ComPort = 0;
285          cv->RetryCount = 0;          cv->RetryCount = 0;
 #ifndef NO_INET6  
286          cv->RetryWithOtherProtocol = TRUE;          cv->RetryWithOtherProtocol = TRUE;
 #endif /* NO_INET6 */  
287          cv->s = INVALID_SOCKET;          cv->s = INVALID_SOCKET;
288          cv->ComID = INVALID_HANDLE_VALUE;          cv->ComID = INVALID_HANDLE_VALUE;
289          cv->CanSend = TRUE;          cv->CanSend = TRUE;
# Line 365  void CommOpen(HWND HW, PTTSet ts, PComVa Line 347  void CommOpen(HWND HW, PTTSet ts, PComVa
347                          else {                          else {
348                                  TTXOpenTCP(); /* TTPLUG */                                  TTXOpenTCP(); /* TTPLUG */
349                                  cv->Open = TRUE;                                  cv->Open = TRUE;
 #ifndef NO_INET6  
350                                  /* resolving address */                                  /* resolving address */
351                                  memset(&hints, 0, sizeof(hints));                                  memset(&hints, 0, sizeof(hints));
352                                  hints.ai_family = ts->ProtocolFamily;                                  hints.ai_family = ts->ProtocolFamily;
# Line 430  void CommOpen(HWND HW, PTTSet ts, PComVa Line 411  void CommOpen(HWND HW, PTTSet ts, PComVa
411                                  break; /* break for-loop immediately */                                  break; /* break for-loop immediately */
412                          }                          }
413                          break;                          break;
 #else  
         if ((ts->HostName[0] >= 0x30) && (ts->HostName[0] <= 0x39))  
         {  
           addr = Pinet_addr(ts->HostName);  
           InvalidHost = (addr == 0xffffffff);  
         }  
         else {  
           HAsync = PWSAAsyncGetHostByName(HW,WM_USER_GETHOST,  
           ts->HostName,HEntBuff,sizeof(HEntBuff));  
           if (HAsync == 0)  
             InvalidHost = TRUE;  
           else {  
             cv->ComPort = 1; // set "getting host" flag  
                              //  (see CVTWindow::OnSysCommand())  
             do {  
               if (GetMessage(&Msg,0,0,0))  
               {  
                 if ((Msg.hwnd==HW) &&  
                     ((Msg.message == WM_SYSCOMMAND) &&  
                      ((Msg.wParam & 0xfff0) == SC_CLOSE) ||  
                      (Msg.message == WM_COMMAND) &&  
                      (LOWORD(Msg.wParam) == ID_FILE_EXIT) ||  
                      (Msg.message == WM_CLOSE)))  
                 { /* Exit when the user closes Tera Term */  
                   PWSACancelAsyncRequest(HAsync);  
                   HAsync = 0;  
                   cv->ComPort = 0; // clear "getting host" flag  
                   PostMessage(HW,Msg.message,Msg.wParam,Msg.lParam);  
                   return;  
                 }  
                 if (Msg.message != WM_USER_GETHOST)  
                 { /* Prosess messages */  
                   TranslateMessage(&Msg);  
                   DispatchMessage(&Msg);  
                 }  
               }  
               else {  
                 return;  
               }  
             } while (Msg.message!=WM_USER_GETHOST);  
             cv->ComPort = 0; // clear "getting host" flag  
             HAsync = 0;  
             InvalidHost = WSAGETASYNCERROR(Msg.lParam) != 0;  
             if (! InvalidHost)  
             {  
               if (((PHOSTENT)HEntBuff)->h_addr_list != NULL)  
                 memcpy(&addr,  
                   ((PHOSTENT)HEntBuff)->h_addr_list[0],sizeof(addr));  
               else  
                 InvalidHost = TRUE;  
             }  
           }  
   
         }  
   
         if (InvalidHost)  
         {  
           if (cv->NoMsg==0) {  
             get_lang_msg("MSG_TT_ERROR", uimsg, sizeof(uimsg), "Tera Term: Error", ts->UILanguageFile);  
             get_lang_msg("MSG_INVALID_HOST_ERROR", ts->UIMsg, sizeof(ts->UIMsg), "Invalid host", ts->UILanguageFile);  
             MessageBox(cv->HWin, ts->UIMsg, uimsg, MB_TASKMODAL | MB_ICONEXCLAMATION);  
           }  
         }  
         else {  
           cv->s= Psocket(AF_INET,SOCK_STREAM,IPPROTO_TCP);  
           if (cv->s==INVALID_SOCKET)  
           {  
             InvalidHost = TRUE;  
             if (cv->NoMsg==0) {  
               get_lang_msg("MSG_TT_ERROR", uimsg, sizeof(uimsg), "Tera Term: Error", ts->UILanguageFile);  
               get_lang_msg("MSG_COMM_TIMEOUT_ERROR", ts->UIMsg, sizeof(ts->UIMsg), "Cannot connect the host", ts->UILanguageFile);  
               MessageBox(cv->HWin, ts->UIMsg, uimsg, MB_TASKMODAL | MB_ICONEXCLAMATION);  
             }  
           }  
           else {  
             BBuf = TRUE;  
             Psetsockopt(cv->s,(int)SOL_SOCKET,SO_OOBINLINE,(char FAR *)&BBuf,sizeof(BBuf));  
   
             PWSAAsyncSelect(cv->s,cv->HWin,WM_USER_COMMOPEN, FD_CONNECT);  
             saddr.sin_family = AF_INET;  
             saddr.sin_port = Phtons(ts->TCPPort);  
             saddr.sin_addr.s_addr = addr;  
             memset(saddr.sin_zero,0,8);  
   
             Err = Pconnect(cv->s,(LPSOCKADDR)&saddr,sizeof(saddr));  
             if (Err!=0 ) Err = PWSAGetLastError();  
             if (Err==WSAEWOULDBLOCK )  
             {  
               /* Do nothing */  
             }  
             else if (Err!=0 )  
               PostMessage(cv->HWin, WM_USER_COMMOPEN,0,  
                           MAKELONG(FD_CONNECT,Err));  
           }  
         }  
       }  
       break;  
 #endif /* NO_INET6 */  
414    
415                  case IdSerial:                  case IdSerial:
416                          InitFileIO(IdSerial);  /* TTPLUG */                          InitFileIO(IdSerial);  /* TTPLUG */
# Line 630  void CommOpen(HWND HW, PTTSet ts, PComVa Line 513  void CommOpen(HWND HW, PTTSet ts, PComVa
513    
514          } /* end of "switch" */          } /* end of "switch" */
515    
 #ifndef NO_INET6  
516  BreakSC:  BreakSC:
 #endif /* NO_INET6 */  
517          if (InvalidHost) {          if (InvalidHost) {
518                  PostMessage(cv->HWin, WM_USER_COMMNOTIFY, 0, FD_CLOSE);                  PostMessage(cv->HWin, WM_USER_COMMNOTIFY, 0, FD_CLOSE);
519                  if ( (ts->PortType==IdTCPIP) && cv->Open ) {                  if ( (ts->PortType==IdTCPIP) && cv->Open ) {
# Line 757  void CommStart(PComVar cv, LONG lParam, Line 638  void CommStart(PComVar cv, LONG lParam,
638                                          _snprintf_s(ErrMsg, sizeof(ErrMsg), _TRUNCATE, "%s", ts->UIMsg);                                          _snprintf_s(ErrMsg, sizeof(ErrMsg), _TRUNCATE, "%s", ts->UIMsg);
639                          }                          }
640                          if (HIWORD(lParam)>0) {                          if (HIWORD(lParam)>0) {
 #ifndef NO_INET6  
641                                  /* connect() failed */                                  /* connect() failed */
642                                  if (cv->res->ai_next != NULL) {                                  if (cv->res->ai_next != NULL) {
643                                          /* try to connect with other protocol */                                          /* try to connect with other protocol */
# Line 784  void CommStart(PComVar cv, LONG lParam, Line 664  void CommStart(PComVar cv, LONG lParam,
664                                          cv->RetryWithOtherProtocol = FALSE;                                          cv->RetryWithOtherProtocol = FALSE;
665                                          return;                                          return;
666                                  }                                  }
 #else  
         if (cv->NoMsg==0) {  
           get_lang_msg("MSG_TT_ERROR", uimsg, sizeof(uimsg), "Tera Term: Error", ts->UILanguageFile);  
           MessageBox(cv->HWin, ErrMsg, uimsg, MB_TASKMODAL | MB_ICONEXCLAMATION);  
         }  
         PostMessage(cv->HWin, WM_USER_COMMNOTIFY, 0, FD_CLOSE);  
         return;  
 #endif /* NO_INET6 */  
667                          }                          }
668    
 #ifndef NO_INET6  
669                          /* here is connection established */                          /* here is connection established */
670                          cv->RetryWithOtherProtocol = FALSE;                          cv->RetryWithOtherProtocol = FALSE;
 #endif /* NO_INET6 */  
671                          PWSAAsyncSelect(cv->s,cv->HWin,WM_USER_COMMNOTIFY, FD_READ | FD_OOB | FD_CLOSE);                          PWSAAsyncSelect(cv->s,cv->HWin,WM_USER_COMMNOTIFY, FD_READ | FD_OOB | FD_CLOSE);
672                          TCPIPClosed = FALSE;                          TCPIPClosed = FALSE;
673                          break;                          break;
# Line 891  void CommClose(PComVar cv) Line 761  void CommClose(PComVar cv)
761                                  PWSACancelAsyncRequest(HAsync);                                  PWSACancelAsyncRequest(HAsync);
762                          }                          }
763                          HAsync = 0;                          HAsync = 0;
 #ifndef NO_INET6  
764                          Pfreeaddrinfo(cv->res0);                          Pfreeaddrinfo(cv->res0);
 #endif /* NO_INET6 */  
765                          if ( cv->s!=INVALID_SOCKET ) {                          if ( cv->s!=INVALID_SOCKET ) {
766                                  Pclosesocket(cv->s);                                  Pclosesocket(cv->s);
767                          }                          }

Legend:
Removed from v.6662  
changed lines
  Added in v.6738

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26