diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-09-07 03:52:15 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-09-07 03:52:15 +0000 |
commit | f4d60b5f6370651978316dcecf8160781190f91f (patch) | |
tree | 06771a9d092ce8afad5105d6394882ff65c60b74 /win32/win32.c | |
parent | 70f8c054b2dad9f7f5af7444fa98bfac541b216b (diff) | |
download | ruby-f4d60b5f6370651978316dcecf8160781190f91f.tar.gz |
* {bcc32,win32,wince}/Makefile.sub (config.h): add fcntl.
* win32/win32.[ch] (fcntl): ditto.
* win32/win32.c (rb_w32_connect): support nonblocking mode.
* ext/socket/socket.c (wait_connectable, ruby_connect): support
nonblocking connect on various platforms.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6863 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32/win32.c')
-rw-r--r-- | win32/win32.c | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/win32/win32.c b/win32/win32.c index 4203ca2aba..7c5e283356 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -2047,8 +2047,16 @@ rb_w32_connect(int s, struct sockaddr *addr, int addrlen) } RUBY_CRITICAL({ r = connect(TO_SOCKET(s), addr, addrlen); - if (r == SOCKET_ERROR) - errno = map_errno(WSAGetLastError()); + if (r == SOCKET_ERROR) { + r = WSAGetLastError(); + if (r != WSAEWOULDBLOCK) { + errno = map_errno(r); + } + else { + errno = EINPROGRESS; + r = -1; + } + } }); return r; } @@ -2411,6 +2419,43 @@ void setprotoent (int stayopen) {} void setservent (int stayopen) {} +int +fcntl(int fd, int cmd, ...) +{ + SOCKET sock = TO_SOCKET(fd); + va_list va; + int arg; + int ret; + u_long ioctlArg; + + if (!is_socket(sock)) { + errno = EBADF; + return -1; + } + if (cmd != F_SETFL) { + errno = EINVAL; + return -1; + } + + va_start(va, cmd); + arg = va_arg(va, int); + va_end(va); + if (arg & O_NONBLOCK) { + ioctlArg = 1; + } + else { + ioctlArg = 0; + } + RUBY_CRITICAL({ + ret = ioctlsocket(sock, FIONBIO, &ioctlArg); + if (ret == -1) { + errno = map_errno(WSAGetLastError()); + } + }); + + return ret; +} + #ifndef WNOHANG #define WNOHANG -1 #endif |