Ignore:
Timestamp:
Dec 2, 1999, 10:35:29 PM (26 years ago)
Author:
phaller
Message:

Fix: more asynchronous functions supported

File:
1 edited

Legend:

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

    r1945 r1951  
    1 /* $Id: relaywin.cpp,v 1.7 1999-12-02 16:39:46 achimha Exp $ */
     1/* $Id: relaywin.cpp,v 1.8 1999-12-02 21:35:29 phaller Exp $ */
    22
    33/*
     
    7575 *****************************************************************************/
    7676
    77 ULONG RelayAlloc(HWND hwnd, ULONG ulMsg, ULONG ulRequestType,
    78                  PVOID pvUserData1, PVOID pvUserData2)
     77ULONG RelayAlloc(HWND  hwnd,
     78                 ULONG ulMsg,
     79                 ULONG ulRequestType,
     80                 BOOL  fSingleRequestPerWindow,
     81                 PVOID pvUserData1,
     82                 PVOID pvUserData2)
    7983{
    8084  ULONG ulCounter;
     
    8488       ulCounter++)
    8589    if ( (arrHwndMsgPair[ulCounter].hwnd == 0) ||    // slot free?
    86          (arrHwndMsgPair[ulCounter].hwnd == hwnd) )  // same window?
     90         ( (fSingleRequestPerWindow == TRUE) &&      // more than one request
     91                                                     // per window ?
     92           (arrHwndMsgPair[ulCounter].hwnd == hwnd) ) ) // same window?
    8793    {
    8894      // occupy slot
    89       arrHwndMsgPair[ulCounter].hwnd  = hwnd;
    90       arrHwndMsgPair[ulCounter].ulMsg = ulMsg;
     95      arrHwndMsgPair[ulCounter].hwnd          = hwnd;
     96      arrHwndMsgPair[ulCounter].ulMsg         = ulMsg;
    9197      arrHwndMsgPair[ulCounter].ulRequestType = ulRequestType;
    92       arrHwndMsgPair[ulCounter].pvUserData1 = pvUserData1;
    93       arrHwndMsgPair[ulCounter].pvUserData2 = pvUserData2;
    94       return ulCounter; // return "id"
     98      arrHwndMsgPair[ulCounter].pvUserData1   = pvUserData1;
     99      arrHwndMsgPair[ulCounter].pvUserData2   = pvUserData2;
     100      return ulCounter + 1; // return "id"
    95101    }
    96102
     
    113119ULONG RelayFree(ULONG ulID)
    114120{
    115   if ( (ulID < 0) ||  // check range
    116        (ulID >= MAX_ASYNC_SOCKETS) )
     121  if ( (ulID < 1) ||  // check range
     122       (ulID > MAX_ASYNC_SOCKETS) )
    117123    return -1; // error
    118124
    119   arrHwndMsgPair[ulID].hwnd = 0; // mark free
     125  arrHwndMsgPair[ulID-1].hwnd = 0; // mark free
    120126
    121127  return 0; // OK
     
    166172PHWNDMSGPAIR RelayQuery(ULONG ulID)
    167173{
    168   if ( (ulID < 0) ||  // check range
    169        (ulID >= MAX_ASYNC_SOCKETS) )
     174  if ( (ulID < 1) ||  // check range
     175       (ulID > MAX_ASYNC_SOCKETS) )
    170176    return NULL; // error
    171177 
    172   if (arrHwndMsgPair[ulID].hwnd == 0)
     178  if (arrHwndMsgPair[ulID-1].hwnd == 0)
    173179    return NULL; // error, free entry
    174180  else
    175     return (&arrHwndMsgPair[ulID]);
     181    return (&arrHwndMsgPair[ulID-1]);
    176182}
    177183
     
    195201{
    196202  PHWNDMSGPAIR pHM;
     203  int          rc;
    197204
    198205  // termination flag handling?
     
    203210  if (pHM != NULL)                                  // message pair found
    204211  {
     212    rc = SHORT1FROMMP(mp2);                /* asynchronous operation result */
     213   
    205214    /* check request type for special handling */
    206215    switch (pHM->ulRequestType)
    207216    {
     217      /**********
     218       * SELECT *
     219       **********/
    208220      case ASYNCREQUEST_SELECT:
    209221      {
     
    211223        break;
    212224      }
     225     
     226     
     227      /*****************
     228       * GETHOSTBYNAME *
     229       *****************/
    213230      case ASYNCREQUEST_GETHOSTBYNAME:
    214231      {
    215232        dprintf(("WSOCK32:RelayWindowProc, Converting hostent for "
    216233                 "WSAAyncGetHostByName\n"));
    217         /* we need to convert the hostent structure here */
    218         Whostent *WinHostent = (Whostent*)pHM->pvUserData1;
    219         hostent *OS2Hostent = (hostent*)pHM->pvUserData1;
    220         short h_addrtype = (short)OS2Hostent->h_addrtype;
    221         WinHostent->h_addrtype = h_addrtype;
    222         short h_length = (short)OS2Hostent->h_length;
    223         WinHostent->h_length = h_length;
    224         char **h_addr_list = OS2Hostent->h_addr_list;
    225         WinHostent->h_addr_list = h_addr_list;
    226   //TODO: the size of OS/2 hostent is 4 bytes bigger so the original buffer *might* be too small
    227 
     234       
     235        /* is there a valid result ? */
     236        if (rc == 0)
     237        {
     238          /* we need to convert the hostent structure here */
     239          Whostent *WinHostent             = (Whostent*)pHM->pvUserData1;
     240          hostent  *OS2Hostent             = (hostent*)pHM->pvUserData1;
     241         
     242          short    h_addrtype              = (short)OS2Hostent->h_addrtype;
     243                   WinHostent->h_addrtype  = h_addrtype;
     244          short    h_length                = (short)OS2Hostent->h_length;
     245                   WinHostent->h_length    = h_length;
     246          char     **h_addr_list           = OS2Hostent->h_addr_list;
     247                   WinHostent->h_addr_list = h_addr_list;
     248          //TODO: the size of OS/2 hostent is 4 bytes bigger
     249          //      so the original buffer *might* be too small
     250        }
     251        break;
     252      }
     253     
     254     
     255      /*****************
     256       * GETHOSTBYADDR *
     257       *****************/
     258      case ASYNCREQUEST_GETHOSTBYADDR:
     259      {
     260        dprintf(("WSOCK32:RelayWindowProc, Converting hostent for "
     261                 "WSAAyncGetHostByAddr\n"));
     262       
     263        if (rc == 0)
     264        {
     265          /* we need to convert the hostent structure here */
     266          Whostent *WinHostent             = (Whostent*)pHM->pvUserData1;
     267          hostent  *OS2Hostent             = (hostent*)pHM->pvUserData1;
     268         
     269          short    h_addrtype              = (short)OS2Hostent->h_addrtype;
     270                   WinHostent->h_addrtype  = h_addrtype;
     271          short    h_length                = (short)OS2Hostent->h_length;
     272                   WinHostent->h_length    = h_length;
     273          char     **h_addr_list           = OS2Hostent->h_addr_list;
     274                   WinHostent->h_addr_list = h_addr_list;
     275          //TODO: the size of OS/2 hostent is 4 bytes bigger
     276          //      so the original buffer *might* be too small
     277        }
     278        break;
     279      }     
     280     
     281     
     282      /*****************
     283       * GETSERVBYNAME *
     284       *****************/
     285      case ASYNCREQUEST_GETSERVBYNAME:
     286      {
     287        dprintf(("WSOCK32:RelayWindowProc, Converting servent for "
     288                 "WSAAyncGetServByName\n"));
     289       
     290        if (rc == 0)
     291        {
     292          /* we need to convert the servent structure here */
     293          Wservent *WinServent             = (Wservent*)pHM->pvUserData1;
     294          servent  *OS2Servent             = (servent*)pHM->pvUserData1;
     295         
     296          WinServent->s_port  = OS2Servent->s_port;
     297          WinServent->s_proto = OS2Servent->s_proto;
     298          //TODO: the size of OS/2 servent is 2 bytes bigger
     299          //      so the original buffer *might* be too small
     300        }
     301        break;
     302      }           
     303     
     304     
     305      /*****************
     306       * GETSERVBYPORT *
     307       *****************/
     308      case ASYNCREQUEST_GETSERVBYPORT:
     309      {
     310        dprintf(("WSOCK32:RelayWindowProc, Converting servent for "
     311                 "WSAAyncGetServByPort\n"));
     312       
     313        if (rc == 0)
     314        {
     315          /* we need to convert the servent structure here */
     316          Wservent *WinServent             = (Wservent*)pHM->pvUserData1;
     317          servent  *OS2Servent             = (servent*)pHM->pvUserData1;
     318         
     319          WinServent->s_port  = OS2Servent->s_port;
     320          WinServent->s_proto = OS2Servent->s_proto;
     321          //TODO: the size of OS/2 servent is 2 bytes bigger
     322          //      so the original buffer *might* be too small
     323        }
     324        break;
     325      }           
     326     
     327     
     328      /******************
     329       * GETPROTOBYNAME *
     330       ******************/
     331      case ASYNCREQUEST_GETPROTOBYNAME:
     332      {
     333        dprintf(("WSOCK32:RelayWindowProc, Converting protoent for "
     334                 "WSAAyncGetProtoByName\n"));
     335       
     336        if (rc == 0)
     337        {
     338          /* we need to convert the protoent structure here */
     339          Wprotoent *WinProtoent             = (Wprotoent*)pHM->pvUserData1;
     340          protoent  *OS2Protoent             = (protoent*)pHM->pvUserData1;
     341         
     342          WinProtoent->p_proto = OS2Protoent->p_proto;
     343         
     344          //TODO: the size of OS/2 hostent is 2 bytes bigger
     345          //      so the original buffer *might* be too small
     346        }
     347        break;
     348      }                 
     349     
     350     
     351      /********************
     352       * GETPROTOBYNUMBER *
     353       ********************/
     354      case ASYNCREQUEST_GETPROTOBYNUMBER:
     355      {
     356        dprintf(("WSOCK32:RelayWindowProc, Converting protoent for "
     357                 "WSAAyncGetProtoByNumber\n"));
     358       
     359        if (rc == 0)
     360        {
     361          /* we need to convert the protoent structure here */
     362          Wprotoent *WinProtoent             = (Wprotoent*)pHM->pvUserData1;
     363          protoent  *OS2Protoent             = (protoent*)pHM->pvUserData1;
     364         
     365          WinProtoent->p_proto = OS2Protoent->p_proto;
     366         
     367          //TODO: the size of OS/2 hostent is 2 bytes bigger
     368          //      so the original buffer *might* be too small
     369        }
    228370        break;
    229371      }
    230372    }
    231 
    232     dprintf(("WSOCK32:RelayWinProc, Posting %d to %d\n", pHM->ulMsg, pHM->hwnd));
     373   
     374   
     375    dprintf(("WSOCK32:RelayWinProc, Posting hwnd=%08xh, msg=%08xh, w=%08xh, l=%08xh\n",
     376             pHM->hwnd,
     377             pHM->ulMsg,
     378             mp1,
     379             mp2));
     380   
    233381    PostMessageA(pHM->hwnd,
    234382                 pHM->ulMsg,
     
    236384                 (ULONG)mp2);
    237385
    238     // if socket close, free entry
    239     //@@@PH
     386    // if socket close or non-select call, free entry
     387    // @@@PH
     388    if (pHM->ulRequestType != ASYNCREQUEST_SELECT)
     389      RelayFree(pHM->ulMsg);
    240390
    241391    return FALSE;                                   // OK, message sent
Note: See TracChangeset for help on using the changeset viewer.