Ignore:
Timestamp:
Dec 3, 1999, 2:19:56 AM (26 years ago)
Author:
phaller
Message:

Add: created separate thread and message queue for WSOCK processign

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wsock32/new/relaywin.cpp

    r1951 r1952  
    1 /* $Id: relaywin.cpp,v 1.8 1999-12-02 21:35:29 phaller Exp $ */
     1
    22
    33/*
     
    5757static HWNDMSGPAIR arrHwndMsgPair[MAX_ASYNC_SOCKETS];
    5858static char*       ODIN_WSOCK_RELAY_CLASS = "ODIN_WSOCK_RELAY";
    59 
     59static HWND        hwndRelay              = NULLHANDLE;
    6060
    6161// prototype for PostMessageA
     
    7676
    7777ULONG RelayAlloc(HWND  hwnd,
    78                  ULONG ulMsg, 
     78                 ULONG ulMsg,
    7979                 ULONG ulRequestType,
    8080                 BOOL  fSingleRequestPerWindow,
    81                  PVOID pvUserData1, 
     81                 PVOID pvUserData1,
    8282                 PVOID pvUserData2)
    8383{
     
    175175       (ulID > MAX_ASYNC_SOCKETS) )
    176176    return NULL; // error
    177  
     177
    178178  if (arrHwndMsgPair[ulID-1].hwnd == 0)
    179179    return NULL; // error, free entry
     
    206206  // if (fTerminate)
    207207  //   WinDefWindowProc()
    208  
     208
    209209  pHM = RelayQuery(ulMsg);                          // find registered message
    210210  if (pHM != NULL)                                  // message pair found
    211211  {
    212212    rc = SHORT1FROMMP(mp2);                /* asynchronous operation result */
    213    
     213
    214214    /* check request type for special handling */
    215215    switch (pHM->ulRequestType)
     
    223223        break;
    224224      }
    225      
    226      
     225
     226
    227227      /*****************
    228228       * GETHOSTBYNAME *
     
    232232        dprintf(("WSOCK32:RelayWindowProc, Converting hostent for "
    233233                 "WSAAyncGetHostByName\n"));
    234        
     234
    235235        /* is there a valid result ? */
    236236        if (rc == 0)
     
    239239          Whostent *WinHostent             = (Whostent*)pHM->pvUserData1;
    240240          hostent  *OS2Hostent             = (hostent*)pHM->pvUserData1;
    241          
     241
    242242          short    h_addrtype              = (short)OS2Hostent->h_addrtype;
    243243                   WinHostent->h_addrtype  = h_addrtype;
     
    246246          char     **h_addr_list           = OS2Hostent->h_addr_list;
    247247                   WinHostent->h_addr_list = h_addr_list;
    248           //TODO: the size of OS/2 hostent is 4 bytes bigger 
     248          //TODO: the size of OS/2 hostent is 4 bytes bigger
    249249          //      so the original buffer *might* be too small
    250250        }
    251251        break;
    252252      }
    253      
    254      
     253
     254
    255255      /*****************
    256256       * GETHOSTBYADDR *
     
    260260        dprintf(("WSOCK32:RelayWindowProc, Converting hostent for "
    261261                 "WSAAyncGetHostByAddr\n"));
    262        
     262
    263263        if (rc == 0)
    264264        {
     
    266266          Whostent *WinHostent             = (Whostent*)pHM->pvUserData1;
    267267          hostent  *OS2Hostent             = (hostent*)pHM->pvUserData1;
    268          
     268
    269269          short    h_addrtype              = (short)OS2Hostent->h_addrtype;
    270270                   WinHostent->h_addrtype  = h_addrtype;
     
    273273          char     **h_addr_list           = OS2Hostent->h_addr_list;
    274274                   WinHostent->h_addr_list = h_addr_list;
    275           //TODO: the size of OS/2 hostent is 4 bytes bigger 
     275          //TODO: the size of OS/2 hostent is 4 bytes bigger
    276276          //      so the original buffer *might* be too small
    277277        }
    278278        break;
    279       }     
    280      
    281      
     279      }
     280
     281
    282282      /*****************
    283283       * GETSERVBYNAME *
     
    287287        dprintf(("WSOCK32:RelayWindowProc, Converting servent for "
    288288                 "WSAAyncGetServByName\n"));
    289        
     289
    290290        if (rc == 0)
    291291        {
     
    293293          Wservent *WinServent             = (Wservent*)pHM->pvUserData1;
    294294          servent  *OS2Servent             = (servent*)pHM->pvUserData1;
    295          
     295
    296296          WinServent->s_port  = OS2Servent->s_port;
    297297          WinServent->s_proto = OS2Servent->s_proto;
     
    300300        }
    301301        break;
    302       }           
    303      
    304      
     302      }
     303
     304
    305305      /*****************
    306306       * GETSERVBYPORT *
     
    310310        dprintf(("WSOCK32:RelayWindowProc, Converting servent for "
    311311                 "WSAAyncGetServByPort\n"));
    312        
     312
    313313        if (rc == 0)
    314314        {
     
    316316          Wservent *WinServent             = (Wservent*)pHM->pvUserData1;
    317317          servent  *OS2Servent             = (servent*)pHM->pvUserData1;
    318          
     318
    319319          WinServent->s_port  = OS2Servent->s_port;
    320320          WinServent->s_proto = OS2Servent->s_proto;
     
    323323        }
    324324        break;
    325       }           
    326      
    327      
     325      }
     326
     327
    328328      /******************
    329329       * GETPROTOBYNAME *
     
    333333        dprintf(("WSOCK32:RelayWindowProc, Converting protoent for "
    334334                 "WSAAyncGetProtoByName\n"));
    335        
     335
    336336        if (rc == 0)
    337337        {
     
    339339          Wprotoent *WinProtoent             = (Wprotoent*)pHM->pvUserData1;
    340340          protoent  *OS2Protoent             = (protoent*)pHM->pvUserData1;
    341          
     341
    342342          WinProtoent->p_proto = OS2Protoent->p_proto;
    343          
     343
    344344          //TODO: the size of OS/2 hostent is 2 bytes bigger
    345345          //      so the original buffer *might* be too small
    346346        }
    347347        break;
    348       }                 
    349      
    350      
     348      }
     349
     350
    351351      /********************
    352352       * GETPROTOBYNUMBER *
     
    356356        dprintf(("WSOCK32:RelayWindowProc, Converting protoent for "
    357357                 "WSAAyncGetProtoByNumber\n"));
    358        
     358
    359359        if (rc == 0)
    360360        {
     
    362362          Wprotoent *WinProtoent             = (Wprotoent*)pHM->pvUserData1;
    363363          protoent  *OS2Protoent             = (protoent*)pHM->pvUserData1;
    364          
     364
    365365          WinProtoent->p_proto = OS2Protoent->p_proto;
    366          
     366
    367367          //TODO: the size of OS/2 hostent is 2 bytes bigger
    368368          //      so the original buffer *might* be too small
     
    371371      }
    372372    }
    373    
    374    
     373
     374
    375375    dprintf(("WSOCK32:RelayWinProc, Posting hwnd=%08xh, msg=%08xh, w=%08xh, l=%08xh\n",
    376376             pHM->hwnd,
     
    378378             mp1,
    379379             mp2));
    380    
     380
    381381    PostMessageA(pHM->hwnd,
    382382                 pHM->ulMsg,
     
    397397
    398398
     399
     400
     401#if 0
    399402/*****************************************************************************
    400403 * Name      :
     
    420423  if (hab == NULLHANDLE)
    421424    return NULLHANDLE;
     425
    422426
    423427  // register relay window class
     
    444448}
    445449
     450#else
     451
     452/*****************************************************************************
     453 * Name      :
     454 * Purpose   :
     455 * Parameters:
     456 * Variables :
     457 * Result    :
     458 * Remark    :
     459 * Status    :
     460 *
     461 * Author    : Patrick Haller [Tue, 1999/11/30 23:00]
     462 *****************************************************************************/
     463
     464
     465//----------------------------------------------------------------------
     466// thread 2 entry point: gets and dispatches object window messages
     467// _Optlink is an IBM C Set/2 function modifier
     468void _Optlink RelayThreadMain(PVOID pParameter)
     469{
     470  BOOL       fSuccess;
     471  HAB        hab;
     472  HMQ        hmq;
     473  QMSG       qmsg;
     474
     475  // thread initialization
     476  hab = WinInitialize( 0 );
     477  hmq = WinCreateMsgQueue( hab, 0 );
     478
     479  // prevent system from posting object window a WM_QUIT
     480  // I'll post WM_QUIT when it's time.
     481  fSuccess = WinCancelShutdown( hmq, TRUE );
     482  if (fSuccess != TRUE)
     483  {
     484    dprintf(("WSOCK32:RelayWin: ERROR WinCancelShutdown failed\n"));
     485    return;
     486  }
     487
     488  // register relay window class
     489  fSuccess = WinRegisterClass(hab,
     490                              ODIN_WSOCK_RELAY_CLASS,
     491                              (PFNWP)RelayWindowProc,
     492                              0,
     493                              0);
     494  if (fSuccess == FALSE)
     495  {
     496    dprintf(("WSOCK32:RelayWin: ERROR WinRegisterClass failed\n"));
     497    return;
     498  }
     499
     500  hwndRelay = WinCreateWindow(HWND_OBJECT,
     501                         ODIN_WSOCK_RELAY_CLASS,
     502                         "ODIN WSock Relay",
     503                         0, 0, 0, 0, 0,
     504                         HWND_OBJECT,
     505                         HWND_BOTTOM,
     506                         0,
     507                         NULL,
     508                         NULL );
     509  if (hwndRelay == NULLHANDLE)
     510  {
     511    dprintf(("WSOCK32:RelayWin: ERROR WinCreateWindow failed\n"));
     512    return;
     513  }
     514
     515  // get/dispatch messages; user messages, for the most part
     516  while( WinGetMsg ( hab, &qmsg, 0, 0, 0 ))
     517  {
     518    WinDispatchMsg ( hab, &qmsg );
     519  }
     520
     521  // clean up
     522  WinDestroyWindow( hwndRelay );
     523  WinDestroyMsgQueue( hmq );
     524  WinTerminate( hab );
     525
     526  // reset relay window handle
     527  hwndRelay = NULLHANDLE;
     528  return;
     529}
     530
     531
     532/*****************************************************************************
     533 * Name      :
     534 * Purpose   :
     535 * Parameters:
     536 * Variables :
     537 * Result    :
     538 * Remark    :
     539 * Status    :
     540 *
     541 * Author    : Patrick Haller [Tue, 1999/11/30 23:00]
     542 *****************************************************************************/
     543
     544HWND RelayInitialize(HWND hwndPost)
     545{
     546  int tidRelay;  // thread identifier
     547
     548  if (hwndRelay != NULLHANDLE)
     549  {
     550    // relay thread has been initialized
     551    return hwndRelay;
     552  }
     553
     554  // else create new subsystem
     555    // create thread
     556#if defined(__IBMCPP__)
     557    tidRelay  = _beginthread(RelayThreadMain,
     558                             NULL,
     559                             16384,
     560                             (PVOID)0);
     561#else
     562    tidRelay  = _beginthread(RelayThreadMain,
     563                             16384,
     564                             (PVOID)0);
     565#endif
     566
     567  // wait for thread to come up and send valid HWND
     568  // @@@PH this is an ugly hack
     569  dprintf(("WSOCK32:RELAYWIN:RelayInitialize wait for window handle\n"));
     570  while (hwndRelay == NULL)
     571  {
     572    DosSleep(10);
     573  }
     574  dprintf(("WSOCK32:RELAYWIN:RelayInitialize window handle = %08xh",
     575            hwndRelay));
     576
     577  return hwndRelay;
     578}
     579
     580#endif
     581
    446582
    447583/*****************************************************************************
Note: See TracChangeset for help on using the changeset viewer.