diff options
author | Eli Zaretskii <eliz@gnu.org> | 2015-03-27 12:44:31 +0300 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2015-03-27 12:44:31 +0300 |
commit | d133cf839421462280ac0bfd9bd84c591f0e0249 (patch) | |
tree | d964223f8da827058aece69ed66ca25ba82ebbf4 /src/w32.h | |
parent | 792d44b3c31d2a682607ab8b79ae7d26b7402f41 (diff) | |
download | emacs-d133cf839421462280ac0bfd9bd84c591f0e0249.tar.gz |
Support non-blocking connect on MS-Windows (Bug#20207)
Based on ideas from Kim F. Storm <storm@cua.dk>, see
http://lists.gnu.org/archive/html/emacs-devel/2006-12/msg00873.html.
src/w32proc.c (reader_thread): If the FILE_CONNECT flag is set, call
'_sys_wait_connect'. If it returns STATUS_CONNECT_FAILED, exit
the thread with code 2.
(sys_select): Support 'wfds' in addition to 'rfds'. If a
descriptor in 'wfds' has its bit set, but the corresponding
fd_info member doesn't have its FILE_CONNECT flag set, ignore the
descriptor. Otherwise, acknowledge a successful non-blocking
connect by resetting the FILE_CONNECT flag and setting cp->status
to STATUS_READ_ACKNOWLEDGED.
src/w32.h (STATUS_CONNECT_FAILED): New enumeration value.
(struct _child_process): New member 'errcode'.
(FILE_CONNECT): New flag.
(_sys_wait_connect): Add prototype.
src/w32.c (pfn_WSAEnumNetworkEvents): New function pointer.
(init_winsock): Load WSAEnumNetworkEvents from winsock DLL.
(set_errno): Map WSAEWOULDBLOCK and WSAENOTCONN.
(sys_connect): Support non-blocking 'connect' calls by setting the
FILE_CONNECT flag in the fd_info member and returning EINPROGRESS.
(_sys_read_ahead): Add debug message if this function is called
for a descriptor that waits for a non-blocking connect to complete.
(_sys_wait_connect): New function.
(sys_read): Support STATUS_CONNECT_FAILED. Return the error code
recorded by _sys_wait_connect when the non-blocking connect
failed. Don't call WSAGetLastError before a call to set_errno had
a chance to use its value, since WSAGetLastError clears the last
error.
nt/inc/ms-w32.h (BROKEN_NON_BLOCKING_CONNECT): Don't define.
Diffstat (limited to 'src/w32.h')
-rw-r--r-- | src/w32.h | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/w32.h b/src/w32.h index 835557d5ec7..9b3521d077f 100644 --- a/src/w32.h +++ b/src/w32.h @@ -61,7 +61,8 @@ enum { STATUS_READ_IN_PROGRESS, STATUS_READ_FAILED, STATUS_READ_SUCCEEDED, - STATUS_READ_ACKNOWLEDGED + STATUS_READ_ACKNOWLEDGED, + STATUS_CONNECT_FAILED }; /* This structure is used for both pipes and sockets; for @@ -96,6 +97,8 @@ typedef struct _child_process /* Status of subprocess/connection and of reading its output. For values, see the enumeration above. */ volatile int status; + /* Used to store errno value of failed async 'connect' calls. */ + volatile int errcode; /* Holds a single character read by _sys_read_ahead, when a subprocess has some output ready. */ char chr; @@ -122,7 +125,8 @@ extern filedesc fd_info [ MAXDESC ]; /* fd_info flag definitions */ #define FILE_READ 0x0001 #define FILE_WRITE 0x0002 -#define FILE_LISTEN 0x0004 +#define FILE_LISTEN 0x0004 +#define FILE_CONNECT 0x0008 #define FILE_BINARY 0x0010 #define FILE_LAST_CR 0x0020 #define FILE_AT_EOF 0x0040 @@ -171,6 +175,7 @@ extern void init_timers (void); extern int _sys_read_ahead (int fd); extern int _sys_wait_accept (int fd); +extern int _sys_wait_connect (int fd); extern HMODULE w32_delayed_load (Lisp_Object); |