From ee560dc68f363f0502349cd35f1fd06a05693c9e Mon Sep 17 00:00:00 2001 From: usa Date: Tue, 22 Jul 2008 08:22:32 +0000 Subject: * 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 --- ChangeLog | 8 ++++++++ win32/win32.c | 33 +++++++++++++++------------------ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index a9e370f9a6..a4f0f93522 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Tue Jul 22 17:20:25 2008 NAKAMURA Usaku + + * 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. + Tue Jul 22 16:47:57 2008 Nobuyoshi Nakada * include/ruby/intern.h, sprintf.c (rb_str_catf, rb_str_vcatf): new 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) -- cgit v1.2.3