- Timestamp:
- Nov 10, 1999, 5:36:16 PM (26 years ago)
- Location:
- trunk/src/wsock32
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wsock32/async.cpp
r1588 r1690 1 /* $Id: async.cpp,v 1.1 2 1999-11-04 01:13:41phaller Exp $ */1 /* $Id: async.cpp,v 1.13 1999-11-10 16:36:15 phaller Exp $ */ 2 2 3 3 /* … … 48 48 49 49 ODINDEBUGCHANNEL(WSOCK32-ASYNC) 50 51 52 typedef enum tagSocketStatus 53 { 54 SOCKSTAT_UNKNOWN = 0, // unknown socket state 55 SOCKSTAT_NORMAL, // normal socket state 56 SOCKSTAT_CONNECT_PENDING // non-blocking connect attempted 57 }; 58 59 typedef struct tagSocketAsync 60 { 61 int hSocket; /* operating system socket descriptor */ 62 int iStatus; 63 } SOCKETASYNC, *PSOCKETASYNC; 50 64 51 65 … … 122 136 void _Optlink WorkerThreadProc(void* pParam); 123 137 BOOL _System PostMessageA(HWND hwnd, UINT ulMessage, WPARAM wParam, LPARAM lParam); 124 125 void _System SetLastError(int iError);126 int _System GetLastError(void);127 #define WSASetLastError(a) SetLastError(a)128 138 129 139 … … 1000 1010 ulEvent = (ULONG) pRequest->ul2; 1001 1011 1012 //@@@PH to do 1013 // 1. automatically set socket to non-blocking mode 1014 1002 1015 //@@@PH how to implement other events? 1016 1003 1017 1004 1018 // finally do the select! -
trunk/src/wsock32/wsock32.cpp
r1468 r1690 1 /* $Id: wsock32.cpp,v 1.1 1 1999-10-27 08:38:05 phaller Exp $ */1 /* $Id: wsock32.cpp,v 1.12 1999-11-10 16:36:15 phaller Exp $ */ 2 2 3 3 /* … … 55 55 #include <sys/time.h> 56 56 #include <win32type.h> 57 #include <wprocess.h> 58 #include <heapstring.h> 59 57 60 #include "wsock32const.h" 58 61 #include "wsock32.h" … … 77 80 #undef FD_ISSET 78 81 #define FD_ISSET(x,y) WFD_SET(x,y) 82 #endif 83 84 #ifndef ERROR_SUCCESS 85 #define ERROR_SUCCESS 0 79 86 #endif 80 87 … … 117 124 118 125 // @@@PH not reentrancy proof 119 static WHOSTENT whsnt; 120 static WSERVENT wsvnt; 121 static WPROTOENT wptnt; 126 //<_sandervl> phs: I already have a rewrite of the error support in wsock. Use the 127 // GetThreadTHDB export in kernel32 and add a DWORD to the thread 128 // structure in include\win\thread.h 129 130 typedef struct tagWsockThreadData 131 { 132 DWORD dwLastError; // Get/SetLastError 133 WHOSTENT whsnt; // database conversion buffers 134 WSERVENT wsvnt; 135 WPROTOENT wptnt; 136 } WSOCKTHREADDATA, *PWSOCKTHREADDATA; 137 138 static WSOCKTHREADDATA wstdFallthru; // for emergency only 139 140 141 /***************************************************************************** 142 * Name : 143 * Purpose : 144 * Parameters: 145 * Variables : 146 * Result : 147 * Remark : free memory when thread dies 148 * Status : UNTESTED STUB 149 * 150 * Author : Patrick Haller [Tue, 1998/06/16 23:00] 151 *****************************************************************************/ 152 153 PWSOCKTHREADDATA iQueryWsockThreadData(void) 154 { 155 struct _THDB* pThreadDB = (struct _THDB*)GetThreadTHDB(); 156 PWSOCKTHREADDATA pwstd; 157 158 // check for existing pointer 159 if (pThreadDB != NULL) 160 { 161 if (pThreadDB->pWsockData == NULL) 162 { 163 // allocate on demand + initialize 164 pwstd = (PWSOCKTHREADDATA)HEAP_malloc (sizeof(WSOCKTHREADDATA)); 165 pThreadDB->pWsockData = (LPVOID)pwstd; 166 } 167 else 168 // use already allocated memory 169 pwstd = (PWSOCKTHREADDATA)pThreadDB->pWsockData; 170 } 171 172 if (pwstd == NULL) 173 pwstd = &wstdFallthru; // no memory and not allocated already 174 175 return pwstd; 176 } 122 177 123 178 … … 240 295 241 296 if (rc == INVALID_SOCKET) 242 OS2WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 297 WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 298 else 299 WSASetLastError(ERROR_SUCCESS); 243 300 244 301 return rc; … … 265 322 266 323 if (rc < 0) 267 OS2WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 268 324 WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 325 else 326 WSASetLastError(ERROR_SUCCESS); 269 327 return rc; 270 328 } … … 288 346 289 347 if (rc < 0) 290 OS2WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 348 WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 349 else 350 WSASetLastError(ERROR_SUCCESS); 291 351 292 352 return rc; … … 315 375 316 376 if (rc < 0) 317 OS2WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 377 WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 378 else 379 WSASetLastError(ERROR_SUCCESS); 318 380 319 381 return rc; … … 340 402 341 403 if (rc < 0) 342 OS2WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 404 WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 405 else 406 WSASetLastError(ERROR_SUCCESS); 343 407 344 408 return rc; … … 365 429 366 430 if (rc == SOCKET_ERROR) 367 OS2WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 431 WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 432 else 433 WSASetLastError(ERROR_SUCCESS); 368 434 369 435 return rc; … … 390 456 391 457 if (rc == SOCKET_ERROR) 392 OS2WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 458 WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 459 else 460 WSASetLastError(ERROR_SUCCESS); 393 461 394 462 return rc; … … 417 485 418 486 if (rc == SOCKET_ERROR) 419 OS2WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 487 WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 488 else 489 WSASetLastError(ERROR_SUCCESS); 420 490 421 491 return rc; … … 513 583 514 584 if (rc < 0) 515 OS2WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 585 WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 586 else 587 WSASetLastError(ERROR_SUCCESS); 516 588 517 589 return rc; … … 575 647 576 648 if (rc < 0) 577 OS2WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 649 WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 650 else 651 WSASetLastError(ERROR_SUCCESS); 578 652 579 653 return rc; … … 603 677 604 678 if (rc < 0) 605 OS2WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 679 WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 680 else 681 WSASetLastError(ERROR_SUCCESS); 606 682 607 683 return rc; … … 636 712 637 713 if (rc == SOCKET_ERROR) 638 OS2WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 714 WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 715 else 716 WSASetLastError(ERROR_SUCCESS); 639 717 640 718 return rc; … … 666 744 667 745 if (rc < 0) 668 OS2WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 746 WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 747 else 748 WSASetLastError(ERROR_SUCCESS); 669 749 670 750 return rc; … … 694 774 695 775 if (rc < 0) 696 OS2WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 776 WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 777 else 778 WSASetLastError(ERROR_SUCCESS); 697 779 698 780 return rc; … … 735 817 736 818 if (rc == SOCKET_ERROR) 737 OS2WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 819 WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 820 else 821 WSASetLastError(ERROR_SUCCESS); 738 822 739 823 return rc; … … 759 843 760 844 if (rc == SOCKET_ERROR) 761 OS2WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 845 WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 846 else 847 WSASetLastError(ERROR_SUCCESS); 762 848 763 849 return rc; … … 784 870 785 871 if (rc == INVALID_SOCKET) 786 OS2WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 872 WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 873 else 874 WSASetLastError(ERROR_SUCCESS); 787 875 788 876 return rc; … … 806 894 int, type) 807 895 { 808 WHOSTENT *yy; 809 struct hostent *xx; 896 WHOSTENT *yy; 897 struct hostent *xx; 898 PWSOCKTHREADDATA pwstd; 810 899 811 900 xx = gethostbyaddr((char *)addr,len,type); … … 813 902 if(xx == NULL) 814 903 { 815 OS2WSASetLastError(iTranslateSockErrToWSock(sock_errno()));904 WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 816 905 return (WHOSTENT *)NULL; 817 906 } 818 819 whsnt.h_name = xx->h_name; 820 whsnt.h_aliases = xx->h_aliases; 821 whsnt.h_addrtype = (short)xx->h_addrtype; 822 whsnt.h_length = (short)xx->h_length; 823 whsnt.h_addr_list = xx->h_addr_list; 824 825 return &whsnt; 907 else 908 WSASetLastError(ERROR_SUCCESS); 909 910 // access current thread wsock data block 911 pwstd = iQueryWsockThreadData(); 912 913 pwstd->whsnt.h_name = xx->h_name; 914 pwstd->whsnt.h_aliases = xx->h_aliases; 915 pwstd->whsnt.h_addrtype = (short)xx->h_addrtype; 916 pwstd->whsnt.h_length = (short)xx->h_length; 917 pwstd->whsnt.h_addr_list = xx->h_addr_list; 918 919 return &pwstd->whsnt; 826 920 } 827 921 … … 841 935 ODINFUNCTION1(WHOSTENT*,OS2gethostbyname,const char*,name) 842 936 { 843 WHOSTENT *yy; 844 struct hostent *xx; 937 WHOSTENT *yy; 938 struct hostent *xx; 939 PWSOCKTHREADDATA pwstd; 940 845 941 846 942 xx = gethostbyname((char *)name); 847 943 if(xx == NULL) 848 944 { 849 OS2WSASetLastError(iTranslateSockErrToWSock(sock_errno()));945 WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 850 946 return (WHOSTENT *)NULL; 851 947 } 852 853 whsnt.h_name = xx->h_name; 854 whsnt.h_aliases = xx->h_aliases; 855 whsnt.h_addrtype = (short)xx->h_addrtype; 856 whsnt.h_length = (short)xx->h_length; 857 whsnt.h_addr_list = xx->h_addr_list; 858 859 return &whsnt; 948 else 949 WSASetLastError(ERROR_SUCCESS); 950 951 // access current thread wsock data block 952 pwstd = iQueryWsockThreadData(); 953 954 pwstd->whsnt.h_name = xx->h_name; 955 pwstd->whsnt.h_aliases = xx->h_aliases; 956 pwstd->whsnt.h_addrtype = (short)xx->h_addrtype; 957 pwstd->whsnt.h_length = (short)xx->h_length; 958 pwstd->whsnt.h_addr_list = xx->h_addr_list; 959 960 return &pwstd->whsnt; 860 961 } 861 962 … … 895 996 const char*, proto) 896 997 { 897 struct servent *xx; 998 struct servent *xx; 999 PWSOCKTHREADDATA pwstd; 898 1000 899 1001 xx = getservbyport(port,(char *)proto); … … 901 1003 if(xx == NULL) 902 1004 { // this call doesn't generate an error message 903 OS2WSASetLastError(iTranslateSockErrToWSock(sock_errno()));1005 WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 904 1006 return (WSERVENT *)NULL; 905 1007 } 906 907 wsvnt.s_name = xx->s_name; 908 wsvnt.s_aliases = xx->s_aliases; 909 wsvnt.s_port = (short)xx->s_port; 910 wsvnt.s_proto = xx->s_proto; 911 912 return &wsvnt; 1008 else 1009 WSASetLastError(ERROR_SUCCESS); 1010 1011 // access current thread wsock data block 1012 pwstd = iQueryWsockThreadData(); 1013 1014 pwstd->wsvnt.s_name = xx->s_name; 1015 pwstd->wsvnt.s_aliases = xx->s_aliases; 1016 pwstd->wsvnt.s_port = (short)xx->s_port; 1017 pwstd->wsvnt.s_proto = xx->s_proto; 1018 1019 return &pwstd->wsvnt; 913 1020 } 914 1021 … … 929 1036 const char*,proto) 930 1037 { 931 WSERVENT *yy; 932 struct servent *xx; 1038 WSERVENT *yy; 1039 struct servent *xx; 1040 PWSOCKTHREADDATA pwstd; 1041 933 1042 934 1043 xx = getservbyname((char *)name,(char *)proto); … … 936 1045 if(xx == NULL) 937 1046 { // this call doesn't generate an error message 938 OS2WSASetLastError(iTranslateSockErrToWSock(sock_errno()));1047 WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 939 1048 return (WSERVENT *)NULL; 940 1049 } 941 942 wsvnt.s_name = xx->s_name; 943 wsvnt.s_aliases = xx->s_aliases; 944 wsvnt.s_port = (short)xx->s_port; 945 wsvnt.s_proto = xx->s_proto; 946 947 return &wsvnt; 1050 else 1051 WSASetLastError(ERROR_SUCCESS); 1052 1053 // access current thread wsock data block 1054 pwstd = iQueryWsockThreadData(); 1055 1056 pwstd->wsvnt.s_name = xx->s_name; 1057 pwstd->wsvnt.s_aliases = xx->s_aliases; 1058 pwstd->wsvnt.s_port = (short)xx->s_port; 1059 pwstd->wsvnt.s_proto = xx->s_proto; 1060 1061 return &pwstd->wsvnt; 948 1062 } 949 1063 … … 963 1077 ODINFUNCTION1(WPROTOENT*,OS2getprotobynumber,int,proto) 964 1078 { 965 struct protoent *xx; 1079 struct protoent *xx; 1080 PWSOCKTHREADDATA pwstd; 966 1081 967 1082 xx = getprotobynumber(proto); … … 970 1085 { 971 1086 // this call doesn't generate an error message 972 OS2WSASetLastError(iTranslateSockErrToWSock(sock_errno()));1087 WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 973 1088 return (WPROTOENT *)NULL; 974 1089 } 975 976 wptnt.p_name = xx->p_name; 977 wptnt.p_aliases = xx->p_aliases; 978 wptnt.p_proto = (short)xx->p_proto; 979 980 return &wptnt; 1090 else 1091 WSASetLastError(ERROR_SUCCESS); 1092 1093 // access current thread wsock data block 1094 pwstd = iQueryWsockThreadData(); 1095 1096 pwstd->wptnt.p_name = xx->p_name; 1097 pwstd->wptnt.p_aliases = xx->p_aliases; 1098 pwstd->wptnt.p_proto = (short)xx->p_proto; 1099 1100 return &pwstd->wptnt; 981 1101 } 982 1102 … … 996 1116 ODINFUNCTION1(WPROTOENT*,OS2getprotobyname,const char*,name) 997 1117 { 998 struct protoent *xx; 1118 struct protoent *xx; 1119 PWSOCKTHREADDATA pwstd; 999 1120 1000 1121 xx = getprotobyname((char *)name); … … 1002 1123 if(xx == NULL) 1003 1124 { // this call doesn't generate an error message 1004 OS2WSASetLastError(iTranslateSockErrToWSock(sock_errno()));1125 WSASetLastError(iTranslateSockErrToWSock(sock_errno())); 1005 1126 return (WPROTOENT *)NULL; 1006 1127 } 1007 1008 wptnt.p_name = xx->p_name; 1009 wptnt.p_aliases = xx->p_aliases; 1010 wptnt.p_proto = (short)xx->p_proto; 1011 1012 return &wptnt; 1128 else 1129 WSASetLastError(ERROR_SUCCESS); 1130 1131 // access current thread wsock data block 1132 pwstd = iQueryWsockThreadData(); 1133 1134 pwstd->wptnt.p_name = xx->p_name; 1135 pwstd->wptnt.p_aliases = xx->p_aliases; 1136 pwstd->wptnt.p_proto = (short)xx->p_proto; 1137 1138 return &pwstd->wptnt; 1013 1139 } 1014 1140 … … 1030 1156 { 1031 1157 APIRET rc; 1032 int ii;1033 1158 1034 1159 /* Make sure that the version requested is >= 1.1. */ … … 1057 1182 WriteLog("WSOCK32: WSAStartup sock_init returned 0\n"); 1058 1183 #endif 1059 return 0; 1184 WSASetLastError(ERROR_SUCCESS); 1185 return 0; 1060 1186 } 1061 1187 else 1062 ii = iTranslateSockErrToWSock(sock_errno()); 1063 1064 return ii; 1188 return(iTranslateSockErrToWSock(sock_errno())); 1065 1189 } 1066 1190 … … 1096 1220 *****************************************************************************/ 1097 1221 1098 ODINPROCEDURE1(OS2WSASetLastError,int,iError) 1099 { 1100 SetLastError(iError); 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 [Tue, 1998/06/16 23:00] 1114 *****************************************************************************/ 1115 1116 ODINFUNCTION0(int,OS2WSAGetLastError) 1117 { 1118 return GetLastError(); 1222 ODINPROCEDURE1(WSASetLastError,int,iError) 1223 { 1224 PWSOCKTHREADDATA pwstd = iQueryWsockThreadData(); 1225 pwstd->dwLastError = iError; 1226 } 1227 1228 1229 /***************************************************************************** 1230 * Name : 1231 * Purpose : 1232 * Parameters: 1233 * Variables : 1234 * Result : 1235 * Remark : 1236 * Status : UNTESTED STUB 1237 * 1238 * Author : Patrick Haller [Tue, 1998/06/16 23:00] 1239 *****************************************************************************/ 1240 1241 ODINFUNCTION0(int,WSAGetLastError) 1242 { 1243 PWSOCKTHREADDATA pwstd = iQueryWsockThreadData(); 1244 return(pwstd->dwLastError); 1119 1245 } 1120 1246 -
trunk/src/wsock32/wsock32.def
r1588 r1690 1 ; $Id: wsock32.def,v 1.1 3 1999-11-04 01:13:42phaller Exp $1 ; $Id: wsock32.def,v 1.14 1999-11-10 16:36:16 phaller Exp $ 2 2 3 3 ;Created by BLAST for IBM's compiler … … 7 7 IMPORTS 8 8 PostMessageA = USER32.416 9 SetLastError = KERNEL32.65410 GetLastError = KERNEL32.34011 9 bsd_select = SO32DLL.32 12 10 os2_select = SO32DLL.12 13 11 14 12 EXPORTS 15 ; _WSAFDIsSet = _OS2_WSAFDIsSet@816 13 ; Arecv = _OS2Arecv 17 14 ; Asend = _OS2Asend … … 74 71 WSASetBlockingHook = _OS2WSASetBlockingHook@4 @109 75 72 WSAUnhookBlockingHook = _OS2WSAUnhookBlockingHook@0 @110 76 WSAGetLastError = _ OS2WSAGetLastError@0 @11177 WSASetLastError = _ OS2WSASetLastError@4 @11273 WSAGetLastError = _WSAGetLastError@0 @111 74 WSASetLastError = _WSASetLastError@4 @112 78 75 WSACancelBlockingCall = _OS2WSACancelBlockingCall@0 @113 79 76
Note:
See TracChangeset
for help on using the changeset viewer.