Changeset 1952 for trunk/src/wsock32


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

Location:
trunk/src/wsock32/new
Files:
2 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/*****************************************************************************
  • trunk/src/wsock32/new/wsock32.cpp

    r1951 r1952  
    1 /* $Id: wsock32.cpp,v 1.11 1999-12-02 21:35:29 phaller Exp $ */
     1/* $Id: wsock32.cpp,v 1.12 1999-12-03 01:19:56 phaller Exp $ */
    22
    33/*
     
    4747#include <win32wnd.h>
    4848
     49
    4950#include "wsock32.h"
    5051#include "relaywin.h"
     
    6465
    6566static HWND hwndRelay = NULL; // handle to our relay window
     67
     68
     69/*****************************************************************************
     70 * Prototypes                                                                *
     71 *****************************************************************************/
     72
     73void __stdcall SetLastError(DWORD dwError);
    6674
    6775
     
    202210               int,iError)
    203211{
     212  // according to the docs, WSASetLastError() is just a call-through
     213  // to SetLastError()
    204214  WSASetLastError(iError);
     215  SetLastError(iError);
    205216}
    206217
     
    220231ODINFUNCTION0(int,OS2WSAGetLastError)
    221232{
     233  // according to the docs, WSASetLastError() is just a call-through
     234  // to SetLastError(). However, what can be implemented here?
    222235  return WSAGetLastError();
    223236}
     
    11671180
    11681181  // add entry to list, we need to store both our temp buffer and the apps buffer
    1169   ulNewID = RelayAlloc(hWnd, 
    1170                        wMsg, 
    1171                        FALSE, 
     1182  ulNewID = RelayAlloc(hWnd,
     1183                       wMsg,
     1184                       FALSE,
    11721185                       ASYNCREQUEST_GETSERVBYNAME,
    11731186                       buf);
     
    11801193                              buf,
    11811194                              buflen);
    1182  
     1195
    11831196  // if an error occurs, free the allocated relay entry
    11841197  if (rc == SOCKET_ERROR)
    11851198    RelayFree(ulNewID);
    11861199
    1187   return (rc);   
     1200  return (rc);
    11881201}
    11891202
     
    12171230
    12181231  // add entry to list, we need to store both our temp buffer and the apps buffer
    1219   ulNewID = RelayAlloc(hWnd, 
    1220                        wMsg, 
    1221                        FALSE, 
     1232  ulNewID = RelayAlloc(hWnd,
     1233                       wMsg,
     1234                       FALSE,
    12221235                       ASYNCREQUEST_GETSERVBYPORT,
    12231236                       buf);
     
    12301243                             buf,
    12311244                             buflen);
    1232  
     1245
    12331246  // if an error occurs, free the allocated relay entry
    12341247  if (rc == SOCKET_ERROR)
    12351248    RelayFree(ulNewID);
    1236  
    1237   return rc; 
     1249
     1250  return rc;
    12381251}
    12391252
     
    12661279
    12671280  // add entry to list, we need to store both our temp buffer and the apps buffer
    1268   ulNewID = RelayAlloc(hWnd, 
    1269                        wMsg, 
    1270                        FALSE, 
     1281  ulNewID = RelayAlloc(hWnd,
     1282                       wMsg,
     1283                       FALSE,
    12711284                       ASYNCREQUEST_GETPROTOBYNAME,
    12721285                       buf);
     
    12781291                              buf,
    12791292                              buflen);
    1280  
     1293
    12811294  // if an error occurs, free the allocated relay entry
    12821295  if (rc == SOCKET_ERROR)
    12831296    RelayFree(ulNewID);
    12841297
    1285   return (rc); 
     1298  return (rc);
    12861299}
    12871300
     
    13141327
    13151328  // add entry to list, we need to store both our temp buffer and the apps buffer
    1316   ulNewID = RelayAlloc(hWnd, 
    1317                        wMsg, 
    1318                        FALSE, 
     1329  ulNewID = RelayAlloc(hWnd,
     1330                       wMsg,
     1331                       FALSE,
    13191332                       ASYNCREQUEST_GETPROTOBYNUMBER,
    13201333                       buf);
     
    13261339                                buf,
    13271340                                buflen);
    1328  
     1341
    13291342  // if an error occurs, free the allocated relay entry
    13301343  if (rc == SOCKET_ERROR)
    13311344    RelayFree(ulNewID);
    1332  
     1345
    13331346  return rc;
    13341347}
     
    13621375
    13631376  // add entry to list, we need to store both our temp buffer and the apps buffer
    1364   ulNewID = RelayAlloc(hWnd, 
    1365                        wMsg, 
    1366                        FALSE, 
    1367                        ASYNCREQUEST_GETHOSTBYNAME, 
     1377  ulNewID = RelayAlloc(hWnd,
     1378                       wMsg,
     1379                       FALSE,
     1380                       ASYNCREQUEST_GETHOSTBYNAME,
    13681381                       buf);
    13691382
     
    13741387                             buf,
    13751388                             buflen);
    1376  
     1389
    13771390  // if an error occurs, free the allocated relay entry
    13781391  if (rc == SOCKET_ERROR)
    13791392    RelayFree(ulNewID);
    1380  
     1393
    13811394  return rc;
    13821395}
     
    14121425
    14131426  // add entry to list, we need to store both our temp buffer and the apps buffer
    1414   ulNewID = RelayAlloc(hWnd, 
    1415                        wMsg, 
    1416                        FALSE, 
     1427  ulNewID = RelayAlloc(hWnd,
     1428                       wMsg,
     1429                       FALSE,
    14171430                       ASYNCREQUEST_GETHOSTBYADDR,
    14181431                       buf);
     
    14261439                             buf,
    14271440                             buflen);
    1428  
     1441
    14291442  // if an error occurs, free the allocated relay entry
    14301443  if (rc == SOCKET_ERROR)
     
    15061519  else
    15071520    // add entry to list
    1508     ulNewID = RelayAlloc(hWnd, 
    1509                          wMsg, 
     1521    ulNewID = RelayAlloc(hWnd,
     1522                         wMsg,
    15101523                         TRUE,
    15111524                         ASYNCREQUEST_SELECT);
Note: See TracChangeset for help on using the changeset viewer.