Changeset 1951 for trunk/src


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

Fix: more asynchronous functions supported

Location:
trunk/src/wsock32/new
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wsock32/new/makefile

    r1933 r1951  
    1 # $Id: makefile,v 1.6 1999-12-02 07:47:26 phaller Exp $
     1# $Id: makefile,v 1.7 1999-12-02 21:35:28 phaller Exp $
    22
    33#
     
    4040    $(IMPDEF) $** $@
    4141
    42 wsock32.obj: wsock32.cpp
    43 unknown.obj: unknown.cpp
     42wsock32.obj: wsock32.cpp   relaywin.h wsock32.h
     43unknown.obj: unknown.cpp   wsock32.h
    4444initterm.obj: initterm.cpp
    45 relaywin.obj: relaywin.cpp
     45relaywin.obj: relaywin.cpp relaywin.h wsock32.h
    4646
    4747
  • 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
  • trunk/src/wsock32/new/relaywin.h

    r1940 r1951  
    1 /* $Id: relaywin.h,v 1.3 1999-12-02 15:22:05 achimha Exp $ */
     1/* $Id: relaywin.h,v 1.4 1999-12-02 21:35:29 phaller Exp $ */
    22
    33/*
     
    3737
    3838/* these are the request types so we can interpret the messages and convert the results */
    39 #define ASYNCREQUEST_SELECT 0
    40 #define ASYNCREQUEST_GETHOSTBYNAME 1
     39
     40#define  ASYNCREQUEST_GETHOSTBYNAME     0
     41#define  ASYNCREQUEST_GETHOSTBYADDR     1
     42#define  ASYNCREQUEST_GETSERVBYNAME     2
     43#define  ASYNCREQUEST_GETSERVBYPORT     3
     44#define  ASYNCREQUEST_GETPROTOBYNAME    4
     45#define  ASYNCREQUEST_GETPROTOBYNUMBER  5
     46#define  ASYNCREQUEST_SELECT            6
     47
    4148
    4249typedef struct tagHwndMsgPair
     
    4956} HWNDMSGPAIR, *PHWNDMSGPAIR;
    5057
     58
    5159/*****************************************************************************
    5260 * Prototypes                                                                *
    5361 *****************************************************************************/
    5462
    55 ULONG RelayAlloc(HWND hwnd, ULONG ulMsg, ULONG ulRequestType,
    56                  PVOID pvUserData1 = 0, PVOID pvUserData2 = 0);
    57 ULONG        RelayFree      (ULONG ulID);
    58 ULONG        RelayFreeByHwnd(HWND  hwnd);
    59 PHWNDMSGPAIR RelayQuery     (ULONG ulID);
    60 MRESULT EXPENTRY RelayWindowProc(HWND  hwnd, ULONG  ulMsg, MPARAM mp1, MPARAM mp2);
    61 HWND         RelayInitialize(HWND  hwndPost);
    62 BOOL         RelayTerminate (HWND  hwndRelay);
     63ULONG            RelayAlloc     (HWND  hwnd,
     64                                 ULONG ulMsg,
     65                                 ULONG ulRequestType,
     66                                 BOOL  fSingleRequestPerWindow,
     67                                 PVOID pvUserData1 = 0,
     68                                 PVOID pvUserData2 = 0);
     69
     70ULONG            RelayFree      (ULONG ulID);
     71
     72ULONG            RelayFreeByHwnd(HWND  hwnd);
     73
     74PHWNDMSGPAIR     RelayQuery     (ULONG ulID);
     75
     76MRESULT EXPENTRY RelayWindowProc(HWND   hwnd,
     77                                 ULONG  ulMsg,
     78                                 MPARAM mp1,
     79                                 MPARAM mp2);
     80
     81HWND             RelayInitialize(HWND  hwndPost);
     82
     83BOOL             RelayTerminate (HWND  hwndRelay);
    6384
    6485
  • trunk/src/wsock32/new/wsock32.cpp

    r1943 r1951  
    1 /* $Id: wsock32.cpp,v 1.10 1999-12-02 16:12:24 achimha Exp $ */
     1/* $Id: wsock32.cpp,v 1.11 1999-12-02 21:35:29 phaller Exp $ */
    22
    33/*
     
    6363static WSOCKTHREADDATA wstdFallthru; // for emergency only
    6464
    65 static HWND hwndRelay; // handle to our relay window
     65static HWND hwndRelay = NULL; // handle to our relay window
     66
    6667
    6768/*****************************************************************************
     
    890891
    891892ODINFUNCTION2(struct Wservent *,OS2getservbyport,
    892               int,port,
    893               const char *, proto)
     893              int,              port,
     894              const char *,     proto)
    894895{
    895896  struct servent   *xx;
     
    927928
    928929ODINFUNCTION2(struct Wservent *,OS2getservbyname,
    929               const char *,name,
    930               const char *,proto)
     930              const char *,     name,
     931              const char *,     proto)
    931932{
    932933  WSERVENT         *yy;
     
    11581159              int,buflen)
    11591160{
    1160   return(WSAAsyncGetServByName(hWnd,
    1161                                wMsg,
    1162                                name,
    1163                                proto,
    1164                                buf,
    1165                                buflen));
     1161  int   rc;
     1162  HWND  hwndOS2 = Win32ToOS2Handle(hWnd);
     1163  ULONG ulNewID;
     1164
     1165  if (hwndRelay == NULL) // already initialized ?
     1166    hwndRelay = RelayInitialize(hwndOS2);
     1167
     1168  // add entry to list, we need to store both our temp buffer and the apps buffer
     1169  ulNewID = RelayAlloc(hWnd,
     1170                       wMsg,
     1171                       FALSE,
     1172                       ASYNCREQUEST_GETSERVBYNAME,
     1173                       buf);
     1174
     1175  // call pmwsock function, will fill our temp buffer
     1176  rc = WSAAsyncGetServByName(hwndRelay,
     1177                              ulNewID,
     1178                              name,
     1179                              proto,
     1180                              buf,
     1181                              buflen);
     1182 
     1183  // if an error occurs, free the allocated relay entry
     1184  if (rc == SOCKET_ERROR)
     1185    RelayFree(ulNewID);
     1186
     1187  return (rc);   
    11661188}
    11671189
     
    11871209              int,buflen)
    11881210{
    1189   return(WSAAsyncGetServByPort(hWnd,
    1190                                wMsg,
    1191                                port,
    1192                                proto,
    1193                                buf,
    1194                                buflen));
     1211  int   rc;
     1212  HWND  hwndOS2 = Win32ToOS2Handle(hWnd);
     1213  ULONG ulNewID;
     1214
     1215  if (hwndRelay == NULL) // already initialized ?
     1216    hwndRelay = RelayInitialize(hwndOS2);
     1217
     1218  // add entry to list, we need to store both our temp buffer and the apps buffer
     1219  ulNewID = RelayAlloc(hWnd,
     1220                       wMsg,
     1221                       FALSE,
     1222                       ASYNCREQUEST_GETSERVBYPORT,
     1223                       buf);
     1224
     1225  // call pmwsock function, will fill our temp buffer
     1226  rc = WSAAsyncGetServByPort(hwndRelay,
     1227                             ulNewID,
     1228                             port,
     1229                             proto,
     1230                             buf,
     1231                             buflen);
     1232 
     1233  // if an error occurs, free the allocated relay entry
     1234  if (rc == SOCKET_ERROR)
     1235    RelayFree(ulNewID);
     1236 
     1237  return rc; 
    11951238}
    11961239
     
    12151258              int,buflen)
    12161259{
    1217   return(WSAAsyncGetProtoByName(hWnd,
    1218                                 wMsg,
    1219                                 name,
    1220                                 buf,
    1221                                 buflen));
     1260  int   rc;
     1261  HWND  hwndOS2 = Win32ToOS2Handle(hWnd);
     1262  ULONG ulNewID;
     1263
     1264  if (hwndRelay == NULL) // already initialized ?
     1265    hwndRelay = RelayInitialize(hwndOS2);
     1266
     1267  // add entry to list, we need to store both our temp buffer and the apps buffer
     1268  ulNewID = RelayAlloc(hWnd,
     1269                       wMsg,
     1270                       FALSE,
     1271                       ASYNCREQUEST_GETPROTOBYNAME,
     1272                       buf);
     1273
     1274  // call pmwsock function, will fill our temp buffer
     1275  rc = WSAAsyncGetProtoByName(hwndRelay,
     1276                              ulNewID,
     1277                              name,
     1278                              buf,
     1279                              buflen);
     1280 
     1281  // if an error occurs, free the allocated relay entry
     1282  if (rc == SOCKET_ERROR)
     1283    RelayFree(ulNewID);
     1284
     1285  return (rc); 
    12221286}
    12231287
     
    12421306              int,buflen)
    12431307{
    1244   return(WSAAsyncGetProtoByNumber(hWnd,
    1245                                   wMsg,
    1246                                   number,
    1247                                   buf,
    1248                                   buflen));
     1308  int   rc;
     1309  HWND  hwndOS2 = Win32ToOS2Handle(hWnd);
     1310  ULONG ulNewID;
     1311
     1312  if (hwndRelay == NULL) // already initialized ?
     1313    hwndRelay = RelayInitialize(hwndOS2);
     1314
     1315  // add entry to list, we need to store both our temp buffer and the apps buffer
     1316  ulNewID = RelayAlloc(hWnd,
     1317                       wMsg,
     1318                       FALSE,
     1319                       ASYNCREQUEST_GETPROTOBYNUMBER,
     1320                       buf);
     1321
     1322  // call pmwsock function, will fill our temp buffer
     1323  rc = WSAAsyncGetProtoByNumber(hwndRelay,
     1324                                ulNewID,
     1325                                number,
     1326                                buf,
     1327                                buflen);
     1328 
     1329  // if an error occurs, free the allocated relay entry
     1330  if (rc == SOCKET_ERROR)
     1331    RelayFree(ulNewID);
     1332 
     1333  return rc;
    12491334}
    12501335
     
    12761361    hwndRelay = RelayInitialize(hwndOS2);
    12771362
    1278   // TODO: Is this the original behaviour?
    1279   if ((name == NULL) || (buf == NULL))
    1280   {
    1281     // remove entry from list
    1282     RelayFreeByHwnd(hWnd);
    1283   }
    1284   else
    1285     // add entry to list, we need to store both our temp buffer and the apps buffer
    1286     ulNewID = RelayAlloc(hWnd, wMsg, ASYNCREQUEST_GETHOSTBYNAME, buf);
     1363  // 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,
     1368                       buf);
    12871369
    12881370  // call pmwsock function, will fill our temp buffer
     
    12921374                             buf,
    12931375                             buflen);
    1294 
     1376 
     1377  // if an error occurs, free the allocated relay entry
     1378  if (rc == SOCKET_ERROR)
     1379    RelayFree(ulNewID);
     1380 
    12951381  return rc;
    12961382}
     
    13181404              int,buflen)
    13191405{
    1320   return(WSAAsyncGetHostByAddr(hWnd,
    1321                                wMsg,
    1322                                addr,
    1323                                len,
    1324                                type,
    1325                                buf,
    1326                                buflen));
     1406  int   rc;
     1407  HWND  hwndOS2 = Win32ToOS2Handle(hWnd);
     1408  ULONG ulNewID;
     1409
     1410  if (hwndRelay == NULL) // already initialized ?
     1411    hwndRelay = RelayInitialize(hwndOS2);
     1412
     1413  // add entry to list, we need to store both our temp buffer and the apps buffer
     1414  ulNewID = RelayAlloc(hWnd,
     1415                       wMsg,
     1416                       FALSE,
     1417                       ASYNCREQUEST_GETHOSTBYADDR,
     1418                       buf);
     1419
     1420  // call pmwsock function, will fill our temp buffer
     1421  rc = WSAAsyncGetHostByAddr(hwndRelay,
     1422                             ulNewID,
     1423                             addr,
     1424                             len,
     1425                             type,
     1426                             buf,
     1427                             buflen);
     1428 
     1429  // if an error occurs, free the allocated relay entry
     1430  if (rc == SOCKET_ERROR)
     1431    RelayFree(ulNewID);
     1432
     1433  return (rc);
    13271434}
    13281435
     
    13991506  else
    14001507    // add entry to list
    1401     ulNewID = RelayAlloc(hWnd, wMsg, ASYNCREQUEST_SELECT);
     1508    ulNewID = RelayAlloc(hWnd,
     1509                         wMsg,
     1510                         TRUE,
     1511                         ASYNCREQUEST_SELECT);
    14021512
    14031513  rc = WSAAsyncSelect(s,
Note: See TracChangeset for help on using the changeset viewer.