diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/w32.c | 34 |
1 files changed, 26 insertions, 8 deletions
| @@ -8772,6 +8772,30 @@ sys_write (int fd, const void * buffer, unsigned int count) | |||
| 8772 | unsigned long nblock = 0; | 8772 | unsigned long nblock = 0; |
| 8773 | if (winsock_lib == NULL) emacs_abort (); | 8773 | if (winsock_lib == NULL) emacs_abort (); |
| 8774 | 8774 | ||
| 8775 | child_process *cp = fd_info[fd].cp; | ||
| 8776 | |||
| 8777 | /* If this is a non-blocking socket whose connection is in | ||
| 8778 | progress or terminated with an error already, return the | ||
| 8779 | proper error code to the caller. */ | ||
| 8780 | if (cp != NULL && (fd_info[fd].flags & FILE_CONNECT) != 0) | ||
| 8781 | { | ||
| 8782 | /* In case connection is in progress, ENOTCONN that would | ||
| 8783 | result from calling pfn_send is not what callers expect. */ | ||
| 8784 | if (cp->status != STATUS_CONNECT_FAILED) | ||
| 8785 | { | ||
| 8786 | errno = EWOULDBLOCK; | ||
| 8787 | return -1; | ||
| 8788 | } | ||
| 8789 | /* In case connection failed, use the actual error code | ||
| 8790 | stashed by '_sys_wait_connect' in cp->errcode. */ | ||
| 8791 | else if (cp->errcode != 0) | ||
| 8792 | { | ||
| 8793 | pfn_WSASetLastError (cp->errcode); | ||
| 8794 | set_errno (); | ||
| 8795 | return -1; | ||
| 8796 | } | ||
| 8797 | } | ||
| 8798 | |||
| 8775 | /* TODO: implement select() properly so non-blocking I/O works. */ | 8799 | /* TODO: implement select() properly so non-blocking I/O works. */ |
| 8776 | /* For now, make sure the write blocks. */ | 8800 | /* For now, make sure the write blocks. */ |
| 8777 | if (fd_info[fd].flags & FILE_NDELAY) | 8801 | if (fd_info[fd].flags & FILE_NDELAY) |
| @@ -8782,14 +8806,8 @@ sys_write (int fd, const void * buffer, unsigned int count) | |||
| 8782 | if (nchars == SOCKET_ERROR) | 8806 | if (nchars == SOCKET_ERROR) |
| 8783 | { | 8807 | { |
| 8784 | set_errno (); | 8808 | set_errno (); |
| 8785 | /* If this is a non-blocking socket whose connection is in | 8809 | DebPrint (("sys_write.send failed with error %d on socket %ld\n", |
| 8786 | progress, return the proper error code to the caller; | 8810 | pfn_WSAGetLastError (), SOCK_HANDLE (fd))); |
| 8787 | ENOTCONN is not what they expect . */ | ||
| 8788 | if (errno == ENOTCONN && (fd_info[fd].flags & FILE_CONNECT) != 0) | ||
| 8789 | errno = EWOULDBLOCK; | ||
| 8790 | else | ||
| 8791 | DebPrint (("sys_write.send failed with error %d on socket %ld\n", | ||
| 8792 | pfn_WSAGetLastError (), SOCK_HANDLE (fd))); | ||
| 8793 | } | 8811 | } |
| 8794 | 8812 | ||
| 8795 | /* Set the socket back to non-blocking if it was before, | 8813 | /* Set the socket back to non-blocking if it was before, |