diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-07-22 08:22:32 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-07-22 08:22:32 +0000 |
commit | ee560dc68f363f0502349cd35f1fd06a05693c9e (patch) | |
tree | 178b0469553ff20643d3102880c64646e7a4f708 /win32/win32.c | |
parent | 70b317b9dababf3527deba01544e157f1c87375d (diff) | |
download | ruby-ee560dc68f363f0502349cd35f1fd06a05693c9e.tar.gz |
* win32/win32.c (init_func): new function to get API's address which
is often used and not supported on all Windows.
* win32/win32.c (overlapped_socket_io): shouldn't use overlapped I/O if
CancelIo() is not supported.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18157 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32/win32.c')
-rw-r--r-- | win32/win32.c | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/win32/win32.c b/win32/win32.c index f6ef84328b..dea612e038 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -408,6 +408,18 @@ init_env(void) NTLoginName = strdup(env); } + +typedef BOOL (WINAPI *cancel_io_t)(HANDLE); +static cancel_io_t cancel_io = NULL; + +static void +init_func(void) +{ + if (!cancel_io) + cancel_io = (cancel_io_t)GetProcAddress(GetModuleHandle("kernel32"), + "CancelIo"); +} + static void init_stdhandle(void); #if _MSC_VER >= 1400 @@ -485,6 +497,8 @@ rb_w32_sysinit(int *argc, char ***argv) init_env(); + init_func(); + init_stdhandle(); InitializeCriticalSection(&select_mutex); @@ -2392,23 +2406,6 @@ rb_w32_listen(int s, int backlog) return r; } -typedef BOOL (WINAPI *cancel_io_t)(HANDLE); -static inline void -cancel_io(HANDLE f) -{ - static cancel_io_t func = NULL; - if (!func) { - func = (cancel_io_t)GetProcAddress(GetModuleHandle("kernel32"), - "CancelIo"); - if (!func) - func = (cancel_io_t)-1; - } - else if (func != (cancel_io_t)-1) - func(f); - /* Win9x and NT3.x doesn't have CancelIo(). - We expect to cancel the I/O by close or ending the thread */ -} - #undef recv #undef recvfrom #undef send @@ -2432,7 +2429,7 @@ overlapped_socket_io(BOOL input, int fd, char *buf, int len, int flags, s = TO_SOCKET(fd); st_lookup(socklist, (st_data_t)s, (st_data_t *)&mode); - if (mode & O_NONBLOCK) { + if (!cancel_io || (mode & O_NONBLOCK)) { RUBY_CRITICAL({ if (input) { if (addr && addrlen) |