source: trunk/src/wsock32/new/wsock32.cpp@ 1951

Last change on this file since 1951 was 1951, checked in by phaller, 26 years ago

Fix: more asynchronous functions supported

File size: 36.6 KB
Line 
1/* $Id: wsock32.cpp,v 1.11 1999-12-02 21:35:29 phaller Exp $ */
2
3/*
4 *
5 * Project Odin Software License can be found in LICENSE.TXT
6 *
7 * Win32 SOCK32 for OS/2
8 *
9 * Copyright (C) 1999 Patrick Haller <phaller@gmx.net>
10 *
11 */
12
13/* Remark:
14 * 1999/11/21 experimental rewrite using IBM's PMWSock only
15 * -> some structural differences remain! (hostent)
16 * 1999/12/01 experimental rewrite works (TELNET)
17 * -> open issue: WSASetLastError / WSAGetLastError
18 * call SetLastError / GetLastError according to docs
19 *
20 * identical structures:
21 * - sockaddr_in
22 * - WSADATA
23 * - sockaddr
24 * - fd_set
25 * - timeval
26 *
27 * incompatible structures:
28 * - hostent
29 * - netent
30 * - servent
31 * - protent
32 * - linger
33 */
34
35
36/*****************************************************************************
37 * Includes *
38 *****************************************************************************/
39
40#include <pmwsock.h>
41#include <odin.h>
42#include <odinwrap.h>
43#include <os2sel.h>
44#include <misc.h>
45#include <wprocess.h>
46#include <heapstring.h>
47#include <win32wnd.h>
48
49#include "wsock32.h"
50#include "relaywin.h"
51
52
53ODINDEBUGCHANNEL(WSOCK32-WSOCK32)
54
55
56/*****************************************************************************
57 * Local variables *
58 *****************************************************************************/
59
60#define ERROR_SUCCESS 0
61
62
63static WSOCKTHREADDATA wstdFallthru; // for emergency only
64
65static HWND hwndRelay = NULL; // handle to our relay window
66
67
68/*****************************************************************************
69 * Name :
70 * Purpose :
71 * Parameters:
72 * Variables :
73 * Result :
74 * Remark : free memory when thread dies
75 * Status : UNTESTED STUB
76 *
77 * Author : Patrick Haller [Tue, 1998/06/16 23:00]
78 *****************************************************************************/
79
80PWSOCKTHREADDATA iQueryWsockThreadData(void)
81{
82 struct _THDB* pThreadDB = (struct _THDB*)GetThreadTHDB();
83 PWSOCKTHREADDATA pwstd;
84
85 // check for existing pointer
86 if (pThreadDB != NULL)
87 {
88 if (pThreadDB->pWsockData == NULL)
89 {
90 // allocate on demand + initialize
91 pwstd = (PWSOCKTHREADDATA)HEAP_malloc (sizeof(WSOCKTHREADDATA));
92 pThreadDB->pWsockData = (LPVOID)pwstd;
93 }
94 else
95 // use already allocated memory
96 pwstd = (PWSOCKTHREADDATA)pThreadDB->pWsockData;
97 }
98
99 if (pwstd == NULL)
100 pwstd = &wstdFallthru; // no memory and not allocated already
101
102 return pwstd;
103}
104
105
106#if 0
107/*****************************************************************************
108 * Name :
109 * Purpose :
110 * Parameters:
111 * Variables :
112 * Result :
113 * Remark :
114 * Status : UNTESTED STUB
115 *
116 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
117 *****************************************************************************/
118
119#define CASEERR2(a) case SOC##a: case a: return WSA##a;
120#define CASEERR1(a) case SOC##a: return WSA##a;
121
122int iTranslateSockErrToWSock(int iError)
123{
124 switch(iError)
125 {
126 CASEERR2(EINTR)
127 CASEERR2(EBADF)
128 CASEERR2(EACCES)
129 CASEERR2(EINVAL)
130 CASEERR2(EMFILE)
131
132 CASEERR1(EWOULDBLOCK)
133 CASEERR1(EINPROGRESS)
134 CASEERR1(EALREADY)
135 CASEERR1(ENOTSOCK)
136// CASEERR1(EDESTADRREQ)
137 CASEERR1(EMSGSIZE)
138 CASEERR1(EPROTOTYPE)
139 CASEERR1(ENOPROTOOPT)
140 CASEERR1(EPROTONOSUPPORT)
141 CASEERR1(ESOCKTNOSUPPORT)
142 CASEERR1(EOPNOTSUPP)
143 CASEERR1(EPFNOSUPPORT)
144 CASEERR1(EAFNOSUPPORT)
145 CASEERR1(EADDRINUSE)
146 CASEERR1(EADDRNOTAVAIL)
147 CASEERR1(ENETDOWN)
148 CASEERR1(ENETUNREACH)
149 CASEERR1(ENETRESET)
150 CASEERR1(ECONNABORTED)
151 CASEERR1(ECONNRESET)
152 CASEERR1(ENOBUFS)
153 CASEERR1(EISCONN)
154 CASEERR1(ENOTCONN)
155 CASEERR1(ESHUTDOWN)
156 CASEERR1(ETOOMANYREFS)
157 CASEERR1(ETIMEDOUT)
158 CASEERR1(ECONNREFUSED)
159 CASEERR1(ELOOP)
160 CASEERR1(ENAMETOOLONG)
161 CASEERR1(EHOSTDOWN)
162 CASEERR1(EHOSTUNREACH)
163
164 CASEERR1(ENOTEMPTY)
165// CASEERR(EPROCLIM)
166// CASEERR(EUSERS)
167// CASEERR(EDQUOT)
168// CASEERR(ESTALE)
169// CASEERR(EREMOTE)
170// CASEERR(EDISCON)
171
172
173 default:
174 dprintf(("WSOCK32: Unknown error condition: %d\n",
175 iError));
176 return iError;
177 }
178}
179
180#endif
181
182
183
184
185
186
187
188/*****************************************************************************
189 * Name :
190 * Purpose :
191 * Parameters:
192 * Variables :
193 * Result :
194 * Remark :
195 * Status : UNTESTED STUB
196 *
197 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
198 *****************************************************************************/
199
200
201ODINPROCEDURE1(OS2WSASetLastError,
202 int,iError)
203{
204 WSASetLastError(iError);
205}
206
207
208/*****************************************************************************
209 * Name :
210 * Purpose :
211 * Parameters:
212 * Variables :
213 * Result :
214 * Remark :
215 * Status : UNTESTED STUB
216 *
217 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
218 *****************************************************************************/
219
220ODINFUNCTION0(int,OS2WSAGetLastError)
221{
222 return WSAGetLastError();
223}
224
225
226/*****************************************************************************
227 * Name :
228 * Purpose :
229 * Parameters:
230 * Variables :
231 * Result :
232 * Remark :
233 * Status : UNTESTED STUB
234 *
235 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
236 *****************************************************************************/
237
238ODINFUNCTION2(int,OS2__WSAFDIsSet,SOCKET, s,
239 fd_set*,fds)
240{
241 return (__WSAFDIsSet(s,fds));
242}
243
244
245/*****************************************************************************
246 * Name :
247 * Purpose :
248 * Parameters:
249 * Variables :
250 * Result :
251 * Remark :
252 * Status : UNTESTED STUB
253 *
254 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
255 *****************************************************************************/
256
257ODINFUNCTION3(SOCKET,OS2accept, SOCKET, s,
258 struct sockaddr *,addr,
259 int *, addrlen)
260{
261 return(accept(s,addr,addrlen));
262}
263
264
265/*****************************************************************************
266 * Name :
267 * Purpose :
268 * Parameters:
269 * Variables :
270 * Result :
271 * Remark :
272 * Status : UNTESTED STUB
273 *
274 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
275 *****************************************************************************/
276
277ODINFUNCTION3(int,OS2bind,
278 SOCKET ,s,
279 const struct sockaddr *,addr,
280 int, namelen)
281{
282 return(bind(s,addr,namelen));
283}
284
285
286/*****************************************************************************
287 * Name :
288 * Purpose :
289 * Parameters:
290 * Variables :
291 * Result :
292 * Remark :
293 * Status : UNTESTED STUB
294 *
295 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
296 *****************************************************************************/
297
298ODINFUNCTION1(int,OS2closesocket,SOCKET, s)
299{
300 return(closesocket(s));
301}
302
303
304/*****************************************************************************
305 * Name :
306 * Purpose :
307 * Parameters:
308 * Variables :
309 * Result :
310 * Remark :
311 * Status : UNTESTED STUB
312 *
313 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
314 *****************************************************************************/
315
316ODINFUNCTION3(int,OS2connect,
317 SOCKET, s,
318 const struct sockaddr *,name,
319 int, namelen)
320{
321 return(connect(s,name,namelen));
322}
323
324
325/*****************************************************************************
326 * Name :
327 * Purpose :
328 * Parameters:
329 * Variables :
330 * Result :
331 * Remark :
332 * Status : UNTESTED STUB
333 *
334 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
335 *****************************************************************************/
336
337ODINFUNCTION3(int,OS2ioctlsocket,
338 SOCKET,s,
339 long, cmd,
340 u_long *,argp)
341{
342 return(ioctlsocket(s,cmd,argp));
343}
344
345
346/*****************************************************************************
347 * Name :
348 * Purpose :
349 * Parameters:
350 * Variables :
351 * Result :
352 * Remark :
353 * Status : UNTESTED STUB
354 *
355 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
356 *****************************************************************************/
357
358ODINFUNCTION3(int,OS2getpeername,
359 SOCKET, s,
360 struct sockaddr *,name,
361 int *, namelen)
362{
363 return(getpeername(s,name,namelen));
364}
365
366
367/*****************************************************************************
368 * Name :
369 * Purpose :
370 * Parameters:
371 * Variables :
372 * Result :
373 * Remark :
374 * Status : UNTESTED STUB
375 *
376 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
377 *****************************************************************************/
378
379ODINFUNCTION3(int,OS2getsockname,
380 SOCKET,s,
381 struct sockaddr *,name,
382 int *, namelen)
383{
384 return(getsockname(s,name,namelen));
385}
386
387
388/*****************************************************************************
389 * Name :
390 * Purpose :
391 * Parameters:
392 * Variables :
393 * Result :
394 * Remark :
395 * Status : UNTESTED STUB
396 *
397 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
398 *****************************************************************************/
399
400ODINFUNCTION5(int,OS2getsockopt,
401 SOCKET, s,
402 int, level,
403 int, optname,
404 char *, optval,
405 int *,optlen)
406{
407 return(getsockopt(s,
408 level,
409 optname,
410 optval,
411 optlen));
412}
413
414
415/*****************************************************************************
416 * Name :
417 * Purpose :
418 * Parameters:
419 * Variables :
420 * Result :
421 * Remark :
422 * Status : UNTESTED STUB
423 *
424 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
425 *****************************************************************************/
426
427ODINFUNCTION1(u_long,OS2htonl,
428 u_long,hostlong)
429{
430 return(htonl(hostlong));
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 [Thu, 1999/11/25 23:00]
444 *****************************************************************************/
445
446ODINFUNCTION1(u_short,OS2htons,
447 u_short,hostshort)
448{
449 return(htons(hostshort));
450}
451
452
453/*****************************************************************************
454 * Name :
455 * Purpose :
456 * Parameters:
457 * Variables :
458 * Result :
459 * Remark :
460 * Status : UNTESTED STUB
461 *
462 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
463 *****************************************************************************/
464
465ODINFUNCTION1(unsigned long,OS2inet_addr,
466 const char *, cp)
467{
468 dprintf(("WSOCK32: OS2inet_addr(%s)\n",
469 cp));
470
471 return (inet_addr(cp));
472}
473
474
475/*****************************************************************************
476 * Name :
477 * Purpose :
478 * Parameters:
479 * Variables :
480 * Result :
481 * Remark :
482 * Status : UNTESTED STUB
483 *
484 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
485 *****************************************************************************/
486
487ODINFUNCTION1(char *,OS2inet_ntoa,
488 struct in_addr, in)
489{
490 return(inet_ntoa(in));
491}
492
493
494/*****************************************************************************
495 * Name :
496 * Purpose :
497 * Parameters:
498 * Variables :
499 * Result :
500 * Remark :
501 * Status : UNTESTED STUB
502 *
503 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
504 *****************************************************************************/
505
506ODINFUNCTION2(int,OS2listen,
507 SOCKET, s,
508 int, backlog)
509{
510 return(listen(s,backlog));
511}
512
513
514/*****************************************************************************
515 * Name :
516 * Purpose :
517 * Parameters:
518 * Variables :
519 * Result :
520 * Remark :
521 * Status : UNTESTED STUB
522 *
523 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
524 *****************************************************************************/
525
526ODINFUNCTION1(u_long,OS2ntohl,
527 u_long,netlong)
528{
529 return(ntohl(netlong));
530}
531
532
533/*****************************************************************************
534 * Name :
535 * Purpose :
536 * Parameters:
537 * Variables :
538 * Result :
539 * Remark :
540 * Status : UNTESTED STUB
541 *
542 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
543 *****************************************************************************/
544
545ODINFUNCTION1(u_short,OS2ntohs,
546 u_short,netshort)
547{
548 return(ntohs(netshort));
549}
550
551
552/*****************************************************************************
553 * Name :
554 * Purpose :
555 * Parameters:
556 * Variables :
557 * Result :
558 * Remark :
559 * Status : UNTESTED STUB
560 *
561 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
562 *****************************************************************************/
563
564ODINFUNCTION4(int,OS2recv,
565 SOCKET,s,
566 char *,buf,
567 int,len,
568 int,flags)
569{
570 return(recv(s,
571 buf,
572 len,
573 flags));
574}
575
576
577/*****************************************************************************
578 * Name :
579 * Purpose :
580 * Parameters:
581 * Variables :
582 * Result :
583 * Remark :
584 * Status : UNTESTED STUB
585 *
586 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
587 *****************************************************************************/
588
589ODINFUNCTION6(int,OS2recvfrom,
590 SOCKET,s,
591 char *,buf,
592 int,len,
593 int,flags,
594 struct sockaddr *,from,
595 int *,fromlen)
596{
597
598 return(recvfrom(s,
599 buf,
600 len,
601 flags,
602 from,
603 fromlen));
604}
605
606
607/*****************************************************************************
608 * Name :
609 * Purpose :
610 * Parameters:
611 * Variables :
612 * Result :
613 * Remark :
614 * Status : UNTESTED STUB
615 *
616 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
617 *****************************************************************************/
618
619ODINFUNCTION5(int,OS2select,
620 int,nfds,
621 fd_set *,readfds,
622 fd_set *,writefds,
623 fd_set *,exceptfds,
624 const struct timeval *,timeout)
625{
626 return(select(nfds,
627 readfds,
628 writefds,
629 exceptfds,
630 timeout));
631}
632
633
634/*****************************************************************************
635 * Name :
636 * Purpose :
637 * Parameters:
638 * Variables :
639 * Result :
640 * Remark :
641 * Status : UNTESTED STUB
642 *
643 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
644 *****************************************************************************/
645
646ODINFUNCTION4(int,OS2send,
647 SOCKET,s,
648 const char *,buf,
649 int,len,
650 int,flags)
651{
652 return(send(s,
653 buf,
654 len,
655 flags));
656}
657
658
659/*****************************************************************************
660 * Name :
661 * Purpose :
662 * Parameters:
663 * Variables :
664 * Result :
665 * Remark :
666 * Status : UNTESTED STUB
667 *
668 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
669 *****************************************************************************/
670
671ODINFUNCTION6(int,OS2sendto,
672 SOCKET,s,
673 const char *,buf,
674 int,len,
675 int,flags,
676 const struct sockaddr *,to,
677 int,tolen)
678{
679 return(sendto(s,
680 buf,
681 len,
682 flags,
683 to,
684 tolen));
685}
686
687
688/*****************************************************************************
689 * Name :
690 * Purpose :
691 * Parameters:
692 * Variables :
693 * Result :
694 * Remark :
695 * Status : UNTESTED STUB
696 *
697 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
698 *****************************************************************************/
699
700ODINFUNCTION5(int,OS2setsockopt,
701 SOCKET,s,
702 int,level,
703 int,optname,
704 const char *,optval,
705 int,optlen)
706{
707 struct Wlinger *yy;
708 struct linger xx;
709 int rc;
710
711 if(level == SOL_SOCKET &&
712 optname == SO_LINGER)
713 {
714 yy = (struct Wlinger *)optval;
715 xx.l_onoff = (int)yy->l_onoff;
716 xx.l_linger = (int)yy->l_linger;
717
718 rc = setsockopt(s,level,optname,(char *)&xx,optlen);
719 }
720 else
721 rc = setsockopt(s,level,optname,(char *)optval,optlen);
722
723 if (rc == SOCKET_ERROR)
724 //OS2WSASetLastError(iTranslateSockErrToWSock(sock_errno()));
725 OS2WSASetLastError(WSAEINVAL);
726 else
727 OS2WSASetLastError(ERROR_SUCCESS);
728
729 return rc;
730}
731
732
733/*****************************************************************************
734 * Name :
735 * Purpose :
736 * Parameters:
737 * Variables :
738 * Result :
739 * Remark :
740 * Status : UNTESTED STUB
741 *
742 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
743 *****************************************************************************/
744
745ODINFUNCTION2(int,OS2shutdown,
746 SOCKET,s,
747 int,how)
748{
749 return(shutdown(s,
750 how));
751}
752
753
754/*****************************************************************************
755 * Name :
756 * Purpose :
757 * Parameters:
758 * Variables :
759 * Result :
760 * Remark :
761 * Status : UNTESTED STUB
762 *
763 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
764 *****************************************************************************/
765
766ODINFUNCTION3(SOCKET,OS2socket,
767 int,af,
768 int,type,
769 int,protocol)
770{
771 return(socket(af,
772 type,
773 protocol));
774}
775
776
777/* Database function prototypes */
778
779/*****************************************************************************
780 * Name :
781 * Purpose :
782 * Parameters:
783 * Variables :
784 * Result :
785 * Remark :
786 * Status : UNTESTED STUB
787 *
788 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
789 *****************************************************************************/
790
791ODINFUNCTION3(struct Whostent *,OS2gethostbyaddr,
792 const char *,addr,
793 int,len,
794 int,type)
795{
796 WHOSTENT *yy;
797 struct hostent *xx;
798 PWSOCKTHREADDATA pwstd;
799
800 xx = gethostbyaddr((char *)addr,len,type);
801 //PH: we assume PMWSOCK sets WSASetLastError correctly!
802
803 if(xx == NULL)
804 return (WHOSTENT *)NULL;
805
806 // access current thread wsock data block
807 pwstd = iQueryWsockThreadData();
808
809 pwstd->whsnt.h_name = xx->h_name;
810 pwstd->whsnt.h_aliases = xx->h_aliases;
811 pwstd->whsnt.h_addrtype = (short)xx->h_addrtype;
812 pwstd->whsnt.h_length = (short)xx->h_length;
813 pwstd->whsnt.h_addr_list = xx->h_addr_list;
814
815 return &pwstd->whsnt;
816}
817
818
819/*****************************************************************************
820 * Name :
821 * Purpose :
822 * Parameters:
823 * Variables :
824 * Result :
825 * Remark :
826 * Status : UNTESTED STUB
827 *
828 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
829 *****************************************************************************/
830
831ODINFUNCTION1(struct Whostent *,OS2gethostbyname,
832 const char *,name)
833{
834 WHOSTENT *yy;
835 struct hostent *xx;
836 PWSOCKTHREADDATA pwstd;
837
838
839 xx = gethostbyname((char *)name);
840 //PH: we assume PMWSOCK sets WSASetLastError correctly!
841
842 if(xx == NULL)
843 return (WHOSTENT *)NULL;
844
845 // access current thread wsock data block
846 pwstd = iQueryWsockThreadData();
847
848 pwstd->whsnt.h_name = xx->h_name;
849 pwstd->whsnt.h_aliases = xx->h_aliases;
850 pwstd->whsnt.h_addrtype = (short)xx->h_addrtype;
851 pwstd->whsnt.h_length = (short)xx->h_length;
852 pwstd->whsnt.h_addr_list = xx->h_addr_list;
853
854 return &pwstd->whsnt;
855}
856
857
858/*****************************************************************************
859 * Name :
860 * Purpose :
861 * Parameters:
862 * Variables :
863 * Result :
864 * Remark :
865 * Status : UNTESTED STUB
866 *
867 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
868 *****************************************************************************/
869
870ODINFUNCTION2(int,OS2gethostname,
871 char *,name,
872 int,namelen)
873{
874 //PH: we assume PMWSOCK sets WSASetLastError correctly!
875 return(gethostname(name,
876 namelen));
877}
878
879
880/*****************************************************************************
881 * Name :
882 * Purpose :
883 * Parameters:
884 * Variables :
885 * Result :
886 * Remark :
887 * Status : UNTESTED STUB
888 *
889 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
890 *****************************************************************************/
891
892ODINFUNCTION2(struct Wservent *,OS2getservbyport,
893 int, port,
894 const char *, proto)
895{
896 struct servent *xx;
897 PWSOCKTHREADDATA pwstd;
898
899 //PH: we assume PMWSOCK sets WSASetLastError correctly!
900 xx = getservbyport(port,(char *)proto);
901
902 if(xx == NULL)
903 return (WSERVENT *)NULL;
904
905 // access current thread wsock data block
906 pwstd = iQueryWsockThreadData();
907
908 pwstd->wsvnt.s_name = xx->s_name;
909 pwstd->wsvnt.s_aliases = xx->s_aliases;
910 pwstd->wsvnt.s_port = (short)xx->s_port;
911 pwstd->wsvnt.s_proto = xx->s_proto;
912
913 return &pwstd->wsvnt;
914}
915
916
917/*****************************************************************************
918 * Name :
919 * Purpose :
920 * Parameters:
921 * Variables :
922 * Result :
923 * Remark :
924 * Status : UNTESTED STUB
925 *
926 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
927 *****************************************************************************/
928
929ODINFUNCTION2(struct Wservent *,OS2getservbyname,
930 const char *, name,
931 const char *, proto)
932{
933 WSERVENT *yy;
934 struct servent *xx;
935 PWSOCKTHREADDATA pwstd;
936
937
938 //PH: we assume PMWSOCK sets WSASetLastError correctly!
939 xx = getservbyname((char *)name,(char *)proto);
940
941 if(xx == NULL)
942 return (WSERVENT *)NULL;
943
944 // access current thread wsock data block
945 pwstd = iQueryWsockThreadData();
946
947 pwstd->wsvnt.s_name = xx->s_name;
948 pwstd->wsvnt.s_aliases = xx->s_aliases;
949 pwstd->wsvnt.s_port = (short)xx->s_port;
950 pwstd->wsvnt.s_proto = xx->s_proto;
951
952 return &pwstd->wsvnt;
953}
954
955
956/*****************************************************************************
957 * Name :
958 * Purpose :
959 * Parameters:
960 * Variables :
961 * Result :
962 * Remark :
963 * Status : UNTESTED STUB
964 *
965 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
966 *****************************************************************************/
967
968ODINFUNCTION1(struct Wprotoent *,OS2getprotobynumber,
969 int,proto)
970{
971 struct protoent *xx;
972 PWSOCKTHREADDATA pwstd;
973
974 //PH: we assume PMWSOCK sets WSASetLastError correctly!
975 xx = getprotobynumber(proto);
976
977 if(xx == NULL)
978 return (WPROTOENT *)NULL;
979
980 // access current thread wsock data block
981 pwstd = iQueryWsockThreadData();
982
983 pwstd->wptnt.p_name = xx->p_name;
984 pwstd->wptnt.p_aliases = xx->p_aliases;
985 pwstd->wptnt.p_proto = (short)xx->p_proto;
986
987 return &pwstd->wptnt;
988}
989
990
991/*****************************************************************************
992 * Name :
993 * Purpose :
994 * Parameters:
995 * Variables :
996 * Result :
997 * Remark :
998 * Status : UNTESTED STUB
999 *
1000 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1001 *****************************************************************************/
1002
1003ODINFUNCTION1(struct Wprotoent *,OS2getprotobyname,
1004 const char *,name)
1005{
1006 struct protoent *xx;
1007 PWSOCKTHREADDATA pwstd;
1008
1009 //PH: we assume PMWSOCK sets WSASetLastError correctly!
1010 xx = getprotobyname((char *)name);
1011
1012 if(xx == NULL)
1013 return (WPROTOENT *)NULL;
1014
1015 // access current thread wsock data block
1016 pwstd = iQueryWsockThreadData();
1017
1018 pwstd->wptnt.p_name = xx->p_name;
1019 pwstd->wptnt.p_aliases = xx->p_aliases;
1020 pwstd->wptnt.p_proto = (short)xx->p_proto;
1021
1022 return &pwstd->wptnt;
1023}
1024
1025
1026
1027/* Microsoft Windows Extension function prototypes */
1028
1029/*****************************************************************************
1030 * Name :
1031 * Purpose :
1032 * Parameters:
1033 * Variables :
1034 * Result :
1035 * Remark :
1036 * Status : UNTESTED STUB
1037 *
1038 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1039 *****************************************************************************/
1040
1041ODINFUNCTION2(int,OS2WSAStartup,
1042 USHORT,wVersionRequired,
1043 LPWSADATA,lpWSAData)
1044{
1045 return(WSAStartup(wVersionRequired,
1046 lpWSAData));
1047}
1048
1049
1050/*****************************************************************************
1051 * Name :
1052 * Purpose :
1053 * Parameters:
1054 * Variables :
1055 * Result :
1056 * Remark :
1057 * Status : UNTESTED STUB
1058 *
1059 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1060 *****************************************************************************/
1061
1062ODINFUNCTION0(int,OS2WSACleanup)
1063{
1064 return(WSACleanup());
1065}
1066
1067
1068/*****************************************************************************
1069 * Name :
1070 * Purpose :
1071 * Parameters:
1072 * Variables :
1073 * Result :
1074 * Remark :
1075 * Status : UNTESTED STUB
1076 *
1077 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1078 *****************************************************************************/
1079
1080ODINFUNCTION0(BOOL,OS2WSAIsBlocking)
1081{
1082 return WSAIsBlocking();
1083}
1084
1085
1086/*****************************************************************************
1087 * Name :
1088 * Purpose :
1089 * Parameters:
1090 * Variables :
1091 * Result :
1092 * Remark :
1093 * Status : UNTESTED STUB
1094 *
1095 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1096 *****************************************************************************/
1097
1098ODINFUNCTION0(int,OS2WSAUnhookBlockingHook)
1099{
1100 return WSAUnhookBlockingHook();
1101}
1102
1103
1104/*****************************************************************************
1105 * Name :
1106 * Purpose :
1107 * Parameters:
1108 * Variables :
1109 * Result :
1110 * Remark :
1111 * Status : UNTESTED STUB
1112 *
1113 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1114 *****************************************************************************/
1115
1116ODINFUNCTION1(PFN,OS2WSASetBlockingHook,
1117 PFN,lpBlockFunc)
1118{
1119 return(WSASetBlockingHook(lpBlockFunc));
1120}
1121
1122
1123/*****************************************************************************
1124 * Name :
1125 * Purpose :
1126 * Parameters:
1127 * Variables :
1128 * Result :
1129 * Remark :
1130 * Status : UNTESTED STUB
1131 *
1132 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1133 *****************************************************************************/
1134
1135ODINFUNCTION0(int,OS2WSACancelBlockingCall)
1136{
1137 return(WSACancelBlockingCall());
1138}
1139
1140
1141/*****************************************************************************
1142 * Name :
1143 * Purpose :
1144 * Parameters:
1145 * Variables :
1146 * Result :
1147 * Remark :
1148 * Status : UNTESTED STUB
1149 *
1150 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1151 *****************************************************************************/
1152
1153ODINFUNCTION6(LHANDLE,OS2WSAAsyncGetServByName,
1154 HWND,hWnd,
1155 u_int,wMsg,
1156 const char *,name,
1157 const char *,proto,
1158 char *,buf,
1159 int,buflen)
1160{
1161 int rc;
1162 HWND hwndOS2 = Win32ToOS2Handle(hWnd);
1163 ULONG ulNewID;
1164
1165 if (hwndRelay == NULL) // already initialized ?
1166 hwndRelay = RelayInitialize(hwndOS2);
1167
1168 // add entry to list, we need to store both our temp buffer and the apps buffer
1169 ulNewID = RelayAlloc(hWnd,
1170 wMsg,
1171 FALSE,
1172 ASYNCREQUEST_GETSERVBYNAME,
1173 buf);
1174
1175 // call pmwsock function, will fill our temp buffer
1176 rc = WSAAsyncGetServByName(hwndRelay,
1177 ulNewID,
1178 name,
1179 proto,
1180 buf,
1181 buflen);
1182
1183 // if an error occurs, free the allocated relay entry
1184 if (rc == SOCKET_ERROR)
1185 RelayFree(ulNewID);
1186
1187 return (rc);
1188}
1189
1190
1191/*****************************************************************************
1192 * Name :
1193 * Purpose :
1194 * Parameters:
1195 * Variables :
1196 * Result :
1197 * Remark :
1198 * Status : UNTESTED STUB
1199 *
1200 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1201 *****************************************************************************/
1202
1203ODINFUNCTION6(LHANDLE,OS2WSAAsyncGetServByPort,
1204 HWND,hWnd,
1205 u_int,wMsg,
1206 int,port,
1207 const char *,proto,
1208 char *,buf,
1209 int,buflen)
1210{
1211 int rc;
1212 HWND hwndOS2 = Win32ToOS2Handle(hWnd);
1213 ULONG ulNewID;
1214
1215 if (hwndRelay == NULL) // already initialized ?
1216 hwndRelay = RelayInitialize(hwndOS2);
1217
1218 // add entry to list, we need to store both our temp buffer and the apps buffer
1219 ulNewID = RelayAlloc(hWnd,
1220 wMsg,
1221 FALSE,
1222 ASYNCREQUEST_GETSERVBYPORT,
1223 buf);
1224
1225 // call pmwsock function, will fill our temp buffer
1226 rc = WSAAsyncGetServByPort(hwndRelay,
1227 ulNewID,
1228 port,
1229 proto,
1230 buf,
1231 buflen);
1232
1233 // if an error occurs, free the allocated relay entry
1234 if (rc == SOCKET_ERROR)
1235 RelayFree(ulNewID);
1236
1237 return rc;
1238}
1239
1240
1241/*****************************************************************************
1242 * Name :
1243 * Purpose :
1244 * Parameters:
1245 * Variables :
1246 * Result :
1247 * Remark :
1248 * Status : UNTESTED STUB
1249 *
1250 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1251 *****************************************************************************/
1252
1253ODINFUNCTION5(LHANDLE,OS2WSAAsyncGetProtoByName,
1254 HWND,hWnd,
1255 u_int,wMsg,
1256 const char *,name,
1257 char *,buf,
1258 int,buflen)
1259{
1260 int rc;
1261 HWND hwndOS2 = Win32ToOS2Handle(hWnd);
1262 ULONG ulNewID;
1263
1264 if (hwndRelay == NULL) // already initialized ?
1265 hwndRelay = RelayInitialize(hwndOS2);
1266
1267 // add entry to list, we need to store both our temp buffer and the apps buffer
1268 ulNewID = RelayAlloc(hWnd,
1269 wMsg,
1270 FALSE,
1271 ASYNCREQUEST_GETPROTOBYNAME,
1272 buf);
1273
1274 // call pmwsock function, will fill our temp buffer
1275 rc = WSAAsyncGetProtoByName(hwndRelay,
1276 ulNewID,
1277 name,
1278 buf,
1279 buflen);
1280
1281 // if an error occurs, free the allocated relay entry
1282 if (rc == SOCKET_ERROR)
1283 RelayFree(ulNewID);
1284
1285 return (rc);
1286}
1287
1288
1289/*****************************************************************************
1290 * Name :
1291 * Purpose :
1292 * Parameters:
1293 * Variables :
1294 * Result :
1295 * Remark :
1296 * Status : UNTESTED STUB
1297 *
1298 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1299 *****************************************************************************/
1300
1301ODINFUNCTION5(LHANDLE,OS2WSAAsyncGetProtoByNumber,
1302 HWND,hWnd,
1303 u_int,wMsg,
1304 int,number,
1305 char *,buf,
1306 int,buflen)
1307{
1308 int rc;
1309 HWND hwndOS2 = Win32ToOS2Handle(hWnd);
1310 ULONG ulNewID;
1311
1312 if (hwndRelay == NULL) // already initialized ?
1313 hwndRelay = RelayInitialize(hwndOS2);
1314
1315 // add entry to list, we need to store both our temp buffer and the apps buffer
1316 ulNewID = RelayAlloc(hWnd,
1317 wMsg,
1318 FALSE,
1319 ASYNCREQUEST_GETPROTOBYNUMBER,
1320 buf);
1321
1322 // call pmwsock function, will fill our temp buffer
1323 rc = WSAAsyncGetProtoByNumber(hwndRelay,
1324 ulNewID,
1325 number,
1326 buf,
1327 buflen);
1328
1329 // if an error occurs, free the allocated relay entry
1330 if (rc == SOCKET_ERROR)
1331 RelayFree(ulNewID);
1332
1333 return rc;
1334}
1335
1336
1337/*****************************************************************************
1338 * Name :
1339 * Purpose :
1340 * Parameters:
1341 * Variables :
1342 * Result :
1343 * Remark :
1344 * Status : UNTESTED STUB
1345 *
1346 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1347 *****************************************************************************/
1348
1349ODINFUNCTION5(LHANDLE,OS2WSAAsyncGetHostByName,
1350 HWND,hWnd,
1351 u_int,wMsg,
1352 const char *,name,
1353 char *,buf,
1354 int,buflen)
1355{
1356 int rc;
1357 HWND hwndOS2 = Win32ToOS2Handle(hWnd);
1358 ULONG ulNewID;
1359
1360 if (hwndRelay == NULL) // already initialized ?
1361 hwndRelay = RelayInitialize(hwndOS2);
1362
1363 // add entry to list, we need to store both our temp buffer and the apps buffer
1364 ulNewID = RelayAlloc(hWnd,
1365 wMsg,
1366 FALSE,
1367 ASYNCREQUEST_GETHOSTBYNAME,
1368 buf);
1369
1370 // call pmwsock function, will fill our temp buffer
1371 rc = WSAAsyncGetHostByName(hwndRelay,
1372 ulNewID,
1373 name,
1374 buf,
1375 buflen);
1376
1377 // if an error occurs, free the allocated relay entry
1378 if (rc == SOCKET_ERROR)
1379 RelayFree(ulNewID);
1380
1381 return rc;
1382}
1383
1384
1385/*****************************************************************************
1386 * Name :
1387 * Purpose :
1388 * Parameters:
1389 * Variables :
1390 * Result :
1391 * Remark :
1392 * Status : UNTESTED STUB
1393 *
1394 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1395 *****************************************************************************/
1396
1397ODINFUNCTION7(LHANDLE,OS2WSAAsyncGetHostByAddr,
1398 HWND,hWnd,
1399 u_int,wMsg,
1400 const char *,addr,
1401 int,len,
1402 int,type,
1403 char *,buf,
1404 int,buflen)
1405{
1406 int rc;
1407 HWND hwndOS2 = Win32ToOS2Handle(hWnd);
1408 ULONG ulNewID;
1409
1410 if (hwndRelay == NULL) // already initialized ?
1411 hwndRelay = RelayInitialize(hwndOS2);
1412
1413 // add entry to list, we need to store both our temp buffer and the apps buffer
1414 ulNewID = RelayAlloc(hWnd,
1415 wMsg,
1416 FALSE,
1417 ASYNCREQUEST_GETHOSTBYADDR,
1418 buf);
1419
1420 // call pmwsock function, will fill our temp buffer
1421 rc = WSAAsyncGetHostByAddr(hwndRelay,
1422 ulNewID,
1423 addr,
1424 len,
1425 type,
1426 buf,
1427 buflen);
1428
1429 // if an error occurs, free the allocated relay entry
1430 if (rc == SOCKET_ERROR)
1431 RelayFree(ulNewID);
1432
1433 return (rc);
1434}
1435
1436
1437/*****************************************************************************
1438 * Name :
1439 * Purpose :
1440 * Parameters:
1441 * Variables :
1442 * Result :
1443 * Remark :
1444 * Status : UNTESTED STUB
1445 *
1446 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1447 *****************************************************************************/
1448
1449ODINFUNCTION1(int,OS2WSACancelAsyncRequest,
1450 LHANDLE,hAsyncTaskHandle)
1451{
1452 return(WSACancelAsyncRequest(hAsyncTaskHandle));
1453}
1454
1455
1456/*****************************************************************************
1457 * Name :
1458 * Purpose :
1459 * Parameters:
1460 * Variables :
1461 * Result :
1462 * Remark :
1463 * Status : UNTESTED STUB
1464 *
1465 * Author : Patrick Haller [Thu, 1999/11/25 23:00]
1466 *****************************************************************************/
1467
1468ODINFUNCTION4(int,OS2WSAAsyncSelect,
1469 SOCKET,s,
1470 HWND,hWnd,
1471 u_int,wMsg,
1472 long,lEvent)
1473{
1474 int rc;
1475// int iError;
1476 HWND hwndOS2 = Win32ToOS2Handle(hWnd);
1477 ULONG ulNewID;
1478
1479 if (hwndRelay == NULL) // already initialized ?
1480 hwndRelay = RelayInitialize(hwndOS2);
1481
1482 /* @@@PH: our source window doesn't seem to have an anchor block.
1483 Docs suggest we've missed to call WinInitialize on the
1484 caller thread.
1485
1486 Cause however is the Open32 handle is (of course!) invalid
1487 in plain PM Window Manager! -> use DAPWSOCK
1488
1489 Unfortunately, DAPWSOCK calls WinQueryAnchorBlock(hOpen32), too.
1490 So, we're stuck until I resolve hWnd to it's valid PM
1491 counterpart.
1492
1493 new problem: we've ultimately got to use PostMessageA instead
1494 anything else. => create invisible msg relay window:
1495 - hMsg = registerMessage(hWnd, wMsg)
1496 - call WSAAsyncSelect with object window handle
1497 - overwrite hWnd relay for "same handles"
1498 */
1499
1500 // add event to list or remove any list entry in case of WSAAsyncSelect(hwnd,0,0)
1501 if ( (wMsg == 0) && (lEvent == 0) )
1502 {
1503 // remove entry from list
1504 RelayFreeByHwnd(hWnd);
1505 }
1506 else
1507 // add entry to list
1508 ulNewID = RelayAlloc(hWnd,
1509 wMsg,
1510 TRUE,
1511 ASYNCREQUEST_SELECT);
1512
1513 rc = WSAAsyncSelect(s,
1514 hwndRelay,
1515 ulNewID,
1516 lEvent);
1517
1518// iError = WSAGetLastError();
1519// dprintf(("res=%d, err=%d\n",
1520// rc,
1521// iError));
1522 return (rc);
1523}
Note: See TracBrowser for help on using the repository browser.