Changeset 1807 for trunk/src/wsock32/async.cpp
- Timestamp:
- Nov 22, 1999, 9:18:04 AM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wsock32/async.cpp
r1761 r1807 1 /* $Id: async.cpp,v 1.1 5 1999-11-16 22:03:56phaller Exp $ */1 /* $Id: async.cpp,v 1.16 1999-11-22 08:18:01 phaller Exp $ */ 2 2 3 3 /* … … 9 9 * Copyright 1999 Patrick Haller 10 10 * 11 * 12 * Remark: 13 * - do NOT call WSASetLastError in the async worker thread, since there we don't 14 * know anything about the caller thread. 11 15 * 12 16 * Idea is to separate requests: … … 50 54 51 55 56 #define ERROR_SUCCESS 0 57 58 52 59 typedef enum tagSocketStatus 53 60 { … … 61 68 int hSocket; /* operating system socket descriptor */ 62 69 int iStatus; 70 71 int iEventMaskAllowed; // bits of valid socket events are set to 1 63 72 } SOCKETASYNC, *PSOCKETASYNC; 64 73 … … 116 125 ULONG ulType; // type of request 117 126 ULONG ulState; // state of request 127 PWSOCKTHREADDATA pwstd; // save pointer of caller thread's wsock data 118 128 119 129 HWND hwnd; // window handle to post message to … … 445 455 pRequestHead->pPrev = pNew; 446 456 pRequestHead = pNew; 457 } 458 459 // queue debug 460 { 461 PASYNCREQUEST pTemp; 462 463 dprintf(("WSOCK32: WSAAsyncWorker pRequest type state hwnd message\n")); 464 for (pTemp = pRequestHead; 465 pTemp; 466 pTemp = pTemp->pNext) 467 dprintf(("WSOCK32: WSAAsyncWorker %08xh %08xh %08xh %08xh %08xh", 468 pTemp, 469 pTemp->ulType, 470 pTemp->ulState, 471 pTemp->hwnd, 472 pTemp->ulMessage)); 447 473 } 448 474 … … 596 622 PASYNCREQUEST pNew = new ASYNCREQUEST(); 597 623 598 if (pNew == NULL) // check for proper allocation 599 return pNew; 600 601 // fill the structure 602 pNew->pPrev = NULL; 603 pNew->pNext = NULL; 604 pNew->ulType = ulType; 605 pNew->ulState = RS_WAITING; 606 pNew->hwnd = hwnd; 607 pNew->ulMessage = ulMessage; 608 pNew->pBuffer = pBuffer; 609 pNew->ulBufferLength = ulBufferLength; 610 pNew->ul1 = ul1; 611 pNew->ul2 = ul2; 612 pNew->ul3 = ul3; 624 if (pNew != NULL) // check for proper allocation 625 { 626 // fill the structure 627 pNew->pPrev = NULL; 628 pNew->pNext = NULL; 629 pNew->ulType = ulType; 630 pNew->ulState = RS_WAITING; 631 pNew->hwnd = hwnd; 632 pNew->ulMessage = ulMessage; 633 pNew->pBuffer = pBuffer; 634 pNew->ulBufferLength = ulBufferLength; 635 pNew->ul1 = ul1; 636 pNew->ul2 = ul2; 637 pNew->ul3 = ul3; 638 639 // save caller thread's wsock data 640 pNew->pwstd = iQueryWsockThreadData(); 641 } 642 643 dprintf(("WSOCK32: WSAAsyncWorker:createRequest = %08xh\n", 644 pNew)); 613 645 614 646 return pNew; … … 643 675 { 644 676 rc = WSAEINVAL; 645 WSASetLastError(rc); // same as Winsock return codes677 //WSASetLastError(rc); // same as Winsock return codes 646 678 } 647 679 else … … 655 687 // build error return code 656 688 rc = iTranslateSockErrToWSock(sock_errno()); 657 WSASetLastError(rc);689 //WSASetLastError(rc); 658 690 } 659 691 else … … 706 738 { 707 739 rc = WSAEINVAL; 708 WSASetLastError(rc); // same as Winsock return codes740 //WSASetLastError(rc); // same as Winsock return codes 709 741 } 710 742 else … … 716 748 // build error return code 717 749 rc = iTranslateSockErrToWSock(sock_errno()); 718 WSASetLastError(rc);750 //WSASetLastError(rc); 719 751 } 720 752 else … … 767 799 { 768 800 rc = WSAEINVAL; 769 WSASetLastError(rc); // same as Winsock return codes801 //WSASetLastError(rc); // same as Winsock return codes 770 802 } 771 803 else … … 777 809 // build error return code 778 810 rc = iTranslateSockErrToWSock(sock_errno()); 779 WSASetLastError(rc);811 //WSASetLastError(rc); 780 812 } 781 813 else … … 826 858 { 827 859 rc = WSAEINVAL; 828 WSASetLastError(rc); // same as Winsock return codes860 //WSASetLastError(rc); // same as Winsock return codes 829 861 } 830 862 else … … 836 868 // build error return code 837 869 rc = iTranslateSockErrToWSock(sock_errno()); 838 WSASetLastError(rc);870 //WSASetLastError(rc); 839 871 } 840 872 else … … 885 917 { 886 918 rc = WSAEINVAL; 887 WSASetLastError(rc); // same as Winsock return codes919 //WSASetLastError(rc); // same as Winsock return codes 888 920 } 889 921 else … … 896 928 // build error return code 897 929 rc = iTranslateSockErrToWSock(sock_errno()); 898 WSASetLastError(rc);930 //WSASetLastError(rc); 899 931 } 900 932 else … … 946 978 { 947 979 rc = WSAEINVAL; 948 WSASetLastError(rc); // same as Winsock return codes980 //WSASetLastError(rc); // same as Winsock return codes 949 981 } 950 982 else … … 957 989 // build error return code 958 990 rc = iTranslateSockErrToWSock(sock_errno()); 959 WSASetLastError(rc);991 //WSASetLastError(rc); 960 992 } 961 993 else … … 1018 1050 //@@@PH to do 1019 1051 // 1. automatically set socket to non-blocking mode 1052 // 2. loop until WSAAsyncSelect(s,hwnd,0,0) ? 1053 1020 1054 1021 1055 //@@@PH how to implement other events? … … 1096 1130 1097 1131 // post result 1132 irc = (LPARAM)((lParam << 16) | usResult); 1133 dprintf(("WSOCK32:asyncSelect() posting %08xh hwnd%08xh, msg=%08xh, wparam=%08xh, lparam=%08xh\n", 1134 pRequest, 1135 pRequest->hwnd, 1136 pRequest->ulMessage, 1137 sockWin, 1138 irc)); 1139 1098 1140 PostMessageA(pRequest->hwnd, 1099 1141 pRequest->ulMessage, 1100 1142 (WPARAM)sockWin, 1101 (LPARAM) ((lParam << 16) | usResult));1143 (LPARAM)irc); 1102 1144 1103 1145 // M$ says, if PostMessageA fails, spin as long as window exists … … 1144 1186 // OK, servicing request 1145 1187 pRequest->ulState = RS_BUSY; 1146 fBlocking = TRUE;1147 1188 1148 1189 switch(pRequest->ulType) … … 1167 1208 1168 1209 pRequest->ulState = RS_DONE; 1169 fBlocking = FALSE;1170 1210 return rc; 1171 1211 } … … 1205 1245 1206 1246 // wait for semaphore 1247 fBlocking = FALSE; 1207 1248 rc = DosWaitEventSem(hevRequest, SEM_INDEFINITE_WAIT); 1249 fBlocking = TRUE; 1208 1250 rc = DosResetEventSem(hevRequest, &ulPostCount); 1209 1251 } … … 1259 1301 (ULONG)buflen, 1260 1302 (ULONG)name); 1261 wsaWorker->pushRequest(pRequest); 1262 return (HANDLE)pRequest; 1303 if (pRequest != NULL) 1304 { 1305 // success 1306 wsaWorker->pushRequest(pRequest); 1307 WSASetLastError(ERROR_SUCCESS); 1308 return (HANDLE)pRequest; 1309 } 1310 else 1311 { 1312 // error 1313 WSASetLastError(WSAENOBUFS); 1314 return 0; 1315 } 1263 1316 } 1264 1317 … … 1292 1345 (ULONG)len, 1293 1346 (ULONG)type); 1294 wsaWorker->pushRequest(pRequest); 1295 return (HANDLE)pRequest; 1347 if (pRequest != NULL) 1348 { 1349 // success 1350 wsaWorker->pushRequest(pRequest); 1351 WSASetLastError(ERROR_SUCCESS); 1352 return (HANDLE)pRequest; 1353 } 1354 else 1355 { 1356 // error 1357 WSASetLastError(WSAENOBUFS); 1358 return 0; 1359 } 1296 1360 } 1297 1361 … … 1324 1388 (ULONG)name, 1325 1389 (ULONG)proto); 1326 wsaWorker->pushRequest(pRequest); 1327 return (HANDLE)pRequest; 1390 if (pRequest != NULL) 1391 { 1392 // success 1393 wsaWorker->pushRequest(pRequest); 1394 WSASetLastError(ERROR_SUCCESS); 1395 return (HANDLE)pRequest; 1396 } 1397 else 1398 { 1399 // error 1400 WSASetLastError(WSAENOBUFS); 1401 return 0; 1402 } 1328 1403 } 1329 1404 … … 1356 1431 (ULONG)port, 1357 1432 (ULONG)proto); 1358 wsaWorker->pushRequest(pRequest); 1359 return (HANDLE)pRequest; 1433 if (pRequest != NULL) 1434 { 1435 // success 1436 wsaWorker->pushRequest(pRequest); 1437 WSASetLastError(ERROR_SUCCESS); 1438 return (HANDLE)pRequest; 1439 } 1440 else 1441 { 1442 // error 1443 WSASetLastError(WSAENOBUFS); 1444 return 0; 1445 } 1360 1446 } 1361 1447 … … 1386 1472 (ULONG)buflen, 1387 1473 (ULONG)name); 1388 wsaWorker->pushRequest(pRequest); 1389 return (HANDLE)pRequest; 1474 if (pRequest != NULL) 1475 { 1476 // success 1477 wsaWorker->pushRequest(pRequest); 1478 WSASetLastError(ERROR_SUCCESS); 1479 return (HANDLE)pRequest; 1480 } 1481 else 1482 { 1483 // error 1484 WSASetLastError(WSAENOBUFS); 1485 return 0; 1486 } 1390 1487 } 1391 1488 … … 1415 1512 (ULONG)buflen, 1416 1513 (ULONG)number); 1417 wsaWorker->pushRequest(pRequest); 1418 return (HANDLE)pRequest; 1514 if (pRequest != NULL) 1515 { 1516 // success 1517 wsaWorker->pushRequest(pRequest); 1518 WSASetLastError(ERROR_SUCCESS); 1519 return (HANDLE)pRequest; 1520 } 1521 else 1522 { 1523 // error 1524 WSASetLastError(WSAENOBUFS); 1525 return 0; 1526 } 1419 1527 } 1420 1528 … … 1440 1548 rc = wsaWorker->cancelAsyncRequest(pRequest); 1441 1549 if (rc == TRUE) 1442 return 0; // success 1550 { 1551 WSASetLastError(ERROR_SUCCESS); 1552 return ERROR_SUCCESS; // success 1553 } 1443 1554 else 1444 1555 { 1556 // error 1445 1557 WSASetLastError(WSAEINVAL); 1446 1558 return (SOCKET_ERROR); … … 1485 1597 long, lEvent) 1486 1598 { 1599 // @@@PH 1999/11/21 implementation is completely wrong! 1600 // handle async select in a completely different way: 1601 // one thread per socket! 1487 1602 PASYNCREQUEST pRequest = wsaWorker->createRequest(WSAASYNC_SELECT, 1488 1603 (HWND) hwnd, … … 1492 1607 (ULONG)s, 1493 1608 (ULONG)lEvent); 1494 wsaWorker->pushRequest(pRequest); 1495 // return (HANDLE)pRequest; 1496 // AH: WINE returns 0 on this call 1497 return 0; 1498 } 1499 1609 if (pRequest != NULL) // request is OK ? 1610 { 1611 wsaWorker->pushRequest(pRequest); 1612 1613 // WSAAsyncSelect() can only fail if the flags specified don't match 1614 WSASetLastError(ERROR_SUCCESS); 1615 return ERROR_SUCCESS; 1616 } 1617 else 1618 { 1619 // error ! 1620 WSASetLastError(WSAEINVAL); 1621 return SOCKET_ERROR; 1622 } 1623 } 1624
Note:
See TracChangeset
for help on using the changeset viewer.