Ignore:
Timestamp:
Aug 16, 1999, 10:18:40 PM (26 years ago)
Author:
phaller
Message:

Fix: added odinwrap support to wsock32

File:
1 edited

Legend:

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

    r120 r518  
    1 /* $Id: wsock32.cpp,v 1.3 1999-06-19 10:54:48 sandervl Exp $ */
     1/* $Id: wsock32.cpp,v 1.4 1999-08-16 20:18:40 phaller Exp $ */
    22
    33/*
     
    55 * Project Odin Software License can be found in LICENSE.TXT
    66 *
     7 * Win32 SOCK32 for OS/2
     8 *
     9 * 1998/08/25 Vince Vielhaber
     10 *
     11 * @(#) wsock32.c                        1.0.0   1998/08/25 VV initial release
     12 *                      1.0.1   1999/04/27 VV cleanup and implement select.
     13 *
    714 */
    8 /*
    9  * Win32 SOCK32 for OS/2
    10  *
    11  * 1998/08/25 Vince Vielhaber
    12  *
    13  * @(#) wsock32.c       1.0.0   1998/08/25 VV initial release
    14  *                      1.0.1   1999/04/27 VV cleanup and implement select.
    15  *
    16  */
     15
     16
     17/*****************************************************************************
     18 * Includes                                                                  *
     19 *****************************************************************************/
     20
    1721
    1822#define INCL_DOSPROCESS     /* Process and thread values */
     
    3236#endif
    3337
    34 #include <os2wrap.h>    //Odin32 OS/2 api wrappers
     38#include <os2wrap.h>                     //Odin32 OS/2 api wrappers
    3539#include <stdio.h>
    3640#include <stdlib.h>
     
    3943#include <ctype.h>
    4044#include <types.h>
     45#include <odinwrap.h>
    4146#include <netdb.h>
    4247#include <sys/socket.h>
     
    5459
    5560
    56 #define FAR
    57 //#define WIN32API APIENTRY
     61ODINDEBUGCHANNEL(WSOCK32-WSOCK32)
     62
     63
     64/*****************************************************************************
     65 * Defines                                                                   *
     66 *****************************************************************************/
     67
     68#define GETSERVBYNAME    1
     69#define GETSERVBYPORT    2
     70#define GETPROTOBYNAME   3
     71#define GETPROTOBYNUMBER 4
     72#define GETHOSTBYNAME    5
     73#define GETHOSTBYADDR    6
     74
     75#define BLOCKING 0
     76#define NONBLOCKING 1
     77
     78#ifdef FD_CLR
     79#undef FD_CLR
     80#define FD_CLR(x,y) WFD_CLR(x,y)
     81#undef FD_SET
     82#define FD_SET(x,y) WFD_SET(x,y)
     83#undef FD_ZERO
     84#define FD_ZERO(x) WFD_ZERO(x)
     85#undef FD_ISSET
     86#define FD_ISSET(x,y) WFD_SET(x,y)
     87#endif
     88
     89
     90/*****************************************************************************
     91 * Structures                                                                *
     92 *****************************************************************************/
     93
     94typedef struct WSAStruct
     95{
     96  int CallingWhat;
     97  HWND hw;
     98  u_int msg;
     99  char *carg1;
     100  char *carg2;
     101  int iarg1;
     102  int iarg2;
     103  char *buf;
     104  int buflen;
     105} WSAStruct;
     106
     107typedef struct PipeStruct
     108{
     109  AsyncStatus as;
     110  int MsgLoop;
     111  HFILE rcv;
     112  HFILE snd;
     113} PipeStruct;
     114
     115typedef struct sockaddr* PSOCKADDR;
     116
     117//typedef struct _TRANSMIT_FILE_BUFFERS {
     118//    PVOID Head;
     119//    DWORD HeadLength;
     120//    PVOID Tail;
     121//    DWORD TailLength;
     122//} TRANSMIT_FILE_BUFFERS, *PTRANSMIT_FILE_BUFFERS, *LPTRANSMIT_FILE_BUFFERS;
     123//
     124//BOOL, OS2TransmitFile, //, IN, SOCKET, hSocket, //, IN, HANDLE, hFile, //, IN, DWORD, nNumberOfBytesToWrite, //, IN DWORD nNumberOfBytesPerSend,
     125//    IN LPOVERLAPPED lpOverlapped,
     126//    IN LPTRANSMIT_FILE_BUFFERS lpTransmitBuffers,
     127//    IN DWORD dwReserved)
     128//{
     129//    return FALSE;
     130//}
     131
     132
     133/*****************************************************************************
     134 * Prototypes                                                                *
     135 *****************************************************************************/
     136
     137void _System AsyncLoop             (ULONG);
     138void         CheckThreads          (AsyncStatus *);
     139void         NotifyApp             (int,AsyncStatus *);
     140int          Notify                (AsyncStatus *,int);
     141int          NotifyWSA             (HWND hw,u_int msg,UINT wp,LONG lp);
     142void _System WSAFunct              (ULONG); // for the wsa database calls
     143void         SetErrForDatabaseCalls(void);
     144
     145
     146/*****************************************************************************
     147 * Local variables                                                           *
     148 *****************************************************************************/
    58149
    59150static WHOSTENT whsnt;
    60151static WSERVENT wsvnt;
    61152static WPROTOENT wptnt;
    62 
    63  /*+-------------------------------------------------------------------+*/
    64  /*| _CRT_init is the C run-time environment initialization function.  |*/
    65  /*|It will return 0 to indicate success and -1 to indicate failure.   |*/
    66  /*+-------------------------------------------------------------------+*/
    67  
    68 int _CRT_init (void);
    69  
    70  /*+-------------------------------------------------------------------+*/
    71  /*| _CRT_term is the C run-time environment termination function.     |*/
    72  /*+-------------------------------------------------------------------+*/
    73  
    74 void _CRT_term (unsigned long);
    75 
    76 void _System AsyncLoop(ULONG);
    77 void CheckThreads(AsyncStatus *);
    78 void NotifyApp(int,AsyncStatus *);
    79 int Notify(AsyncStatus *,int);
    80 
    81 int NotifyWSA(HWND hw,u_int msg,UINT wp,LONG lp);
    82 
    83 void _System WSAFunct(ULONG); // for the wsa database calls
    84 void SetErrForDatabaseCalls(void);
    85 
    86 
    87153size_t nSize;
    88154int *pArray;
     
    91157int LocalErrorNumber = 0;
    92158
    93 
    94159TID tidAsyncLoop = 0;     /* ID of AsyncSelect (AsyncLoop) thread */
    95160
     161PipeStruct PS;
     162
     163AsyncStatus *TopASY = 0;
     164
     165
    96166/*
    97 
    98  
    99167typedef struct AsyncStatus {
    100168    HWND hwnd;     // owner's hwindow
     
    108176    struct AsyncStatus *Prev; // pointer to previous AsyncStatus in the list
    109177} AsyncStatus;
    110  
    111  
    112  
    113178*/
    114179
    115 AsyncStatus *TopASY = 0;
    116 
    117 
    118 #define BLOCKING 0
    119 #define NONBLOCKING 1
    120 
    121 
    122 
    123 typedef struct WSAStruct {
    124     int CallingWhat;
    125     HWND hw;
    126     u_int msg;
    127     char *carg1;
    128     char *carg2;
    129     int iarg1;
    130     int iarg2;
    131     char *buf;
    132     int buflen;
    133 } WSAStruct;
    134 
    135 
    136 #define GETSERVBYNAME    1
    137 #define GETSERVBYPORT    2
    138 #define GETPROTOBYNAME   3
    139 #define GETPROTOBYNUMBER 4
    140 #define GETHOSTBYNAME    5
    141 #define GETHOSTBYADDR    6
    142 
    143 
    144 
    145 
    146 typedef struct PipeStruct {
    147     AsyncStatus as;
    148     int MsgLoop;
    149     HFILE rcv;
    150     HFILE snd;
    151 } PipeStruct;
    152 
    153 PipeStruct PS;
    154 
    155 
    156 
    157 #ifdef FD_CLR
    158 #undef FD_CLR
    159 #define FD_CLR(x,y) WFD_CLR(x,y)
    160 #undef FD_SET
    161 #define FD_SET(x,y) WFD_SET(x,y)
    162 #undef FD_ZERO
    163 #define FD_ZERO(x) WFD_ZERO(x)
    164 #undef FD_ISSET
    165 #define FD_ISSET(x,y) WFD_SET(x,y)
     180
     181/*****************************************************************************
     182 * Name      :
     183 * Purpose   :
     184 * Parameters:
     185 * Variables :
     186 * Result    :
     187 * Remark    :
     188 * Status    : UNTESTED STUB
     189 *
     190 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     191 *****************************************************************************/
     192
     193void _System AsyncLoop(ULONG ASP)
     194{
     195  int socks[1],r,w,e,rc,ii;
     196  AsyncStatus *as;
     197
     198  as = (AsyncStatus *)ASP;
     199
     200  r = w = e = 0;
     201  if(as->event & FD_READ) r = 1;
     202  if(as->event & FD_WRITE) w = 1;
     203  if(as->event & FD_OOB) e = 1;
     204
     205  socks[0] = (int)as->socket;
     206
     207  if((r+w+e) == 0)
     208  {
     209    dprintf(("WSOCK32: Turning off async\n"));
     210
     211    ii = 0;
     212    rc = ioctl(socks[0],FIONBIO,(char *)&ii,sizeof(ii));
     213    as->threadID = 0;
     214    as->hwnd = 0;
     215    as->msg = 0;
     216    as->event = 0;
     217    as->status = BLOCKING;
     218    return;
     219  } // end if
     220  else
     221  {
     222    dprintf(("WSOCK32: Setting up non-blocking sockets\n"));
     223    ii = 1;
     224    rc = ioctl(socks[0],FIONBIO,(char *)&ii,sizeof(ii));
     225    if(rc != 0)
     226    {
     227      dprintf(("WSOCK32: ioctl failed trying to non-block.\n"));
     228      return;
     229    }
     230    as->status = NONBLOCKING;
     231  } // end else
     232
     233  do
     234  {
     235    rc = select(socks[0],(fd_set*)&r,0,0,0); // ioctl may be better for this.
     236    if(rc > 0)
     237    {
     238      rc = ioctl(socks[0],FIONREAD,(char *)&ii,sizeof(ii));
     239      if(rc == 0 && ii > 0)
     240      {
     241        /* data is ready */
     242        NotifyApp(FD_READ,as);
     243      }
     244    }
     245
     246    if(rc < 0)
     247    {
     248      rc = sock_errno();
     249      /* something ain't right */
     250      if(rc == 10038)
     251      { // Connection closed
     252        NotifyApp(FD_CLOSE,as);
     253        DosSleep(500);
     254        return;
     255      }
     256
     257      dprintf(("WSOCK32: Select error: %d\n",
     258               rc));
     259    } // end if
     260    DosSleep(50);
     261  }
     262  while(1);
     263}
     264
     265
     266/*****************************************************************************
     267 * Name      :
     268 * Purpose   :
     269 * Parameters:
     270 * Variables :
     271 * Result    :
     272 * Remark    :
     273 * Status    : UNTESTED STUB
     274 *
     275 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     276 *****************************************************************************/
     277
     278void CheckThreads(AsyncStatus *as)
     279{
     280  AsyncStatus *asy;
     281
     282  if(as != NULL)
     283    if(as->threadID != 0) DosKillThread(as->threadID);
     284
     285  for(asy = TopASY; asy; asy = asy->Next)
     286    if(asy->threadID != 0)
     287      DosKillThread(asy->threadID);
     288}
     289
     290
     291/*****************************************************************************
     292 * Name      :
     293 * Purpose   :
     294 * Parameters:
     295 * Variables :
     296 * Result    :
     297 * Remark    :
     298 * Status    : UNTESTED STUB
     299 *
     300 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     301 *****************************************************************************/
     302
     303void NotifyApp(int xx,AsyncStatus *as)
     304{
     305  BOOL    fResult;        /* message-posted indicator             */
     306  unsigned long ii;
     307
     308
     309//#ifdef DEBUG
     310//    WriteLog("WSOCK32: Notifying the caller.  rc = %d\n",xx);
     311//#endif
     312
     313  if(as->MsgStat == 0)
     314  {
     315   fResult = Notify(as,xx);
     316   dprintf(("WSOCK32: Notify returns: %d\n",
     317            fResult));
     318  } // end if
     319
     320  if(as->MsgStat == 2)
     321    as->MsgStat = 0;
     322  else
     323    as->MsgStat = 1;
     324}
     325
     326
     327/*****************************************************************************
     328 * Name      :
     329 * Purpose   :
     330 * Parameters:
     331 * Variables :
     332 * Result    :
     333 * Remark    :
     334 * Status    : UNTESTED STUB
     335 *
     336 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     337 *****************************************************************************/
     338
     339void _System WSAFunct(ULONG xx)
     340{
     341  WSAStruct *wsa;
     342  WSERVENT *ooo;
     343  char *yy;
     344  int ii;
     345  size_t ss;
     346  UINT wp;
     347  LONG lp;
     348  int id = *_threadid;
     349
     350  wsa = (WSAStruct *)xx;
     351
     352  dprintf(("WSOCK32: WSAFunct: xx = %p, hwnd = %p\n",
     353           xx,
     354           wsa->hw));
     355
     356  dprintf(("WSOCK32: WSAFunct info carg1 = %s, carg2 = %s\n",
     357           wsa->carg1,
     358           wsa->carg2));
     359
     360  dprintf(("WSOCK32: WSAFunct info buf = %p, %d\n",
     361           wsa->buf,
     362           wsa->buflen));
     363
     364  switch (wsa->CallingWhat)
     365  {
     366    case GETSERVBYNAME:
     367      yy = (char *)OS2getservbyname(wsa->carg1,wsa->carg2);
     368      ss = sizeof(WSERVENT);
     369      break;
     370    case GETSERVBYPORT:
     371      yy = (char *)OS2getservbyport(wsa->iarg1,wsa->carg1);
     372      break;
     373    case GETPROTOBYNUMBER:
     374      yy = (char *)OS2getprotobynumber(wsa->iarg1);
     375      break;
     376    case GETPROTOBYNAME:
     377      yy = (char *)OS2getprotobyname(wsa->carg1);
     378      break;
     379    case GETHOSTBYNAME:
     380      yy = (char *)OS2gethostbyname(wsa->carg1);
     381      break;
     382    case GETHOSTBYADDR:
     383      yy = (char *)OS2gethostbyaddr(wsa->carg1,wsa->iarg1,wsa->iarg2);
     384      break;
     385    default:
     386      yy = (char *)NULL;
     387      OS2WSASetLastError(-5000);
     388      break;
     389  } // end switch
     390
     391#ifdef DEBUG
     392  if(yy)
     393  {
     394    ooo = (WSERVENT *)yy;
     395    dprintf(("WSOCK32: WSAFunct service name = %s, port = %d\n",
     396             ooo->s_name,
     397             (int)ooo->s_port));
     398  }
    166399#endif
    167400
    168 
    169 
    170 
    171 
    172 
    173 int WIN32API OS2__WSAFDIsSet(SOCKET fd, Wfd_set FAR *set)
    174 {
    175 int i = set->fd_count;
    176 
    177 #ifdef DEBUG
    178     WriteLog("WSOCK32: __WSAFDIsSet\n");
     401  wp = id;
     402
     403  if(yy == (char *)NULL)
     404  {
     405    dprintf(("WSOCK32: WSAFunct error carg1 = %s, carg2 = %s\n",
     406             wsa->carg1,
     407             wsa->carg2));
     408
     409   ii = OS2WSAGetLastError();
     410   lp = OS2WSAMAKEASYNCREPLY(0,ii);
     411  } // end if
     412  else
     413  {
     414    if(wsa->buflen < ss)
     415      ii = WSAENOBUFS;
     416    else
     417      ii = 0;
     418
     419    lp = OS2WSAMAKEASYNCREPLY(ss,ii);
     420    if(ii == 0)
     421      memmove(wsa->buf,yy,ss);
     422  }
     423
     424  do
     425  {
     426    if(WinQueryAnchorBlock(wsa->hw))
     427          ii = NotifyWSA(wsa->hw,wsa->msg,wp,lp);
     428  } while(ii != TRUE);
     429
     430  free(wsa);
     431}
     432
     433
     434/*****************************************************************************
     435 * Name      :
     436 * Purpose   :
     437 * Parameters:
     438 * Variables :
     439 * Result    :
     440 * Remark    :
     441 * Status    : UNTESTED STUB
     442 *
     443 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     444 *****************************************************************************/
     445
     446void SetErrForDatabaseCalls(void)
     447{
     448  switch(h_errno)
     449  {
     450    case 1:
     451      OS2WSASetLastError(11001); // host not found
     452      break;
     453    case 2:
     454      OS2WSASetLastError(11002); // try again later
     455      break;
     456    case 3:
     457      OS2WSASetLastError(11003); // No recovery
     458      break;
     459    case 4:
     460      OS2WSASetLastError(11004); // No address or no data
     461      break;
     462    default:
     463      OS2WSASetLastError(0); // unknown error and should never get here
     464      dprintf(("WSOCK32: Unknown error condition: %d\n",
     465               h_errno));
     466      break;
     467  }
     468}
     469
     470
     471/*****************************************************************************
     472 * Name      :
     473 * Purpose   :
     474 * Parameters:
     475 * Variables :
     476 * Result    :
     477 * Remark    :
     478 * Status    : UNTESTED STUB
     479 *
     480 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     481 *****************************************************************************/
     482
     483AsyncStatus * FindASY(SOCKET s)
     484{
     485  AsyncStatus *as;
     486
     487  for(as = TopASY; as; as = as->Next)
     488    if(as->socket == s)
     489      return as;
     490
     491  return 0;
     492}
     493
     494
     495/*****************************************************************************
     496 * Name      :
     497 * Purpose   :
     498 * Parameters:
     499 * Variables :
     500 * Result    :
     501 * Remark    :
     502 * Status    : UNTESTED STUB
     503 *
     504 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     505 *****************************************************************************/
     506
     507ODINFUNCTION2(int, OS2__WSAFDIsSet, SOCKET,       fd,
     508                                    Wfd_set FAR*, set)
     509{
     510  int i = set->fd_count;
     511
     512  while (i--)
     513    if (set->fd_array[i] == fd)
     514      return 1;
     515
     516  return 0;
     517}
     518
     519
     520/*****************************************************************************
     521 * Name      :
     522 * Purpose   :
     523 * Parameters:
     524 * Variables :
     525 * Result    :
     526 * Remark    :
     527 * Status    : UNTESTED STUB
     528 *
     529 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     530 *****************************************************************************/
     531
     532ODINFUNCTION3(SOCKET,OS2accept,SOCKET,    s,
     533                               PSOCKADDR, addr,
     534                               int*,      addrlen)
     535{
     536  return accept(s,addr,addrlen);
     537}
     538
     539
     540/*****************************************************************************
     541 * Name      :
     542 * Purpose   :
     543 * Parameters:
     544 * Variables :
     545 * Result    :
     546 * Remark    :
     547 * Status    : UNTESTED STUB
     548 *
     549 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     550 *****************************************************************************/
     551
     552ODINFUNCTION3(int,OS2bind,SOCKET,          s,
     553                          const struct sockaddr *, addr,
     554                          int,             namelen)
     555{
     556  return bind(s,(PSOCKADDR)addr,namelen);
     557}
     558
     559
     560/*****************************************************************************
     561 * Name      :
     562 * Purpose   :
     563 * Parameters:
     564 * Variables :
     565 * Result    :
     566 * Remark    :
     567 * Status    : UNTESTED STUB
     568 *
     569 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     570 *****************************************************************************/
     571
     572ODINFUNCTION1(int,OS2closesocket,SOCKET,s)
     573{
     574  AsyncStatus *as;
     575
     576  as = FindASY(s);
     577  if(as == NULL)
     578  {
     579    LocalErrorNumber = 10038;
     580    return -1;
     581  }
     582
     583  CheckThreads(as);
     584
     585  if(as->Prev && as->Next)
     586    as->Prev->Prev = as->Next->Next; // I SURE HOPE THIS IS RIGHT!!!!!!!!
     587
     588  free(as);
     589
     590  return soclose((int)s);
     591}
     592
     593
     594/*****************************************************************************
     595 * Name      :
     596 * Purpose   :
     597 * Parameters:
     598 * Variables :
     599 * Result    :
     600 * Remark    :
     601 * Status    : UNTESTED STUB
     602 *
     603 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     604 *****************************************************************************/
     605
     606ODINFUNCTION3(int,OS2connect,SOCKET,          s,
     607                             const struct sockaddr*, name,
     608                             int,             namelen)
     609{
     610  return connect(s,
     611                 (PSOCKADDR)name,
     612                 namelen);
     613}
     614
     615
     616/*****************************************************************************
     617 * Name      :
     618 * Purpose   :
     619 * Parameters:
     620 * Variables :
     621 * Result    :
     622 * Remark    :
     623 * Status    : UNTESTED STUB
     624 *
     625 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     626 *****************************************************************************/
     627
     628ODINFUNCTION3(int,OS2ioctlsocket,SOCKET,  s,
     629                                 long,    cmd,
     630                                 u_long*, argp)
     631{
     632  return ioctl(s, cmd, (char *)argp, 4);
     633}
     634
     635
     636/*****************************************************************************
     637 * Name      :
     638 * Purpose   :
     639 * Parameters:
     640 * Variables :
     641 * Result    :
     642 * Remark    :
     643 * Status    : UNTESTED STUB
     644 *
     645 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     646 *****************************************************************************/
     647
     648ODINFUNCTION3(int,OS2getpeername,SOCKET,   s,
     649                                 PSOCKADDR,name,
     650                                 int*,     namelen)
     651{
     652  return getpeername(s,name,namelen);
     653}
     654
     655
     656/*****************************************************************************
     657 * Name      :
     658 * Purpose   :
     659 * Parameters:
     660 * Variables :
     661 * Result    :
     662 * Remark    :
     663 * Status    : UNTESTED STUB
     664 *
     665 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     666 *****************************************************************************/
     667
     668ODINFUNCTION3(int,OS2getsockname,SOCKET,   s,
     669                                 PSOCKADDR,name,
     670                                 int*,     namelen)
     671{
     672  return getsockname(s,name,namelen);
     673}
     674
     675
     676/*****************************************************************************
     677 * Name      :
     678 * Purpose   :
     679 * Parameters:
     680 * Variables :
     681 * Result    :
     682 * Remark    :
     683 * Status    : UNTESTED STUB
     684 *
     685 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     686 *****************************************************************************/
     687
     688ODINFUNCTION5(int,OS2getsockopt,SOCKET,s,
     689                                int,   level,
     690                                int,   optname,
     691                                char*, optval,
     692                                int*,  optlen)
     693{
     694  return getsockopt(s,level,optname,optval,optlen);
     695}
     696
     697
     698/*****************************************************************************
     699 * Name      :
     700 * Purpose   :
     701 * Parameters:
     702 * Variables :
     703 * Result    :
     704 * Remark    :
     705 * Status    : UNTESTED STUB
     706 *
     707 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     708 *****************************************************************************/
     709
     710ODINFUNCTION1(u_long,OS2htonl,u_long,hostlong)
     711{
     712  return htonl(hostlong);
     713}
     714
     715
     716/*****************************************************************************
     717 * Name      :
     718 * Purpose   :
     719 * Parameters:
     720 * Variables :
     721 * Result    :
     722 * Remark    :
     723 * Status    : UNTESTED STUB
     724 *
     725 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     726 *****************************************************************************/
     727
     728ODINFUNCTION1(u_short,OS2htons,u_short,hostshort)
     729{
     730  return htons(hostshort);
     731}
     732
     733
     734/*****************************************************************************
     735 * Name      :
     736 * Purpose   :
     737 * Parameters:
     738 * Variables :
     739 * Result    :
     740 * Remark    :
     741 * Status    : UNTESTED STUB
     742 *
     743 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     744 *****************************************************************************/
     745
     746ODINFUNCTION1(u_long,OS2inet_addr,const char*, cp)
     747{
     748  return inet_addr((char *)cp);
     749}
     750
     751
     752/*****************************************************************************
     753 * Name      :
     754 * Purpose   :
     755 * Parameters:
     756 * Variables :
     757 * Result    :
     758 * Remark    :
     759 * Status    : UNTESTED STUB
     760 *
     761 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     762 *****************************************************************************/
     763
     764ODINFUNCTION1(char*,OS2inet_ntoa,struct in_addr,in)
     765{
     766  return inet_ntoa(in);
     767}
     768
     769
     770/*****************************************************************************
     771 * Name      :
     772 * Purpose   :
     773 * Parameters:
     774 * Variables :
     775 * Result    :
     776 * Remark    :
     777 * Status    : UNTESTED STUB
     778 *
     779 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     780 *****************************************************************************/
     781
     782ODINFUNCTION2(int,OS2listen,SOCKET,s,
     783                            int,   backlog)
     784{
     785  return listen(s,backlog);
     786}
     787
     788
     789/*****************************************************************************
     790 * Name      :
     791 * Purpose   :
     792 * Parameters:
     793 * Variables :
     794 * Result    :
     795 * Remark    :
     796 * Status    : UNTESTED STUB
     797 *
     798 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     799 *****************************************************************************/
     800
     801ODINFUNCTION1(u_long,OS2ntohl,u_long,netlong)
     802{
     803  return ntohl(netlong);
     804}
     805
     806
     807/*****************************************************************************
     808 * Name      :
     809 * Purpose   :
     810 * Parameters:
     811 * Variables :
     812 * Result    :
     813 * Remark    :
     814 * Status    : UNTESTED STUB
     815 *
     816 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     817 *****************************************************************************/
     818
     819ODINFUNCTION1(u_short,OS2ntohs,u_short,netshort)
     820{
     821  return ntohs(netshort);
     822}
     823
     824
     825/*****************************************************************************
     826 * Name      :
     827 * Purpose   :
     828 * Parameters:
     829 * Variables :
     830 * Result    :
     831 * Remark    :
     832 * Status    : UNTESTED STUB
     833 *
     834 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     835 *****************************************************************************/
     836
     837ODINFUNCTION4(int,OS2recv,SOCKET,s,
     838                          char*, buf,
     839                          int,   len,
     840                          int,   flags)
     841{
     842  unsigned long ii;
     843  int           xx,
     844                yy;
     845  char          buff[200];
     846  AsyncStatus   *as;
     847
     848  PS.MsgLoop = 0;
     849
     850  as = FindASY(s);
     851
     852  if(as != NULL)
     853    as->MsgStat = 2;
     854
     855  xx = recv(s,buf,len,flags);
     856
     857  return xx;
     858}
     859
     860
     861/*****************************************************************************
     862 * Name      :
     863 * Purpose   :
     864 * Parameters:
     865 * Variables :
     866 * Result    :
     867 * Remark    :
     868 * Status    : UNTESTED STUB
     869 *
     870 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     871 *****************************************************************************/
     872
     873ODINFUNCTION6(int,OS2recvfrom,SOCKET,    s,
     874                              char*,     buf,
     875                              int,       len,
     876                              int,       flags,
     877                              PSOCKADDR, from,
     878                              int*,      fromlen)
     879{
     880  return recvfrom(s,buf,len,flags,from,fromlen);
     881}
     882
     883
     884/*****************************************************************************
     885 * Name      :
     886 * Purpose   :
     887 * Parameters:
     888 * Variables :
     889 * Result    :
     890 * Remark    :
     891 * Status    : UNTESTED STUB
     892 *
     893 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     894 *****************************************************************************/
     895
     896#ifdef VV_BSD_SELECT
     897
     898ODINFUNCTION5(int,OS2select,int,      nfds,
     899                            Wfd_set*, readfds,
     900                            Wfd_set*, writefds,
     901                            Wfd_set*, exceptfds,
     902                            const struct Wtimeval*, timeout)
     903{
     904  return select(nfds,
     905                (fd_set *)readfds,
     906                (fd_set *)writefds,
     907                (fd_set *)exceptfds,
     908                (timeval *)timeout);
     909}
     910
     911#else
     912#  error OS/2-style select not implemented!
    179913#endif
    180  
    181      while (i--)
    182          if (set->fd_array[i] == fd)
    183              return 1;
    184  
    185 return 0;
    186 }
    187 
    188 
    189 
    190 AsyncStatus * FindASY(SOCKET s)
    191 {
    192 AsyncStatus *as;
    193 
    194     for(as = TopASY; as; as = as->Next)
    195         if(as->socket == s)
    196             return as;
    197 
    198 return 0;
    199 }
    200 
    201 
    202 
    203 SOCKET WIN32API OS2accept (SOCKET s, struct sockaddr *addr,
    204                         int *addrlen) {
    205 #ifdef DEBUG
    206     WriteLog("WSOCK32: accept\n");
    207 #endif
    208 
    209     return accept(s,addr,addrlen);
    210 }
    211 
    212 int WIN32API OS2bind (SOCKET s, const struct sockaddr *addr, int namelen)
    213 {
    214  int rc;
    215 
    216 #ifdef DEBUG
    217     WriteLog("WSOCK32: bind\n");
    218 #endif
    219 
    220     rc = bind(s,(struct sockaddr *)addr,namelen);
    221     dprintf(("bind returned %X\n", rc));
    222     return(rc);
    223 }
    224 
    225 int WIN32API OS2closesocket (SOCKET s)
    226 {
    227 AsyncStatus *as;
    228 #ifdef DEBUG
    229     WriteLog("WSOCK32: closesocket\n");
    230 #endif
    231 
    232     as = FindASY(s);
    233     if(as == NULL) {
    234         LocalErrorNumber = 10038;
    235         return -1;
     914
     915
     916/*****************************************************************************
     917 * Name      :
     918 * Purpose   :
     919 * Parameters:
     920 * Variables :
     921 * Result    :
     922 * Remark    :
     923 * Status    : UNTESTED STUB
     924 *
     925 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     926 *****************************************************************************/
     927
     928ODINFUNCTION4(int,OS2send,SOCKET,      s,
     929                          const char*, buf,
     930                          int,         len,
     931                          int,         flags)
     932{
     933  return send(s,(char *)buf,len,flags);
     934}
     935
     936
     937/*****************************************************************************
     938 * Name      :
     939 * Purpose   :
     940 * Parameters:
     941 * Variables :
     942 * Result    :
     943 * Remark    :
     944 * Status    : UNTESTED STUB
     945 *
     946 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     947 *****************************************************************************/
     948
     949ODINFUNCTION6(int,OS2sendto,SOCKET,          s,
     950                            const char*,     buf,
     951                            int,             len,
     952                            int,             flags,
     953                            const struct sockaddr*, to,
     954                            int,             tolen)
     955{
     956  return sendto(s,(char *)buf,len,flags,(PSOCKADDR)to,tolen);
     957}
     958
     959
     960/*****************************************************************************
     961 * Name      :
     962 * Purpose   :
     963 * Parameters:
     964 * Variables :
     965 * Result    :
     966 * Remark    :
     967 * Status    : UNTESTED STUB
     968 *
     969 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     970 *****************************************************************************/
     971
     972ODINFUNCTION5(int,OS2setsockopt,SOCKET,      s,
     973                                int,         level,
     974                                int,         optname,
     975                                const char*, optval,
     976                                int,         optlen)
     977{
     978  struct Wlinger *yy;
     979  struct linger xx;
     980
     981  if(level   == SOL_SOCKET &&
     982     optname == SO_LINGER)
     983  {
     984    yy = (struct Wlinger *)optval;
     985    xx.l_onoff = (int)yy->l_onoff;
     986    xx.l_linger = (int)yy->l_linger;
     987
     988    return setsockopt(s,level,optname,(char *)&xx,optlen);
     989  }
     990  else
     991    return setsockopt(s,level,optname,(char *)optval,optlen);
     992}
     993
     994
     995/*****************************************************************************
     996 * Name      :
     997 * Purpose   :
     998 * Parameters:
     999 * Variables :
     1000 * Result    :
     1001 * Remark    :
     1002 * Status    : UNTESTED STUB
     1003 *
     1004 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     1005 *****************************************************************************/
     1006
     1007ODINFUNCTION2(int,OS2shutdown,SOCKET,s,
     1008                              int,   how)
     1009{
     1010  return shutdown(s,how);
     1011}
     1012
     1013
     1014/*****************************************************************************
     1015 * Name      :
     1016 * Purpose   :
     1017 * Parameters:
     1018 * Variables :
     1019 * Result    :
     1020 * Remark    :
     1021 * Status    : UNTESTED STUB
     1022 *
     1023 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     1024 *****************************************************************************/
     1025
     1026ODINFUNCTION3(SOCKET,OS2socket,int,af,
     1027                               int,type,
     1028                               int,protocol)
     1029{
     1030  SOCKET s;
     1031  AsyncStatus *as;
     1032
     1033  s = (SOCKET)socket(af,type,protocol);
     1034  if(s > 0)
     1035  {
     1036    as = (AsyncStatus *)malloc(sizeof(AsyncStatus));
     1037    if(as != NULL)
     1038    {
     1039      as->hwnd = (HWND)0;
     1040      as->msg = 0;
     1041      as->event = 0L;
     1042      as->socket = s;
     1043      as->status = BLOCKING;
     1044      as->threadID = 0;
     1045      as->MsgStat = 0;
     1046      as->Next = TopASY;
     1047      as->Prev = NULL;
     1048
     1049      if(TopASY)
     1050        TopASY->Prev = as;
     1051
     1052      TopASY = as;
    2361053    }
    237 
    238     CheckThreads(as);
    239 
    240 #ifdef DEBUG
    241     WriteLog("WSOCK32: closesocket\n");
    242 #endif
    243     if(as->Prev && as->Next)
    244         as->Prev->Prev = as->Next->Next; // I SURE HOPE THIS IS RIGHT!!!!!!!!
    245     free(as);
    246    
    247     return soclose((int)s);
    248 }
    249 
    250 int WIN32API OS2connect (SOCKET s, const struct sockaddr *name, int namelen)
    251 {
    252 #ifdef DEBUG
    253 //char message[512];
    254 //struct Wsockaddr_in *xname;
    255 
    256   WriteLog("WSOCK32: connect\n");
    257 
    258 
    259 #endif
    260 
    261     return connect(s,(struct sockaddr *)name,namelen);
    262 }
    263 
    264 int WIN32API OS2ioctlsocket (SOCKET s, long cmd, u_long *argp)
    265 {
    266  int rc;
    267 
    268 #ifdef DEBUG
    269     WriteLog("WSOCK32: ioctlsocket unimplemented\n");
    270 #endif
    271 
    272     rc = ioctl(s, cmd, (char *)argp, 4);
    273     dprintf(("ioctl returned %X\n", rc));
    274     return(rc);
    275 }
    276 
    277 int WIN32API OS2getpeername (SOCKET s, struct sockaddr *name,
    278                           int * namelen)
    279 {
    280 #ifdef DEBUG
    281     WriteLog("WSOCK32: getpeername\n");
    282 #endif
    283 
    284     return getpeername(s,name,namelen);
    285 }
    286 
    287 int WIN32API OS2getsockname (SOCKET s, struct sockaddr *name,
    288                           int * namelen)
    289 {
    290 #ifdef DEBUG
    291     WriteLog("WSOCK32: getsockname\n");
    292 #endif
    293 
    294     return getsockname(s,name,namelen);
    295 }
    296 
    297 int WIN32API OS2getsockopt (SOCKET s, int level, int optname,
    298                          char * optval, int *optlen)
    299 {
    300 #ifdef DEBUG
    301     WriteLog("WSOCK32: getsockopt\n");
    302 #endif
    303 
    304     return getsockopt(s,level,optname,optval,optlen);
    305 }
    306 
    307 u_long WIN32API OS2htonl (u_long hostlong)
    308 {
    309 #ifdef DEBUG
    310     WriteLog("WSOCK32: htonl\n");
    311 #endif
    312 
    313     return htonl(hostlong);
    314 }
    315 
    316 u_short WIN32API OS2htons (u_short hostshort)
    317 {
    318 #ifdef DEBUG
    319     WriteLog("WSOCK32: htons\n");
    320 #endif
    321 
    322     return htons(hostshort);
    323 }
    324 
    325 unsigned long WIN32API OS2inet_addr (const char * cp)
    326 {
    327 #ifdef DEBUG
    328     WriteLog("WSOCK32: inet_addr\n");
    329 #endif
    330 
    331     return inet_addr((char *)cp);
    332 }
    333 
    334 char * WIN32API OS2inet_ntoa (struct in_addr in)
    335 {
    336 #ifdef DEBUG
    337     WriteLog("WSOCK32: inet_ntoa\n");
    338 #endif
    339 
    340     return inet_ntoa(in);
    341 }
    342 
    343 int WIN32API OS2listen (SOCKET s, int backlog)
    344 {
    345 #ifdef DEBUG
    346     WriteLog("WSOCK32: listen\n");
    347 #endif
    348 
    349     return listen(s,backlog);
    350 }
    351 
    352 u_long WIN32API OS2ntohl (u_long netlong)
    353 {
    354 #ifdef DEBUG
    355     WriteLog("WSOCK32: ntohl\n");
    356 #endif
    357 
    358     return ntohl(netlong);
    359 }
    360 
    361 u_short WIN32API OS2ntohs (u_short netshort)
    362 {
    363 #ifdef DEBUG
    364     WriteLog("WSOCK32: ntohs\n");
    365 #endif
    366 
    367     return ntohs(netshort);
    368 }
    369 
    370 int WIN32API OS2recv (SOCKET s, char * buf, int len, int flags)
    371 {
    372 unsigned long ii;
    373 int xx,yy;
    374 char buff[200];
    375 AsyncStatus *as;
    376 #ifdef DEBUG
    377     WriteLog("WSOCK32: recv socket: %u\n",(unsigned int)s);
    378     WriteLog("WSOCK32: recv len: %d\n",len);
    379     WriteLog("WSOCK32: recv flags: %d\n",flags);
    380 
    381 #endif
    382 
    383     PS.MsgLoop = 0;
    384 
    385     as = FindASY(s);
    386 
    387     if(as != NULL) as->MsgStat = 2;
    388 
    389    
    390     xx = recv(s,buf,len,flags);
    391 
    392 return xx;
    393 }
    394 
    395 
    396 
    397 int WIN32API OS2recvfrom (SOCKET s, char * buf, int len, int flags,
    398                        struct sockaddr *from, int * fromlen)
    399 {
    400  int rc;
    401 
    402 #ifdef DEBUG
    403     WriteLog("WSOCK32: recvfrom\n");
    404 #endif
    405 
    406     rc = recvfrom(s,buf,len,flags,from,fromlen);
    407     dprintf(("recvfrom returned %X\n", rc));
    408     return(rc);
    409 }
    410 
    411 
    412 
    413 #ifdef VV_BSD_SELECT
    414 
    415 
    416 int WIN32API OS2select (int nfds, Wfd_set *readfds, Wfd_set *writefds,
    417                      Wfd_set *exceptfds, const struct Wtimeval *timeout)
    418 {
    419 #ifdef DEBUG
    420     WriteLog("WSOCK32: select\n");
    421 #endif
    422 
    423 
    424     return select(nfds,(fd_set *)readfds,(fd_set *)writefds,(fd_set *)exceptfds,(timeval *)timeout);
    425    
    426 }
    427 
    428 
    429 
    430 #else
    431 
    432 
    433 int WIN32API OS2select (int nfds, Wfd_set *readfds, Wfd_set *writefds,
    434                      Wfd_set *exceptfds, const struct Wtimeval *timeout)
    435 {
    436 #ifdef DEBUG
    437     WriteLog("WSOCK32: select\n");
    438 #endif
    439 
    440     // NEED TO DO THIS ONE!!!!!
    441    
    442     return 0;
    443 }
    444 #endif
    445 
    446 
    447 
    448 int WIN32API OS2send (SOCKET s, const char * buf, int len, int flags)
    449 {
    450 #ifdef DEBUG
    451     WriteLog("WSOCK32: send socket: %u\n",(unsigned int)s);
    452 //    WriteLog("WSOCK32: send buf: %s\n",buf);
    453     WriteLog("WSOCK32: send len: %d\n",len);
    454     WriteLog("WSOCK32: send flags: %d\n",flags);
    455 #endif
    456 
    457     return send(s,(char *)buf,len,flags);
    458 }
    459 
    460 int WIN32API OS2sendto (SOCKET s, const char * buf, int len, int flags,
    461                      const struct sockaddr *to, int tolen)
    462 {
    463  int rc;
    464 
    465 #ifdef DEBUG
    466     WriteLog("WSOCK32: sendto\n");
    467 #endif
    468 
    469     rc = sendto(s,(char *)buf,len,flags,(struct sockaddr *)to,tolen);
    470     dprintf(("sendto returned %X\n", rc));
    471     return(rc);
    472 }
    473 
    474 int WIN32API OS2setsockopt (SOCKET s, int level, int optname,
    475                          const char * optval, int optlen)
    476 {
    477 struct Wlinger *yy;
    478 struct linger xx;
    479 
    480 #ifdef DEBUG
    481     WriteLog("WSOCK32: setsockopt\n");
    482 #endif
    483 
    484     if(level == SOL_SOCKET && optname == SO_LINGER) {
    485         yy = (struct Wlinger *)optval;
    486         xx.l_onoff = (int)yy->l_onoff;
    487         xx.l_linger = (int)yy->l_linger;
    488 
    489         return setsockopt(s,level,optname,(char *)&xx,optlen);
    490     }
    491 
    492     else return setsockopt(s,level,optname,(char *)optval,optlen);
    493 
    494 }
    495 
    496 int WIN32API OS2shutdown (SOCKET s, int how)
    497 {
    498 #ifdef DEBUG
    499     WriteLog("WSOCK32: shutdown\n");
    500 #endif
    501 
    502     return shutdown(s,how);
    503 }
    504 
    505 SOCKET WIN32API OS2socket (int af, int type, int protocol)
    506 {
    507 SOCKET s;
    508 AsyncStatus *as;
    509 #ifdef DEBUG
    510     WriteLog("WSOCK32: socket\n");
    511 #endif
    512 
    513     s = (SOCKET)socket(af,type,protocol);
    514 
    515     if(s > 0) {
    516         as = (AsyncStatus *)malloc(sizeof(AsyncStatus));
    517         if(as != NULL) {
    518            as->hwnd = (HWND)0;
    519            as->msg = 0;
    520            as->event = 0L;
    521            as->socket = s;
    522            as->status = BLOCKING;
    523            as->threadID = 0;
    524            as->MsgStat = 0;
    525            as->Next = TopASY;
    526            as->Prev = NULL;
    527            if(TopASY) TopASY->Prev = as;
    528            TopASY = as;
    529         } else {
    530             soclose(s);
    531             return -1;
    532         }
     1054    else
     1055    {
     1056      soclose(s);
     1057      return -1;
    5331058    }
    534     dprintf(("WSOCK32: socket returned %X\n", s));
    535 
    536 return s;
    537 }
    538 
    539 /* Database function prototypes */
    540 
    541 
    542 void SetErrForDatabaseCalls(void)
    543 {
    544 
    545     switch(h_errno) {
    546         case 1:
    547             OS2WSASetLastError(11001); // host not found
    548             break;
    549         case 2:
    550             OS2WSASetLastError(11002); // try again later
    551             break;
    552         case 3:
    553             OS2WSASetLastError(11003); // No recovery
    554             break;
    555         case 4:
    556             OS2WSASetLastError(11004); // No address or no data
    557             break;
    558         default:
    559             OS2WSASetLastError(0); // unknown error and should never get here
    560 #ifdef DEBUG
    561 WriteLog("WSOCK32: Unknown error condition: %d\n",h_errno);
    562 #endif
    563             break;
    564     }
    565 
    566 return;
    567 }
    568 
    569 
    570 
    571 
    572 WHOSTENT * WIN32API OS2gethostbyaddr(const char * addr,
    573                                         int len, int type)
    574 {
    575 WHOSTENT *yy;
    576 struct hostent *xx;
    577 #ifdef DEBUG
    578     WriteLog("WSOCK32: gethostbyaddr\n");
    579 #endif
    580 
    581     xx = gethostbyaddr((char *)addr,len,type);
    582 
    583     if(xx == NULL) {
    584         SetErrForDatabaseCalls();
    585         return (WHOSTENT *)NULL;
    586     }
    587 
    588     whsnt.h_name = xx->h_name;
    589     whsnt.h_aliases = xx->h_aliases;
    590     whsnt.h_addrtype = (short)xx->h_addrtype;
    591     whsnt.h_length = (short)xx->h_length;
    592     whsnt.h_addr_list = xx->h_addr_list;
    593 
    594 return &whsnt;
    595 }
    596 
    597 
    598 
    599 
    600 WHOSTENT * WIN32API OS2gethostbyname(const char * name)
    601 {
    602 WHOSTENT *yy;
    603 struct hostent *xx;
    604 #ifdef DEBUG
    605     WriteLog("WSOCK32: gethostbyname: %s\n",name);
    606 #endif
    607 
    608     xx = gethostbyname((char *)name);
    609 
    610     if(xx == NULL) {
    611         SetErrForDatabaseCalls();
    612         return (WHOSTENT *)NULL;
    613     }
    614 
    615     whsnt.h_name = xx->h_name;
    616     whsnt.h_aliases = xx->h_aliases;
    617     whsnt.h_addrtype = (short)xx->h_addrtype;
    618     whsnt.h_length = (short)xx->h_length;
    619     whsnt.h_addr_list = xx->h_addr_list;
    620  
    621 return &whsnt;   
    622 }
    623 
    624 
    625 
    626 
    627 
    628 
    629 int WIN32API _OS2gethostname (char * name, int namelen)
    630 {
    631 #ifdef DEBUG
    632     WriteLog("WSOCK32: _gethostname\n");
    633 #endif
    634 
    635     return gethostname(name,namelen);
    636 }
    637 
    638 
    639 
    640 int WIN32API OS2gethostname (char * name, int namelen)
    641 {
    642 #ifdef DEBUG
    643     WriteLog("WSOCK32: gethostname\n");
    644 #endif
    645 
    646     return gethostname(name,namelen);
    647 }
    648 
    649 WSERVENT * WIN32API OS2getservbyport(int port, const char * proto)
    650 {
    651 struct servent *xx;
    652 #ifdef DEBUG
    653     WriteLog("WSOCK32: getservbyport\n");
    654 #endif
    655 
    656     xx = getservbyport(port,(char *)proto);
    657 
    658     if(xx == NULL) { // this call doesn't generate an error message
    659         return (WSERVENT *)NULL;
    660     }
    661 
    662     wsvnt.s_name = xx->s_name;
    663     wsvnt.s_aliases = xx->s_aliases;
    664     wsvnt.s_port = (short)xx->s_port;
    665     wsvnt.s_proto = xx->s_proto;
    666 
    667 return &wsvnt;
    668 }
    669 
    670 WSERVENT * WIN32API OS2getservbyname(const char * name,
    671                                         const char * proto)
    672 {
    673 WSERVENT *yy;
    674 struct servent *xx;
    675 #ifdef DEBUG
    676     WriteLog("WSOCK32: getservbyname\n");
    677 #endif
    678 
    679     xx = getservbyname((char *)name,(char *)proto);
    680 
    681     if(xx == NULL) { // this call doesn't generate an error message
    682       return (WSERVENT *)NULL;
    683     }
    684 
    685     wsvnt.s_name = xx->s_name;
    686     wsvnt.s_aliases = xx->s_aliases;
    687     wsvnt.s_port = (short)xx->s_port;
    688     wsvnt.s_proto = xx->s_proto;
    689 
    690 return &wsvnt;
    691 }
    692 
    693 WPROTOENT * WIN32API OS2getprotobynumber(int proto)
    694 {
    695 struct protoent *xx;
    696 #ifdef DEBUG
    697     WriteLog("WSOCK32: getprotobynumber\n");
    698 #endif
    699 
    700     xx = getprotobynumber(proto);
    701 
    702     if(xx == NULL) { // this call doesn't generate an error message
    703         return (WPROTOENT *)NULL;
    704     }
    705 
    706     wptnt.p_name = xx->p_name;
    707     wptnt.p_aliases = xx->p_aliases;
    708     wptnt.p_proto = (short)xx->p_proto;
    709 
    710 return &wptnt;
    711 }
    712 
    713 WPROTOENT * WIN32API OS2getprotobyname(const char * name)
    714 {
    715 struct protoent *xx;
    716 #ifdef DEBUG
    717     WriteLog("WSOCK32: getprotobyname\n");
    718 #endif
    719 
    720     xx = getprotobyname((char *)name);
    721 
    722     if(xx == NULL) { // this call doesn't generate an error message
    723         return (WPROTOENT *)NULL;
    724     }
    725 
    726     wptnt.p_name = xx->p_name;
    727     wptnt.p_aliases = xx->p_aliases;
    728     wptnt.p_proto = (short)xx->p_proto;
    729 
    730 return &wptnt;
    731 }
    732 
    733 
    734 
    735 
    736 int WIN32API OS2WSAStartup(USHORT wVersionRequired, LPWSADATA lpWsaData)
    737 {
    738 APIRET rc;
    739 int ii;
    740 #ifdef DEBUG
    741     WriteLog("WSOCK32: WSAStartup\n");
    742 #endif
     1059  }
     1060
     1061  return s;
     1062}
     1063
     1064
     1065/*****************************************************************************
     1066 * Name      :
     1067 * Purpose   :
     1068 * Parameters:
     1069 * Variables :
     1070 * Result    :
     1071 * Remark    :
     1072 * Status    : UNTESTED STUB
     1073 *
     1074 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     1075 *****************************************************************************/
     1076
     1077ODINFUNCTION3(WHOSTENT*,OS2gethostbyaddr,const char*, addr,
     1078                                         int,         len,
     1079                                         int,         type)
     1080{
     1081  WHOSTENT *yy;
     1082  struct hostent *xx;
     1083
     1084  xx = gethostbyaddr((char *)addr,len,type);
     1085
     1086  if(xx == NULL)
     1087  {
     1088     SetErrForDatabaseCalls();
     1089     return (WHOSTENT *)NULL;
     1090  }
     1091
     1092  whsnt.h_name = xx->h_name;
     1093  whsnt.h_aliases = xx->h_aliases;
     1094  whsnt.h_addrtype = (short)xx->h_addrtype;
     1095  whsnt.h_length = (short)xx->h_length;
     1096  whsnt.h_addr_list = xx->h_addr_list;
     1097
     1098  return &whsnt;
     1099}
     1100
     1101
     1102/*****************************************************************************
     1103 * Name      :
     1104 * Purpose   :
     1105 * Parameters:
     1106 * Variables :
     1107 * Result    :
     1108 * Remark    :
     1109 * Status    : UNTESTED STUB
     1110 *
     1111 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     1112 *****************************************************************************/
     1113
     1114ODINFUNCTION1(WHOSTENT*,OS2gethostbyname,const char*,name)
     1115{
     1116  WHOSTENT *yy;
     1117  struct hostent *xx;
     1118
     1119  xx = gethostbyname((char *)name);
     1120  if(xx == NULL)
     1121  {
     1122    SetErrForDatabaseCalls();
     1123    return (WHOSTENT *)NULL;
     1124  }
     1125
     1126  whsnt.h_name = xx->h_name;
     1127  whsnt.h_aliases = xx->h_aliases;
     1128  whsnt.h_addrtype = (short)xx->h_addrtype;
     1129  whsnt.h_length = (short)xx->h_length;
     1130  whsnt.h_addr_list = xx->h_addr_list;
     1131
     1132  return &whsnt;
     1133}
     1134
     1135
     1136/*****************************************************************************
     1137 * Name      :
     1138 * Purpose   :
     1139 * Parameters:
     1140 * Variables :
     1141 * Result    :
     1142 * Remark    :
     1143 * Status    : UNTESTED STUB
     1144 *
     1145 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     1146 *****************************************************************************/
     1147
     1148ODINFUNCTION2(int,OS2gethostname,char *,name,
     1149                                 int,   namelen)
     1150{
     1151  return gethostname(name,namelen);
     1152}
     1153
     1154
     1155/*****************************************************************************
     1156 * Name      :
     1157 * Purpose   :
     1158 * Parameters:
     1159 * Variables :
     1160 * Result    :
     1161 * Remark    :
     1162 * Status    : UNTESTED STUB
     1163 *
     1164 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     1165 *****************************************************************************/
     1166
     1167ODINFUNCTION2(WSERVENT*,OS2getservbyport, int,         port,
     1168                                          const char*, proto)
     1169{
     1170  struct servent *xx;
     1171
     1172  xx = getservbyport(port,(char *)proto);
     1173
     1174  if(xx == NULL)
     1175  { // this call doesn't generate an error message
     1176    return (WSERVENT *)NULL;
     1177  }
     1178
     1179  wsvnt.s_name = xx->s_name;
     1180  wsvnt.s_aliases = xx->s_aliases;
     1181  wsvnt.s_port = (short)xx->s_port;
     1182  wsvnt.s_proto = xx->s_proto;
     1183
     1184  return &wsvnt;
     1185}
     1186
     1187
     1188/*****************************************************************************
     1189 * Name      :
     1190 * Purpose   :
     1191 * Parameters:
     1192 * Variables :
     1193 * Result    :
     1194 * Remark    :
     1195 * Status    : UNTESTED STUB
     1196 *
     1197 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     1198 *****************************************************************************/
     1199
     1200ODINFUNCTION2(WSERVENT*,OS2getservbyname,const char*,name,
     1201                                         const char*,proto)
     1202{
     1203  WSERVENT *yy;
     1204  struct servent *xx;
     1205
     1206  xx = getservbyname((char *)name,(char *)proto);
     1207
     1208  if(xx == NULL)
     1209  { // this call doesn't generate an error message
     1210    return (WSERVENT *)NULL;
     1211  }
     1212
     1213  wsvnt.s_name = xx->s_name;
     1214  wsvnt.s_aliases = xx->s_aliases;
     1215  wsvnt.s_port = (short)xx->s_port;
     1216  wsvnt.s_proto = xx->s_proto;
     1217
     1218  return &wsvnt;
     1219}
     1220
     1221
     1222/*****************************************************************************
     1223 * Name      :
     1224 * Purpose   :
     1225 * Parameters:
     1226 * Variables :
     1227 * Result    :
     1228 * Remark    :
     1229 * Status    : UNTESTED STUB
     1230 *
     1231 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     1232 *****************************************************************************/
     1233
     1234ODINFUNCTION1(WPROTOENT*,OS2getprotobynumber,int,proto)
     1235{
     1236  struct protoent *xx;
     1237
     1238  xx = getprotobynumber(proto);
     1239
     1240  if(xx == NULL)
     1241  {
     1242     // this call doesn't generate an error message
     1243    return (WPROTOENT *)NULL;
     1244  }
     1245
     1246  wptnt.p_name = xx->p_name;
     1247  wptnt.p_aliases = xx->p_aliases;
     1248  wptnt.p_proto = (short)xx->p_proto;
     1249
     1250  return &wptnt;
     1251}
     1252
     1253
     1254/*****************************************************************************
     1255 * Name      :
     1256 * Purpose   :
     1257 * Parameters:
     1258 * Variables :
     1259 * Result    :
     1260 * Remark    :
     1261 * Status    : UNTESTED STUB
     1262 *
     1263 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     1264 *****************************************************************************/
     1265
     1266ODINFUNCTION1(WPROTOENT*,OS2getprotobyname,const char*,name)
     1267{
     1268  struct protoent *xx;
     1269
     1270  xx = getprotobyname((char *)name);
     1271
     1272  if(xx == NULL)
     1273  { // this call doesn't generate an error message
     1274    return (WPROTOENT *)NULL;
     1275  }
     1276
     1277  wptnt.p_name = xx->p_name;
     1278  wptnt.p_aliases = xx->p_aliases;
     1279  wptnt.p_proto = (short)xx->p_proto;
     1280
     1281  return &wptnt;
     1282}
     1283
     1284
     1285/*****************************************************************************
     1286 * Name      :
     1287 * Purpose   :
     1288 * Parameters:
     1289 * Variables :
     1290 * Result    :
     1291 * Remark    :
     1292 * Status    : UNTESTED STUB
     1293 *
     1294 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     1295 *****************************************************************************/
     1296
     1297ODINFUNCTION2(int,OS2WSAStartup,USHORT,   wVersionRequired,
     1298                                LPWSADATA,lpWsaData)
     1299{
     1300  APIRET rc;
     1301  int ii;
     1302
    7431303  /* Make sure that the version requested is >= 1.1.   */
    7441304  /* The low byte is the major version and the high    */
    7451305  /* byte is the minor version.                        */
    746  
     1306
    7471307  if ( LOBYTE( wVersionRequired ) < 1 ||
    7481308       ( LOBYTE( wVersionRequired ) == 1 &&
     
    7501310      return WSAVERNOTSUPPORTED;
    7511311  }
    752  
     1312
    7531313  /* Since we only support 1.1, set both wVersion and  */
    7541314  /* wHighVersion to 1.1.                              */
    755  
     1315
    7561316  lpWsaData->wVersion = MAKEWORD( 1, 1 );
    7571317  lpWsaData->wHighVersion = MAKEWORD( 1, 1 );
     
    7631323  LocalErrorNumber = 0;
    7641324
    765   if(sock_init() == 0) {
     1325  if(sock_init() == 0)
     1326  {
    7661327#ifdef DEBUG
    7671328    WriteLog("WSOCK32: WSAStartup sock_init returned 0\n");
     
    7691330      return 0;
    7701331  }
    771   else ii = sock_errno();
    772 #ifdef DEBUG
    773     WriteLog("WSOCK32: WSAStartup exiting: %d\n",ii);
    774 #endif
    775 return ii;
    776 }
    777 
    778 
    779 
    780 
    781 
    782 
    783 int WIN32API OS2WSACleanup(void)
    784 {
    785 #ifdef DEBUG
    786     WriteLog("WSOCK32: WSACleanup\n");
    787 #endif
    788 
    789     CheckThreads((AsyncStatus *)NULL);
    790    
    791     return 0;
    792 }
    793 
    794 void WIN32API OS2WSASetLastError(int iError)
    795 {
    796 #ifdef DEBUG
    797     WriteLog("WSOCK32: WSASetLastError(%d)\n",iError);
    798 #endif
    799 
    800     LocalErrorNumber = iError;
    801    
    802     return;
    803 }
    804 
    805 int WIN32API OS2WSAGetLastError(void)
    806 {
    807 int ii;
    808 #ifdef DEBUG
    809     WriteLog("WSOCK32: WSAGetLastError\n");
    810 #endif
    811 
    812     if(LocalErrorNumber == 0) {
    813         ii = sock_errno(); // WSAGetLastError();
    814 #ifdef DEBUG
    815     WriteLog("WSOCK32: WSAGetLastError: %d\n",ii);
    816 #endif
    817         return ii;
    818     }
    819     else {
    820 #ifdef DEBUG
    821     WriteLog("WSOCK32: WSAGetLastError: %d\n",LocalErrorNumber);
    822 #endif
    823         return LocalErrorNumber;
    824     }
    825 }
    826 
    827 BOOL WIN32API OS2WSAIsBlocking(void)
    828 {
    829 #ifdef DEBUG
    830     WriteLog("WSOCK32: WSAIsBlocking unimplemented\n");
    831 #endif
    832 
    833     return -5000; //WSAIsBlocking();
    834 }
    835 
    836 int WIN32API OS2WSAUnhookBlockingHook(void)
    837 {
    838 #ifdef DEBUG
    839     WriteLog("WSOCK32: WSAUnhookBlockingHook unimplemented\n");
    840 #endif
    841 
    842     return -5000; //WSAUnhookBlockingHook();
    843 }
    844 
    845 FARPROC WIN32API OS2WSASetBlockingHook(FARPROC lpBlockFunc)
    846 {
    847 #ifdef DEBUG
    848     WriteLog("WSOCK32: WSASetBlockingHook Unimplemented\n");
    849 #endif
    850 
    851     return (FARPROC)NULL;
    852 }
    853 
    854 int WIN32API OS2WSACancelBlockingCall(void)
    855 {
    856 #ifdef DEBUG
    857     WriteLog("WSOCK32: WSACancelBlockingCall unimplemented\n");
    858 #endif
    859 
    860     return -5000; //WSACancelBlockingCall();
    861 }
    862 
    863 
    864 
     1332  else
     1333    ii = sock_errno();
     1334
     1335  return ii;
     1336}
     1337
     1338
     1339/*****************************************************************************
     1340 * Name      :
     1341 * Purpose   :
     1342 * Parameters:
     1343 * Variables :
     1344 * Result    :
     1345 * Remark    :
     1346 * Status    : UNTESTED STUB
     1347 *
     1348 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     1349 *****************************************************************************/
     1350
     1351ODINFUNCTION0(int,OS2WSACleanup)
     1352{
     1353  CheckThreads((AsyncStatus *)NULL);
     1354
     1355  return 0;
     1356}
     1357
     1358
     1359/*****************************************************************************
     1360 * Name      :
     1361 * Purpose   :
     1362 * Parameters:
     1363 * Variables :
     1364 * Result    :
     1365 * Remark    :
     1366 * Status    : UNTESTED STUB
     1367 *
     1368 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     1369 *****************************************************************************/
     1370
     1371ODINPROCEDURE1(OS2WSASetLastError,int,iError)
     1372{
     1373  LocalErrorNumber = iError;
     1374}
     1375
     1376
     1377/*****************************************************************************
     1378 * Name      :
     1379 * Purpose   :
     1380 * Parameters:
     1381 * Variables :
     1382 * Result    :
     1383 * Remark    :
     1384 * Status    : UNTESTED STUB
     1385 *
     1386 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     1387 *****************************************************************************/
     1388
     1389ODINFUNCTION0(int,OS2WSAGetLastError)
     1390{
     1391  int ii;
     1392
     1393  if(LocalErrorNumber == 0)
     1394  {
     1395    ii = sock_errno(); // WSAGetLastError();
     1396    return ii;
     1397  }
     1398  else
     1399  {
     1400    return LocalErrorNumber;
     1401  }
     1402}
     1403
     1404
     1405/*****************************************************************************
     1406 * Name      :
     1407 * Purpose   :
     1408 * Parameters:
     1409 * Variables :
     1410 * Result    :
     1411 * Remark    :
     1412 * Status    : UNTESTED STUB
     1413 *
     1414 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     1415 *****************************************************************************/
     1416
     1417ODINFUNCTION0(BOOL,OS2WSAIsBlocking)
     1418{
     1419  dprintf(("WSOCK32: WSAIsBlocking unimplemented\n"));
     1420
     1421  return -5000; //WSAIsBlocking();
     1422}
     1423
     1424
     1425/*****************************************************************************
     1426 * Name      :
     1427 * Purpose   :
     1428 * Parameters:
     1429 * Variables :
     1430 * Result    :
     1431 * Remark    :
     1432 * Status    : UNTESTED STUB
     1433 *
     1434 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     1435 *****************************************************************************/
     1436
     1437ODINFUNCTION0(int,OS2WSAUnhookBlockingHook)
     1438{
     1439  dprintf(("WSOCK32: WSAUnhookBlockingHook unimplemented\n"));
     1440
     1441  return -5000; //WSAUnhookBlockingHook();
     1442}
     1443
     1444
     1445/*****************************************************************************
     1446 * Name      :
     1447 * Purpose   :
     1448 * Parameters:
     1449 * Variables :
     1450 * Result    :
     1451 * Remark    :
     1452 * Status    : UNTESTED STUB
     1453 *
     1454 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     1455 *****************************************************************************/
     1456
     1457ODINFUNCTION1(PROC,OS2WSASetBlockingHook,PROC,lpBlockFund)
     1458{
     1459  dprintf(("WSOCK32: WSASetBlockingHook Unimplemented\n"));
     1460  return (PROC)NULL;
     1461}
     1462
     1463
     1464/*****************************************************************************
     1465 * Name      :
     1466 * Purpose   :
     1467 * Parameters:
     1468 * Variables :
     1469 * Result    :
     1470 * Remark    :
     1471 * Status    : UNTESTED STUB
     1472 *
     1473 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     1474 *****************************************************************************/
     1475
     1476ODINFUNCTION0(int,OS2WSACancelBlockingCall)
     1477{
     1478  dprintf(("WSOCK32: WSACancelBlockingCall unimplemented\n"));
     1479
     1480  return -5000; //WSACancelBlockingCall();
     1481}
    8651482
    8661483
     
    8691486// notify the sender.
    8701487
    871 
    872 LHANDLE WIN32API OS2WSAAsyncGetServByName(HWND hWnd, u_int wMsg,
    873                                         const char * name,
    874                                         const char * proto,
    875                                         char * buf, int buflen)
    876 {
    877 WSAStruct *wsa;
    878 PFNTHREAD   pfnAsyncThread = &WSAFunct; /* Address of thread program   */
    879 ULONG       ulThreadParm = 100;          /* Parameter to thread routine     */
    880 APIRET      rc           = NO_ERROR;     /* Return code */
    881 TID         tid;
    882 
    883 
    884 OS2WSASetLastError(WSAEWOULDBLOCK);
    885 return 0;
    886 
    887 #ifdef DEBUG
    888 WriteLog("WSOCK32: WSAAsyncGetServByName.  name: %s, proto: %s \n",name,proto);
    889 #endif
    890 
    891     wsa = (WSAStruct *)malloc(sizeof(WSAStruct));
    892     if(wsa == NULL) {
    893         OS2WSASetLastError(WSAEWOULDBLOCK);
    894         return 0;
    895     }
    896 
    897     wsa->CallingWhat = GETSERVBYNAME;
    898     wsa->hw = hWnd;
    899     wsa->msg = wMsg;
    900     wsa->carg1 = strdup(name);
    901     wsa->carg2 = strdup(proto);
    902     wsa->buf = buf;
    903     wsa->buflen = buflen;
    904 
    905     ulThreadParm = (ULONG)wsa;
    906    
    907     rc = DosCreateThread(&tid,           /* Thread ID (returned by function)  */
    908                          pfnAsyncThread, /* Address of thread program         */
    909                          ulThreadParm,   /* Parameter passed to ThreadProc    */
    910                          CREATE_READY |  /* Thread is ready when created      */
    911                          STACK_SPARSE,   /* Do not pre-commit stack pages     */
    912                          8192L);         /* Stack size, rounded to page bdy   */
    913     if (rc != NO_ERROR) {
    914 #ifdef DEBUG
    915         WriteLog("WSOCK32: DosCreateThread error in WSAAsyncGetServByName: return code = %u\n", rc);
    916 #endif
    917         OS2WSASetLastError(rc);
    918         free(wsa);
    919         return 0;
    920     }
    921 
    922 #ifdef DEBUG
    923     WriteLog("WSOCK32 THREAD: DosCreateThread's tid: %lu, ThreadParm = %p\n",(unsigned long)tid,ulThreadParm);
    924     WriteLog("WSOCK32 THREAD: hwnd: %p\n",wsa->hw);
    925 #endif
    926 
    927     return (LHANDLE)tid; //WSAAsyncGetServByName(hWnd,wMsg,name,proto,buf,buflen);
    928 }
    929 
    930 LHANDLE WIN32API OS2WSAAsyncGetServByPort(HWND hWnd, u_int wMsg, int port,
    931                                         const char * proto, char * buf,
    932                                         int buflen)
    933 {
    934 #ifdef DEBUG
    935     WriteLog("WSOCK32: WSAAsyncGetServByPort unimplemented\n");
    936 #endif
    937 
    938     return -5000; //WSAAsyncGetServByPort(hWnd,wMsg,port,proto,buf,buflen);
    939 }
    940 
    941 LHANDLE WIN32API OS2WSAAsyncGetProtoByName(HWND hWnd, u_int wMsg,
    942                                          const char * name, char * buf,
    943                                          int buflen)
    944 {
    945 #ifdef DEBUG
    946     WriteLog("WSOCK32: WSAAsyncGetProtoByName unimplemented\n");
    947 #endif
    948 
    949     return -5000; //WSAAsyncGetProtoByName(hWnd,wMsg,name,buf,buflen);
    950 }
    951 
    952 LHANDLE WIN32API OS2WSAAsyncGetProtoByNumber(HWND hWnd, u_int wMsg,
    953                                            int number, char * buf,
    954                                            int buflen)
    955 {
    956 #ifdef DEBUG
    957     WriteLog("WSOCK32: WSAAsyncGetProtoByNumber unimplemented\n");
    958 #endif
    959 
    960     return -5000; //WSAAsyncGetProtoByNumber(hWnd,wMsg,number,buf,buflen);
    961 }
    962 
    963 LHANDLE WIN32API OS2WSAAsyncGetHostByName(HWND hWnd, u_int wMsg,
    964                                         const char * name, char * buf,
    965                                         int buflen)
    966 {
    967 #ifdef DEBUG
    968     WriteLog("WSOCK32: WSAAsyncGetHostByName unimplemented\n");
    969 #endif
    970 
    971     return -5000; //WSAAsyncGetHostByName(hWnd,wMsg,name,buf,buflen);
    972 }
    973 
    974 LHANDLE WIN32API OS2WSAAsyncGetHostByAddr(HWND hWnd, u_int wMsg,
    975                                         const char * addr, int len, int type,
    976                                         char * buf, int buflen)
    977 {
    978 #ifdef DEBUG
    979     WriteLog("WSOCK32: WSAAsyncGetHostByAddr unimplemented\n");
    980 #endif
    981 
    982 
    983 
    984 
    985    
    986     return -5000; //WSAAsyncGetHostByAddr(hWnd,wMsg,addr,len,type,buf,buflen);
    987 }
    988 
    989 
    990 
    991 
    992 
    993 
    994 
    995 int WIN32API OS2WSACancelAsyncRequest(LHANDLE hAsyncTaskHandle)
    996 {
    997 TID tid;
    998 APIRET rc;
    999 #ifdef DEBUG
    1000     WriteLog("WSOCK32: WSACancelAsyncRequest unimplemented\n");
    1001 #endif
    1002 
    1003     rc = 0;
    1004    
    1005     tid = (LHANDLE)hAsyncTaskHandle;
    1006 
    1007     if(tid == 0) rc = WSAEINVAL;
    1008 
    1009     if(!rc) rc = DosKillThread(tid);
    1010 
    1011     switch(rc) {
    1012         case 0: // SUCCESS!!
    1013             return 0;
    1014         case 170:
    1015             rc = WSAEINPROGRESS;
    1016             break;
    1017         case 309:
    1018             rc = WSAEINVAL;
    1019             break;
    1020         default:
    1021             rc = -5000;
    1022             break;
    1023     } // end switch
    1024 
     1488/*****************************************************************************
     1489 * Name      :
     1490 * Purpose   :
     1491 * Parameters:
     1492 * Variables :
     1493 * Result    :
     1494 * Remark    :
     1495 * Status    : UNTESTED STUB
     1496 *
     1497 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     1498 *****************************************************************************/
     1499
     1500ODINFUNCTION6(LHANDLE,OS2WSAAsyncGetServByName,HWND,        hWnd,
     1501                                               u_int,       wMsg,
     1502                                               const char*, name,
     1503                                               const char*, proto,
     1504                                               char*,       buf,
     1505                                               int,         buflen)
     1506{
     1507  WSAStruct *wsa;
     1508  PFNTHREAD   pfnAsyncThread = &WSAFunct; /* Address of thread program   */
     1509  ULONG       ulThreadParm = 100;          /* Parameter to thread routine     */
     1510  APIRET      rc           = NO_ERROR;     /* Return code */
     1511  TID         tid;
     1512
     1513
     1514  OS2WSASetLastError(WSAEWOULDBLOCK);
     1515  return 0;
     1516
     1517  dprintf(("WSOCK32: WSAAsyncGetServByName.  name: %s, proto: %s \n",
     1518           name,
     1519           proto));
     1520
     1521  wsa = (WSAStruct *)malloc(sizeof(WSAStruct));
     1522  if(wsa == NULL)
     1523  {
     1524    OS2WSASetLastError(WSAEWOULDBLOCK);
     1525    return 0;
     1526  }
     1527
     1528  wsa->CallingWhat = GETSERVBYNAME;
     1529  wsa->hw = hWnd;
     1530  wsa->msg = wMsg;
     1531  wsa->carg1 = strdup(name);
     1532  wsa->carg2 = strdup(proto);
     1533  wsa->buf = buf;
     1534  wsa->buflen = buflen;
     1535
     1536  ulThreadParm = (ULONG)wsa;
     1537
     1538  rc = DosCreateThread(&tid,           /* Thread ID (returned by function)  */
     1539                       pfnAsyncThread, /* Address of thread program         */
     1540                       ulThreadParm,   /* Parameter passed to ThreadProc    */
     1541                       CREATE_READY |  /* Thread is ready when created      */
     1542                       STACK_SPARSE,   /* Do not pre-commit stack pages     */
     1543                       8192L);         /* Stack size, rounded to page bdy   */
     1544  if (rc != NO_ERROR)
     1545  {
     1546    dprintf(("WSOCK32: DosCreateThread error in WSAAsyncGetServByName: return code = %u\n",
     1547            rc));
    10251548    OS2WSASetLastError(rc);
    1026     return SOCKET_ERROR; // ERROR!
    1027 }
    1028 
    1029 
    1030 
    1031 
    1032 
    1033 int WIN32API OS2WSAAsyncSelect(SOCKET s, HWND hWnd, u_int wMsg,
    1034                             long lEvent)
    1035 {
    1036 PFNTHREAD   pfnAsyncThread = &AsyncLoop; /* Address of thread program   */
    1037 ULONG       ulThreadParm = 100;          /* Parameter to thread routine     */
    1038 APIRET      rc           = NO_ERROR;     /* Return code                     */
    1039 unsigned long ii;
    1040 AsyncStatus *as;
    1041 #ifdef DEBUG
    1042 char buf[150];
    1043 sprintf(buf,"WSOCK32: WSAAsyncSelect\n         Message: %x\n         Event: %ld\n         hwindow: %x\n",
    1044         wMsg,lEvent,(HWND)hWnd);
    1045     WriteLog(buf);
    1046 #endif
    1047 
    1048     as = FindASY(s);
    1049 
    1050     if(as == NULL) return 0;
    1051    
    1052     CheckThreads(as);
    1053 
    1054     as->hwnd = hWnd;
    1055     as->msg = wMsg;
    1056     as->event = lEvent;
    1057 
    1058     ulThreadParm = (ULONG)as;
    1059    
    1060     rc = DosCreateThread(&(as->threadID),  /* Thread ID (returned by function)  */
    1061                          pfnAsyncThread, /* Address of thread program         */
    1062                          ulThreadParm,   /* Parameter passed to ThreadProc    */
    1063                          CREATE_READY |  /* Thread is ready when created      */
    1064                          STACK_SPARSE,   /* Do not pre-commit stack pages     */
    1065                          8192L);         /* Stack size, rounded to page bdy   */
    1066     if (rc != NO_ERROR) {
    1067 #ifdef DEBUG
    1068         WriteLog("WSOCK32: DosCreateThread error: return code = %u\n", rc);
    1069 #endif
    1070         OS2WSASetLastError(rc);
    1071         return 0;
    1072     }
    1073 
    1074     return 1; //WSAAsyncSelect(s,hWnd,wMsg,lEvent);
    1075 }
    1076 
    1077 
    1078 
    1079 void _System AsyncLoop(ULONG ASP)
    1080 {
    1081 int socks[1],r,w,e,rc,ii;
    1082 AsyncStatus *as;
    1083 
    1084     as = (AsyncStatus *)ASP;
    1085 
    1086     r = w = e = 0;
    1087     if(as->event & FD_READ) r = 1;
    1088     if(as->event & FD_WRITE) w = 1;
    1089     if(as->event & FD_OOB) e = 1;
    1090 
    1091     socks[0] = (int)as->socket;
    1092 
    1093     if((r+w+e) == 0) {
    1094 #ifdef DEBUG
    1095         WriteLog("WSOCK32: Turning off async\n");
    1096 #endif
    1097         ii = 0;
    1098         rc = ioctl(socks[0],FIONBIO,(char *)&ii,sizeof(ii));
    1099         as->threadID = 0;
    1100         as->hwnd = 0;
    1101         as->msg = 0;
    1102         as->event = 0;
    1103         as->status = BLOCKING;
    1104         return;
    1105     } // end if
    1106     else
    1107     {
    1108 #ifdef DEBUG
    1109         WriteLog("WSOCK32: Setting up non-blocking sockets\n");
    1110 #endif
    1111         ii = 1;
    1112         rc = ioctl(socks[0],FIONBIO,(char *)&ii,sizeof(ii));
    1113         if(rc != 0) {
    1114 #ifdef DEBUG
    1115             WriteLog("WSOCK32: ioctl failed trying to non-block.\n");
    1116 #endif
    1117             return;
    1118         }
    1119         as->status = NONBLOCKING;
    1120     } // end else
    1121 
    1122     do {
    1123         rc = select(socks[0],(fd_set*)&r,0,0,0); // ioctl may be better for this.
    1124         if(rc > 0) {
    1125             rc = ioctl(socks[0],FIONREAD,(char *)&ii,sizeof(ii));
    1126             if(rc == 0 && ii > 0) {
    1127             /* data is ready */
    1128                 NotifyApp(FD_READ,as);
    1129 //#ifdef DEBUG
    1130 //                WriteLog("WSOCK32: Data Waiting\n");
    1131 //#endif
    1132             }
    1133         }
    1134         if(rc < 0) {
    1135             rc = sock_errno();
    1136             /* something ain't right */
    1137             if(rc == 10038) { // Connection closed
    1138                 NotifyApp(FD_CLOSE,as);
    1139                 DosSleep(500);
    1140                 return;
    1141             }
    1142 #ifdef DEBUG
    1143             WriteLog("WSOCK32: Select error: %d\n",rc);
    1144 #endif
    1145         } // end if
    1146         DosSleep(50);
    1147     } while(1);
    1148 
    1149 return;
    1150 }
    1151 
    1152 
    1153 
    1154 void CheckThreads(AsyncStatus *as)
    1155 {
    1156 AsyncStatus *asy;
    1157 
    1158     if(as != NULL)
    1159         if(as->threadID != 0) DosKillThread(as->threadID);
    1160 
    1161     for(asy = TopASY; asy; asy = asy->Next)
    1162         if(asy->threadID != 0) DosKillThread(asy->threadID);
    1163    
    1164 return;
    1165 }
    1166 
    1167 
    1168 
    1169 void NotifyApp(int xx,AsyncStatus *as)
    1170 {
    1171     BOOL    fResult;        /* message-posted indicator             */
    1172     unsigned long ii;
    1173 
    1174 
    1175 //#ifdef DEBUG
    1176 //    WriteLog("WSOCK32: Notifying the caller.  rc = %d\n",xx);
    1177 //#endif
    1178 
    1179     if(as->MsgStat == 0) {
    1180         fResult = Notify(as,xx);
    1181 #ifdef DEBUG
    1182     WriteLog("WSOCK32: Notify returns: %d\n",fResult);
    1183 #endif
    1184     } // end if
    1185 
    1186     if(as->MsgStat == 2) as->MsgStat = 0;
    1187     else as->MsgStat = 1;
    1188 
    1189 return;
    1190 }
    1191 
    1192 
    1193 
    1194 void _System WSAFunct(ULONG xx)
    1195 {
    1196 WSAStruct *wsa;
    1197 WSERVENT *ooo;
    1198 char *yy;
    1199 int ii;
    1200 size_t ss;
    1201 UINT wp;
    1202 LONG lp;
    1203 int id = *_threadid;
    1204 
    1205     wsa = (WSAStruct *)xx;
    1206 
    1207 #ifdef DEBUG
    1208     WriteLog("WSOCK32: WSAFunct: xx = %p, hwnd = %p\n",xx,wsa->hw);
    1209     WriteLog("WSOCK32: WSAFunct info carg1 = %s, carg2 = %s\n",wsa->carg1,wsa->carg2);
    1210     WriteLog("WSOCK32: WSAFunct info buf = %p, %d\n",wsa->buf,wsa->buflen);
    1211 #endif
    1212 
    1213     switch (wsa->CallingWhat) {
    1214         case GETSERVBYNAME:
    1215             yy = (char *)OS2getservbyname(wsa->carg1,wsa->carg2);
    1216             ss = sizeof(WSERVENT);
    1217             break;
    1218         case GETSERVBYPORT:
    1219             yy = (char *)OS2getservbyport(wsa->iarg1,wsa->carg1);
    1220             break;
    1221         case GETPROTOBYNUMBER:
    1222             yy = (char *)OS2getprotobynumber(wsa->iarg1);
    1223             break;
    1224         case GETPROTOBYNAME:
    1225             yy = (char *)OS2getprotobyname(wsa->carg1);
    1226             break;
    1227         case GETHOSTBYNAME:
    1228             yy = (char *)OS2gethostbyname(wsa->carg1);
    1229             break;
    1230         case GETHOSTBYADDR:
    1231             yy = (char *)OS2gethostbyaddr(wsa->carg1,wsa->iarg1,wsa->iarg2);
    1232             break;
    1233         default:
    1234             yy = (char *)NULL;
    1235             OS2WSASetLastError(-5000);
    1236             break;
    1237     } // end switch
    1238 
    1239 #ifdef DEBUG
    1240     WriteLog("WSOCK32: THREAD id = %lu\n",(unsigned long)id);
    1241     if(yy) {
    1242         ooo = (WSERVENT *)yy;
    1243         WriteLog("WSOCK32: WSAFunct service name = %s\n",ooo->s_name);
    1244         WriteLog("WSOCK32: WSAFunct service port = %d\n",(int)ooo->s_port);
    1245     }
    1246 #endif
    1247 
    1248     wp = id;
    1249 
    1250     if(yy == (char *)NULL) {
    1251 #ifdef DEBUG
    1252         WriteLog("WSOCK32: WSAFunct error\n");
    1253         WriteLog("WSOCK32: WSAFunct error carg1 = %s, carg2 = %s\n",wsa->carg1,wsa->carg2);
    1254 #endif
    1255         ii = OS2WSAGetLastError();
    1256         lp = OS2WSAMAKEASYNCREPLY(0,ii);
    1257     } // end if
    1258 
    1259     else {
    1260         if(wsa->buflen < ss) ii = WSAENOBUFS;
    1261         else ii = 0;
    1262         lp = OS2WSAMAKEASYNCREPLY(ss,ii);
    1263         if(ii == 0) memmove(wsa->buf,yy,ss);
    1264     }
    1265 
    1266 #ifdef DEBUG
    1267 #endif
    1268 
    1269    
    1270     do {
    1271         if(WinQueryAnchorBlock(wsa->hw))
    1272             ii = NotifyWSA(wsa->hw,wsa->msg,wp,lp);
    1273     } while(ii != TRUE);
    1274 
    12751549    free(wsa);
    1276 
    1277 return;
    1278 }
    1279 
    1280 
    1281 
    1282    
    1283 
    1284 int WIN32API OS2WSARecvEx (SOCKET s, char FAR * buf, int len, int FAR *flags)
    1285 {
    1286 #ifdef DEBUG
    1287     WriteLog("WSOCK32: WSARecvEx not implemented.\n");
    1288 #endif
     1550    return 0;
     1551  }
     1552
     1553  dprintf(("WSOCK32 THREAD: DosCreateThread's tid: %lu, ThreadParm = %p\n",
     1554           (unsigned long)tid,
     1555           ulThreadParm));
     1556  dprintf(("WSOCK32 THREAD: hwnd: %p\n",wsa->hw));
     1557
     1558  return (LHANDLE)tid; //WSAAsyncGetServByName(hWnd,wMsg,name,proto,buf,buflen);
     1559}
     1560
     1561
     1562/*****************************************************************************
     1563 * Name      :
     1564 * Purpose   :
     1565 * Parameters:
     1566 * Variables :
     1567 * Result    :
     1568 * Remark    :
     1569 * Status    : UNTESTED STUB
     1570 *
     1571 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     1572 *****************************************************************************/
     1573
     1574ODINFUNCTION6(LHANDLE,OS2WSAAsyncGetServByPort,HWND,        hWnd,
     1575                                               u_int,       wMsg,
     1576                                               int,         port,
     1577                                               const char*, proto,
     1578                                               char*,       buf,
     1579                                               int,         buflen)
     1580{
     1581  dprintf(("WSOCK32: WSAAsyncGetServByPort unimplemented\n"));
     1582
     1583  return -5000; //WSAAsyncGetServByPort(hWnd,wMsg,port,proto,buf,buflen);
     1584}
     1585
     1586
     1587/*****************************************************************************
     1588 * Name      :
     1589 * Purpose   :
     1590 * Parameters:
     1591 * Variables :
     1592 * Result    :
     1593 * Remark    :
     1594 * Status    : UNTESTED STUB
     1595 *
     1596 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     1597 *****************************************************************************/
     1598
     1599ODINFUNCTION5(LHANDLE,OS2WSAAsyncGetProtoByName,HWND,        hWnd,
     1600                                                u_int,       wMsg,
     1601                                                const char*, name,
     1602                                                char *,      buf,
     1603                                                int,         buflen)
     1604{
     1605  dprintf(("WSOCK32: WSAAsyncGetProtoByName unimplemented\n"));
     1606  return -5000; //WSAAsyncGetProtoByName(hWnd,wMsg,name,buf,buflen);
     1607}
     1608
     1609
     1610/*****************************************************************************
     1611 * Name      :
     1612 * Purpose   :
     1613 * Parameters:
     1614 * Variables :
     1615 * Result    :
     1616 * Remark    :
     1617 * Status    : UNTESTED STUB
     1618 *
     1619 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     1620 *****************************************************************************/
     1621
     1622ODINFUNCTION5(LHANDLE,OS2WSAAsyncGetProtoByNumber,HWND,   hWnd,
     1623                                                  u_int,  wMsg,
     1624                                                  int,    number,
     1625                                                  char *, buf,
     1626                                                  int,    buflen)
     1627{
     1628  dprintf(("WSOCK32: WSAAsyncGetProtoByNumber unimplemented\n"));
     1629  return -5000; //WSAAsyncGetProtoByNumber(hWnd,wMsg,number,buf,buflen);
     1630}
     1631
     1632
     1633/*****************************************************************************
     1634 * Name      :
     1635 * Purpose   :
     1636 * Parameters:
     1637 * Variables :
     1638 * Result    :
     1639 * Remark    :
     1640 * Status    : UNTESTED STUB
     1641 *
     1642 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     1643 *****************************************************************************/
     1644
     1645ODINFUNCTION5(LHANDLE,OS2WSAAsyncGetHostByName,HWND,         hWnd,
     1646                                               u_int,        wMsg,
     1647                                               const char *, name,
     1648                                               char *,       buf,
     1649                                               int,          buflen)
     1650{
     1651  dprintf(("WSOCK32: WSAAsyncGetHostByName unimplemented\n"));
     1652  return -5000; //WSAAsyncGetHostByName(hWnd,wMsg,name,buf,buflen);
     1653}
     1654
     1655
     1656/*****************************************************************************
     1657 * Name      :
     1658 * Purpose   :
     1659 * Parameters:
     1660 * Variables :
     1661 * Result    :
     1662 * Remark    :
     1663 * Status    : UNTESTED STUB
     1664 *
     1665 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     1666 *****************************************************************************/
     1667
     1668ODINFUNCTION7(LHANDLE, OS2WSAAsyncGetHostByAddr, HWND,        hWnd,
     1669                                                 u_int,       wMsg,
     1670                                                 const char*, addr,
     1671                                                 int,         len,
     1672                                                 int,         type,
     1673                                                 char*,       buf,
     1674                                                 int,         buflen)
     1675{
     1676  dprintf(("WSOCK32: WSAAsyncGetHostByAddr unimplemented\n"));
     1677
     1678  return -5000; //WSAAsyncGetHostByAddr(hWnd,wMsg,addr,len,type,buf,buflen);
     1679}
     1680
     1681
     1682/*****************************************************************************
     1683 * Name      :
     1684 * Purpose   :
     1685 * Parameters:
     1686 * Variables :
     1687 * Result    :
     1688 * Remark    :
     1689 * Status    : UNTESTED STUB
     1690 *
     1691 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     1692 *****************************************************************************/
     1693
     1694ODINFUNCTION1(int, OS2WSACancelAsyncRequest,LHANDLE,hAsyncTaskHandle)
     1695{
     1696  TID    tid;
     1697  APIRET rc;
     1698
     1699  dprintf(("WSOCK32: WSACancelAsyncRequest unimplemented\n"));
     1700
     1701  tid = (LHANDLE)hAsyncTaskHandle;
     1702  if(tid == 0)
     1703    rc = WSAEINVAL;
     1704  else
     1705    rc = DosKillThread(tid);
     1706
     1707  switch(rc)
     1708  {
     1709    case 0: // SUCCESS!!
     1710      return 0;
     1711    case 170:
     1712      rc = WSAEINPROGRESS;
     1713      break;
     1714    case 309:
     1715      rc = WSAEINVAL;
     1716      break;
     1717    default:
     1718      rc = -5000;
     1719      break;
     1720  } // end switch
     1721
     1722  OS2WSASetLastError(rc);
     1723  return SOCKET_ERROR; // ERROR!
     1724}
     1725
     1726
     1727/*****************************************************************************
     1728 * Name      :
     1729 * Purpose   :
     1730 * Parameters:
     1731 * Variables :
     1732 * Result    :
     1733 * Remark    :
     1734 * Status    : UNTESTED STUB
     1735 *
     1736 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     1737 *****************************************************************************/
     1738
     1739ODINFUNCTION4(int, OS2WSAAsyncSelect, SOCKET, s,
     1740                                      HWND,   hWnd,
     1741                                      u_int,  wMsg,
     1742                                      long,   lEvent)
     1743{
     1744  PFNTHREAD   pfnAsyncThread = &AsyncLoop; /* Address of thread program   */
     1745  ULONG       ulThreadParm = 100;          /* Parameter to thread routine     */
     1746  APIRET      rc           = NO_ERROR;     /* Return code                     */
     1747  unsigned long ii;
     1748  AsyncStatus *as;
     1749
     1750  as = FindASY(s);
     1751  if(as == NULL)
     1752    return 0;
     1753
     1754  CheckThreads(as);
     1755
     1756  as->hwnd = hWnd;
     1757  as->msg = wMsg;
     1758  as->event = lEvent;
     1759
     1760  ulThreadParm = (ULONG)as;
     1761
     1762  rc = DosCreateThread(&(as->threadID),  /* Thread ID (returned by function)  */
     1763                       pfnAsyncThread, /* Address of thread program         */
     1764                       ulThreadParm,   /* Parameter passed to ThreadProc    */
     1765                       CREATE_READY |  /* Thread is ready when created      */
     1766                       STACK_SPARSE,   /* Do not pre-commit stack pages     */
     1767                       8192L);         /* Stack size, rounded to page bdy   */
     1768  if (rc != NO_ERROR)
     1769  {
     1770    dprintf(("WSOCK32: DosCreateThread error: return code = %u\n",
     1771             rc));
     1772    OS2WSASetLastError(rc);
     1773    return 0;
     1774  }
     1775
     1776  return 1; //WSAAsyncSelect(s,hWnd,wMsg,lEvent);
     1777}
     1778
     1779
     1780/*****************************************************************************
     1781 * Name      :
     1782 * Purpose   :
     1783 * Parameters:
     1784 * Variables :
     1785 * Result    :
     1786 * Remark    :
     1787 * Status    : UNTESTED STUB
     1788 *
     1789 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     1790 *****************************************************************************/
     1791
     1792ODINFUNCTION4(int, OS2WSARecvEx, SOCKET,    s,
     1793                                 char FAR*, buf,
     1794                                 int,       len,
     1795                                 int FAR *,flags)
     1796{
     1797  dprintf(("WSOCK32: WSARecvEx not implemented.\n"));
    12891798
    12901799//    return WSARecvEx(s,buf,len,flags);
    1291     return 0;
    1292 }
    1293 
    1294 void WIN32API OS2s_perror(char *pszMessage,
    1295                           void *pUnknown)
     1800  return 0;
     1801}
     1802
     1803
     1804/*****************************************************************************
     1805 * Name      :
     1806 * Purpose   :
     1807 * Parameters:
     1808 * Variables :
     1809 * Result    :
     1810 * Remark    :
     1811 * Status    : UNTESTED STUB
     1812 *
     1813 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     1814 *****************************************************************************/
     1815
     1816ODINPROCEDURE2(OS2s_perror, char*, pszMessage,
     1817                            void*, pUnknown)
    12961818{
    12971819  perror(pszMessage);
     
    12991821
    13001822
    1301 //typedef struct _TRANSMIT_FILE_BUFFERS {
    1302 //    PVOID Head;
    1303 //    DWORD HeadLength;
    1304 //    PVOID Tail;
    1305 //    DWORD TailLength;
    1306 //} TRANSMIT_FILE_BUFFERS, *PTRANSMIT_FILE_BUFFERS, *LPTRANSMIT_FILE_BUFFERS;
    1307 //
    1308 //BOOL WIN32API OS2TransmitFile (
    1309 //    IN SOCKET hSocket,
    1310 //    IN HANDLE hFile,
    1311 //    IN DWORD nNumberOfBytesToWrite,
    1312 //    IN DWORD nNumberOfBytesPerSend,
    1313 //    IN LPOVERLAPPED lpOverlapped,
    1314 //    IN LPTRANSMIT_FILE_BUFFERS lpTransmitBuffers,
    1315 //    IN DWORD dwReserved)
    1316 //{
    1317 //    return FALSE;
    1318 //}
    1319 
    1320 
    1321 
    1322 
    1323 
    1324 
    1325 
    1326 
    1327 
    1328 
    1329 
Note: See TracChangeset for help on using the changeset viewer.