diff options
Diffstat (limited to 'src/w32.c')
| -rw-r--r-- | src/w32.c | 95 |
1 files changed, 61 insertions, 34 deletions
| @@ -6232,7 +6232,7 @@ sys_socket (int af, int type, int protocol) | |||
| 6232 | 6232 | ||
| 6233 | if (winsock_lib == NULL) | 6233 | if (winsock_lib == NULL) |
| 6234 | { | 6234 | { |
| 6235 | h_errno = ENETDOWN; | 6235 | errno = h_errno = ENETDOWN; |
| 6236 | return INVALID_SOCKET; | 6236 | return INVALID_SOCKET; |
| 6237 | } | 6237 | } |
| 6238 | 6238 | ||
| @@ -6242,7 +6242,13 @@ sys_socket (int af, int type, int protocol) | |||
| 6242 | s = pfn_socket (af, type, protocol); | 6242 | s = pfn_socket (af, type, protocol); |
| 6243 | 6243 | ||
| 6244 | if (s != INVALID_SOCKET) | 6244 | if (s != INVALID_SOCKET) |
| 6245 | return socket_to_fd (s); | 6245 | { |
| 6246 | int retval = socket_to_fd (s); | ||
| 6247 | |||
| 6248 | if (retval == -1) | ||
| 6249 | errno = h_errno; | ||
| 6250 | return retval; | ||
| 6251 | } | ||
| 6246 | 6252 | ||
| 6247 | set_errno (); | 6253 | set_errno (); |
| 6248 | return -1; | 6254 | return -1; |
| @@ -6309,6 +6315,7 @@ socket_to_fd (SOCKET s) | |||
| 6309 | } | 6315 | } |
| 6310 | } | 6316 | } |
| 6311 | } | 6317 | } |
| 6318 | eassert (fd < MAXDESC); | ||
| 6312 | fd_info[fd].hnd = (HANDLE) s; | 6319 | fd_info[fd].hnd = (HANDLE) s; |
| 6313 | 6320 | ||
| 6314 | /* set our own internal flags */ | 6321 | /* set our own internal flags */ |
| @@ -6347,7 +6354,7 @@ sys_bind (int s, const struct sockaddr * addr, int namelen) | |||
| 6347 | { | 6354 | { |
| 6348 | if (winsock_lib == NULL) | 6355 | if (winsock_lib == NULL) |
| 6349 | { | 6356 | { |
| 6350 | h_errno = ENOTSOCK; | 6357 | errno = h_errno = ENOTSOCK; |
| 6351 | return SOCKET_ERROR; | 6358 | return SOCKET_ERROR; |
| 6352 | } | 6359 | } |
| 6353 | 6360 | ||
| @@ -6359,7 +6366,7 @@ sys_bind (int s, const struct sockaddr * addr, int namelen) | |||
| 6359 | set_errno (); | 6366 | set_errno (); |
| 6360 | return rc; | 6367 | return rc; |
| 6361 | } | 6368 | } |
| 6362 | h_errno = ENOTSOCK; | 6369 | errno = h_errno = ENOTSOCK; |
| 6363 | return SOCKET_ERROR; | 6370 | return SOCKET_ERROR; |
| 6364 | } | 6371 | } |
| 6365 | 6372 | ||
| @@ -6368,7 +6375,7 @@ sys_connect (int s, const struct sockaddr * name, int namelen) | |||
| 6368 | { | 6375 | { |
| 6369 | if (winsock_lib == NULL) | 6376 | if (winsock_lib == NULL) |
| 6370 | { | 6377 | { |
| 6371 | h_errno = ENOTSOCK; | 6378 | errno = h_errno = ENOTSOCK; |
| 6372 | return SOCKET_ERROR; | 6379 | return SOCKET_ERROR; |
| 6373 | } | 6380 | } |
| 6374 | 6381 | ||
| @@ -6380,7 +6387,7 @@ sys_connect (int s, const struct sockaddr * name, int namelen) | |||
| 6380 | set_errno (); | 6387 | set_errno (); |
| 6381 | return rc; | 6388 | return rc; |
| 6382 | } | 6389 | } |
| 6383 | h_errno = ENOTSOCK; | 6390 | errno = h_errno = ENOTSOCK; |
| 6384 | return SOCKET_ERROR; | 6391 | return SOCKET_ERROR; |
| 6385 | } | 6392 | } |
| 6386 | 6393 | ||
| @@ -6414,7 +6421,7 @@ sys_gethostname (char * name, int namelen) | |||
| 6414 | if (namelen > MAX_COMPUTERNAME_LENGTH) | 6421 | if (namelen > MAX_COMPUTERNAME_LENGTH) |
| 6415 | return !GetComputerName (name, (DWORD *)&namelen); | 6422 | return !GetComputerName (name, (DWORD *)&namelen); |
| 6416 | 6423 | ||
| 6417 | h_errno = EFAULT; | 6424 | errno = h_errno = EFAULT; |
| 6418 | return SOCKET_ERROR; | 6425 | return SOCKET_ERROR; |
| 6419 | } | 6426 | } |
| 6420 | 6427 | ||
| @@ -6425,7 +6432,7 @@ sys_gethostbyname (const char * name) | |||
| 6425 | 6432 | ||
| 6426 | if (winsock_lib == NULL) | 6433 | if (winsock_lib == NULL) |
| 6427 | { | 6434 | { |
| 6428 | h_errno = ENETDOWN; | 6435 | errno = h_errno = ENETDOWN; |
| 6429 | return NULL; | 6436 | return NULL; |
| 6430 | } | 6437 | } |
| 6431 | 6438 | ||
| @@ -6443,7 +6450,7 @@ sys_getservbyname (const char * name, const char * proto) | |||
| 6443 | 6450 | ||
| 6444 | if (winsock_lib == NULL) | 6451 | if (winsock_lib == NULL) |
| 6445 | { | 6452 | { |
| 6446 | h_errno = ENETDOWN; | 6453 | errno = h_errno = ENETDOWN; |
| 6447 | return NULL; | 6454 | return NULL; |
| 6448 | } | 6455 | } |
| 6449 | 6456 | ||
| @@ -6459,7 +6466,7 @@ sys_getpeername (int s, struct sockaddr *addr, int * namelen) | |||
| 6459 | { | 6466 | { |
| 6460 | if (winsock_lib == NULL) | 6467 | if (winsock_lib == NULL) |
| 6461 | { | 6468 | { |
| 6462 | h_errno = ENETDOWN; | 6469 | errno = h_errno = ENETDOWN; |
| 6463 | return SOCKET_ERROR; | 6470 | return SOCKET_ERROR; |
| 6464 | } | 6471 | } |
| 6465 | 6472 | ||
| @@ -6471,7 +6478,7 @@ sys_getpeername (int s, struct sockaddr *addr, int * namelen) | |||
| 6471 | set_errno (); | 6478 | set_errno (); |
| 6472 | return rc; | 6479 | return rc; |
| 6473 | } | 6480 | } |
| 6474 | h_errno = ENOTSOCK; | 6481 | errno = h_errno = ENOTSOCK; |
| 6475 | return SOCKET_ERROR; | 6482 | return SOCKET_ERROR; |
| 6476 | } | 6483 | } |
| 6477 | 6484 | ||
| @@ -6480,7 +6487,7 @@ sys_shutdown (int s, int how) | |||
| 6480 | { | 6487 | { |
| 6481 | if (winsock_lib == NULL) | 6488 | if (winsock_lib == NULL) |
| 6482 | { | 6489 | { |
| 6483 | h_errno = ENETDOWN; | 6490 | errno = h_errno = ENETDOWN; |
| 6484 | return SOCKET_ERROR; | 6491 | return SOCKET_ERROR; |
| 6485 | } | 6492 | } |
| 6486 | 6493 | ||
| @@ -6492,7 +6499,7 @@ sys_shutdown (int s, int how) | |||
| 6492 | set_errno (); | 6499 | set_errno (); |
| 6493 | return rc; | 6500 | return rc; |
| 6494 | } | 6501 | } |
| 6495 | h_errno = ENOTSOCK; | 6502 | errno = h_errno = ENOTSOCK; |
| 6496 | return SOCKET_ERROR; | 6503 | return SOCKET_ERROR; |
| 6497 | } | 6504 | } |
| 6498 | 6505 | ||
| @@ -6501,7 +6508,7 @@ sys_setsockopt (int s, int level, int optname, const void * optval, int optlen) | |||
| 6501 | { | 6508 | { |
| 6502 | if (winsock_lib == NULL) | 6509 | if (winsock_lib == NULL) |
| 6503 | { | 6510 | { |
| 6504 | h_errno = ENETDOWN; | 6511 | errno = h_errno = ENETDOWN; |
| 6505 | return SOCKET_ERROR; | 6512 | return SOCKET_ERROR; |
| 6506 | } | 6513 | } |
| 6507 | 6514 | ||
| @@ -6514,7 +6521,7 @@ sys_setsockopt (int s, int level, int optname, const void * optval, int optlen) | |||
| 6514 | set_errno (); | 6521 | set_errno (); |
| 6515 | return rc; | 6522 | return rc; |
| 6516 | } | 6523 | } |
| 6517 | h_errno = ENOTSOCK; | 6524 | errno = h_errno = ENOTSOCK; |
| 6518 | return SOCKET_ERROR; | 6525 | return SOCKET_ERROR; |
| 6519 | } | 6526 | } |
| 6520 | 6527 | ||
| @@ -6523,7 +6530,7 @@ sys_listen (int s, int backlog) | |||
| 6523 | { | 6530 | { |
| 6524 | if (winsock_lib == NULL) | 6531 | if (winsock_lib == NULL) |
| 6525 | { | 6532 | { |
| 6526 | h_errno = ENETDOWN; | 6533 | errno = h_errno = ENETDOWN; |
| 6527 | return SOCKET_ERROR; | 6534 | return SOCKET_ERROR; |
| 6528 | } | 6535 | } |
| 6529 | 6536 | ||
| @@ -6537,7 +6544,7 @@ sys_listen (int s, int backlog) | |||
| 6537 | fd_info[s].flags |= FILE_LISTEN; | 6544 | fd_info[s].flags |= FILE_LISTEN; |
| 6538 | return rc; | 6545 | return rc; |
| 6539 | } | 6546 | } |
| 6540 | h_errno = ENOTSOCK; | 6547 | errno = h_errno = ENOTSOCK; |
| 6541 | return SOCKET_ERROR; | 6548 | return SOCKET_ERROR; |
| 6542 | } | 6549 | } |
| 6543 | 6550 | ||
| @@ -6546,7 +6553,7 @@ sys_getsockname (int s, struct sockaddr * name, int * namelen) | |||
| 6546 | { | 6553 | { |
| 6547 | if (winsock_lib == NULL) | 6554 | if (winsock_lib == NULL) |
| 6548 | { | 6555 | { |
| 6549 | h_errno = ENETDOWN; | 6556 | errno = h_errno = ENETDOWN; |
| 6550 | return SOCKET_ERROR; | 6557 | return SOCKET_ERROR; |
| 6551 | } | 6558 | } |
| 6552 | 6559 | ||
| @@ -6558,7 +6565,7 @@ sys_getsockname (int s, struct sockaddr * name, int * namelen) | |||
| 6558 | set_errno (); | 6565 | set_errno (); |
| 6559 | return rc; | 6566 | return rc; |
| 6560 | } | 6567 | } |
| 6561 | h_errno = ENOTSOCK; | 6568 | errno = h_errno = ENOTSOCK; |
| 6562 | return SOCKET_ERROR; | 6569 | return SOCKET_ERROR; |
| 6563 | } | 6570 | } |
| 6564 | 6571 | ||
| @@ -6567,7 +6574,7 @@ sys_accept (int s, struct sockaddr * addr, int * addrlen) | |||
| 6567 | { | 6574 | { |
| 6568 | if (winsock_lib == NULL) | 6575 | if (winsock_lib == NULL) |
| 6569 | { | 6576 | { |
| 6570 | h_errno = ENETDOWN; | 6577 | errno = h_errno = ENETDOWN; |
| 6571 | return -1; | 6578 | return -1; |
| 6572 | } | 6579 | } |
| 6573 | 6580 | ||
| @@ -6579,13 +6586,20 @@ sys_accept (int s, struct sockaddr * addr, int * addrlen) | |||
| 6579 | if (t == INVALID_SOCKET) | 6586 | if (t == INVALID_SOCKET) |
| 6580 | set_errno (); | 6587 | set_errno (); |
| 6581 | else | 6588 | else |
| 6582 | fd = socket_to_fd (t); | 6589 | { |
| 6590 | fd = socket_to_fd (t); | ||
| 6591 | if (fd < 0) | ||
| 6592 | errno = h_errno; /* socket_to_fd sets h_errno */ | ||
| 6593 | } | ||
| 6583 | 6594 | ||
| 6584 | fd_info[s].cp->status = STATUS_READ_ACKNOWLEDGED; | 6595 | if (fd >= 0) |
| 6585 | ResetEvent (fd_info[s].cp->char_avail); | 6596 | { |
| 6597 | fd_info[s].cp->status = STATUS_READ_ACKNOWLEDGED; | ||
| 6598 | ResetEvent (fd_info[s].cp->char_avail); | ||
| 6599 | } | ||
| 6586 | return fd; | 6600 | return fd; |
| 6587 | } | 6601 | } |
| 6588 | h_errno = ENOTSOCK; | 6602 | errno = h_errno = ENOTSOCK; |
| 6589 | return -1; | 6603 | return -1; |
| 6590 | } | 6604 | } |
| 6591 | 6605 | ||
| @@ -6595,7 +6609,7 @@ sys_recvfrom (int s, char * buf, int len, int flags, | |||
| 6595 | { | 6609 | { |
| 6596 | if (winsock_lib == NULL) | 6610 | if (winsock_lib == NULL) |
| 6597 | { | 6611 | { |
| 6598 | h_errno = ENETDOWN; | 6612 | errno = h_errno = ENETDOWN; |
| 6599 | return SOCKET_ERROR; | 6613 | return SOCKET_ERROR; |
| 6600 | } | 6614 | } |
| 6601 | 6615 | ||
| @@ -6607,7 +6621,7 @@ sys_recvfrom (int s, char * buf, int len, int flags, | |||
| 6607 | set_errno (); | 6621 | set_errno (); |
| 6608 | return rc; | 6622 | return rc; |
| 6609 | } | 6623 | } |
| 6610 | h_errno = ENOTSOCK; | 6624 | errno = h_errno = ENOTSOCK; |
| 6611 | return SOCKET_ERROR; | 6625 | return SOCKET_ERROR; |
| 6612 | } | 6626 | } |
| 6613 | 6627 | ||
| @@ -6617,7 +6631,7 @@ sys_sendto (int s, const char * buf, int len, int flags, | |||
| 6617 | { | 6631 | { |
| 6618 | if (winsock_lib == NULL) | 6632 | if (winsock_lib == NULL) |
| 6619 | { | 6633 | { |
| 6620 | h_errno = ENETDOWN; | 6634 | errno = h_errno = ENETDOWN; |
| 6621 | return SOCKET_ERROR; | 6635 | return SOCKET_ERROR; |
| 6622 | } | 6636 | } |
| 6623 | 6637 | ||
| @@ -6629,7 +6643,7 @@ sys_sendto (int s, const char * buf, int len, int flags, | |||
| 6629 | set_errno (); | 6643 | set_errno (); |
| 6630 | return rc; | 6644 | return rc; |
| 6631 | } | 6645 | } |
| 6632 | h_errno = ENOTSOCK; | 6646 | errno = h_errno = ENOTSOCK; |
| 6633 | return SOCKET_ERROR; | 6647 | return SOCKET_ERROR; |
| 6634 | } | 6648 | } |
| 6635 | 6649 | ||
| @@ -6640,7 +6654,7 @@ fcntl (int s, int cmd, int options) | |||
| 6640 | { | 6654 | { |
| 6641 | if (winsock_lib == NULL) | 6655 | if (winsock_lib == NULL) |
| 6642 | { | 6656 | { |
| 6643 | h_errno = ENETDOWN; | 6657 | errno = h_errno = ENETDOWN; |
| 6644 | return -1; | 6658 | return -1; |
| 6645 | } | 6659 | } |
| 6646 | 6660 | ||
| @@ -6663,7 +6677,7 @@ fcntl (int s, int cmd, int options) | |||
| 6663 | return SOCKET_ERROR; | 6677 | return SOCKET_ERROR; |
| 6664 | } | 6678 | } |
| 6665 | } | 6679 | } |
| 6666 | h_errno = ENOTSOCK; | 6680 | errno = h_errno = ENOTSOCK; |
| 6667 | return SOCKET_ERROR; | 6681 | return SOCKET_ERROR; |
| 6668 | } | 6682 | } |
| 6669 | 6683 | ||
| @@ -6800,6 +6814,7 @@ sys_pipe (int * phandles) | |||
| 6800 | { | 6814 | { |
| 6801 | _close (phandles[0]); | 6815 | _close (phandles[0]); |
| 6802 | _close (phandles[1]); | 6816 | _close (phandles[1]); |
| 6817 | errno = EMFILE; | ||
| 6803 | rc = -1; | 6818 | rc = -1; |
| 6804 | } | 6819 | } |
| 6805 | else | 6820 | else |
| @@ -6873,19 +6888,31 @@ _sys_read_ahead (int fd) | |||
| 6873 | 6888 | ||
| 6874 | /* Configure timeouts for blocking read. */ | 6889 | /* Configure timeouts for blocking read. */ |
| 6875 | if (!GetCommTimeouts (hnd, &ct)) | 6890 | if (!GetCommTimeouts (hnd, &ct)) |
| 6876 | return STATUS_READ_ERROR; | 6891 | { |
| 6892 | cp->status = STATUS_READ_ERROR; | ||
| 6893 | return STATUS_READ_ERROR; | ||
| 6894 | } | ||
| 6877 | ct.ReadIntervalTimeout = 0; | 6895 | ct.ReadIntervalTimeout = 0; |
| 6878 | ct.ReadTotalTimeoutMultiplier = 0; | 6896 | ct.ReadTotalTimeoutMultiplier = 0; |
| 6879 | ct.ReadTotalTimeoutConstant = 0; | 6897 | ct.ReadTotalTimeoutConstant = 0; |
| 6880 | if (!SetCommTimeouts (hnd, &ct)) | 6898 | if (!SetCommTimeouts (hnd, &ct)) |
| 6881 | return STATUS_READ_ERROR; | 6899 | { |
| 6900 | cp->status = STATUS_READ_ERROR; | ||
| 6901 | return STATUS_READ_ERROR; | ||
| 6902 | } | ||
| 6882 | 6903 | ||
| 6883 | if (!ReadFile (hnd, &cp->chr, sizeof (char), (DWORD*) &rc, ovl)) | 6904 | if (!ReadFile (hnd, &cp->chr, sizeof (char), (DWORD*) &rc, ovl)) |
| 6884 | { | 6905 | { |
| 6885 | if (GetLastError () != ERROR_IO_PENDING) | 6906 | if (GetLastError () != ERROR_IO_PENDING) |
| 6886 | return STATUS_READ_ERROR; | 6907 | { |
| 6908 | cp->status = STATUS_READ_ERROR; | ||
| 6909 | return STATUS_READ_ERROR; | ||
| 6910 | } | ||
| 6887 | if (!GetOverlappedResult (hnd, ovl, (DWORD*) &rc, TRUE)) | 6911 | if (!GetOverlappedResult (hnd, ovl, (DWORD*) &rc, TRUE)) |
| 6888 | return STATUS_READ_ERROR; | 6912 | { |
| 6913 | cp->status = STATUS_READ_ERROR; | ||
| 6914 | return STATUS_READ_ERROR; | ||
| 6915 | } | ||
| 6889 | } | 6916 | } |
| 6890 | } | 6917 | } |
| 6891 | else if (fd_info[fd].flags & FILE_SOCKET) | 6918 | else if (fd_info[fd].flags & FILE_SOCKET) |