From e8a03f98f83d0592edae30e58c365cdcdf84f3ad 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: http://svn.ruby-lang.org/repos/ruby/trunk@18157 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- win32/win32.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'win32') diff --git a/win32/win32.c b/win32/win32.c index f6ef84328..dea612e03 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