[前][次][番号順一覧][スレッド一覧]

ruby-changes:23886

From: usa <ko1@a...>
Date: Wed, 6 Jun 2012 13:29:49 +0900 (JST)
Subject: [ruby-changes:23886] usa:r35937 (trunk): * win32/win32.c, include/ruby/win32.h (rb_w32_wrap_io_handle): new API.

usa	2012-06-06 13:29:38 +0900 (Wed, 06 Jun 2012)

  New Revision: 35937

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=35937

  Log:
    * win32/win32.c, include/ruby/win32.h (rb_w32_wrap_io_handle): new API.
      this API wraps an I/O handle (HANDLE or SOCKET) and returns fd.
      the second parameter should be combination of O_*, for example,
      O_RDWR | O_BINARY | O_NOINHERT.
    
    * win32/win32.c, include/ruby/win32.h (rb_w32_unwrap_io_handle): new
      API.  this API unwraps an I/O handle and close the fd (not closes
      the handle itself).
    
    [Feature #4960] [ruby-core:37227]

  Modified files:
    trunk/ChangeLog
    trunk/include/ruby/win32.h
    trunk/win32/win32.c

Index: include/ruby/win32.h
===================================================================
--- include/ruby/win32.h	(revision 35936)
+++ include/ruby/win32.h	(revision 35937)
@@ -726,6 +726,8 @@
 int  WINAPI rb_w32_Sleep(unsigned long msec);
 int  rb_w32_wait_events_blocking(HANDLE *events, int num, DWORD timeout);
 int  rb_w32_time_subtract(struct timeval *rest, const struct timeval *wait);
+int  rb_w32_wrap_io_handle(HANDLE, int);
+int  rb_w32_unwrap_io_handle(int);
 
 /*
 == ***CAUTION***
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 35936)
+++ ChangeLog	(revision 35937)
@@ -1,3 +1,16 @@
+Wed Jun  6 13:25:04 2012  NAKAMURA Usaku  <usa@r...>
+
+	* win32/win32.c, include/ruby/win32.h (rb_w32_wrap_io_handle): new API.
+	  this API wraps an I/O handle (HANDLE or SOCKET) and returns fd.
+	  the second parameter should be combination of O_*, for example,
+	  O_RDWR | O_BINARY | O_NOINHERT.
+
+	* win32/win32.c, include/ruby/win32.h (rb_w32_unwrap_io_handle): new
+	  API.  this API unwraps an I/O handle and close the fd (not closes
+	  the handle itself).
+
+	[Feature #4960] [ruby-core:37227]
+
 Wed Jun  6 13:18:26 2012  NAKAMURA Usaku  <usa@r...>
 
 	* win32/win32.c (rb_w32_close): of course, console handle is not socket.
Index: win32/win32.c
===================================================================
--- win32/win32.c	(revision 35936)
+++ win32/win32.c	(revision 35937)
@@ -6747,3 +6747,41 @@
 #endif
     return rp;
 }
+
+/* License: Ruby's */
+int
+rb_w32_wrap_io_handle(HANDLE h, int flags)
+{
+    BOOL tmp;
+    int len = sizeof(tmp);
+    int r = getsockopt((SOCKET)h, SOL_SOCKET, SO_DEBUG, (char *)&tmp, &len);
+    if (r != SOCKET_ERROR || WSAGetLastError() != WSAENOTSOCK) {
+        int f = 0;
+        if (flags & O_NONBLOCK) {
+            flags &= ~O_NONBLOCK;
+            f = O_NONBLOCK;
+        }
+        socklist_insert((SOCKET)h, f);
+    }
+    else if (flags & O_NONBLOCK) {
+        errno = EINVAL;
+        return -1;
+    }
+    return rb_w32_open_osfhandle((intptr_t)h, flags);
+}
+
+/* License: Ruby's */
+int
+rb_w32_unwrap_io_handle(int fd)
+{
+    SOCKET sock = TO_SOCKET(fd);
+    _set_osfhnd(fd, (SOCKET)INVALID_HANDLE_VALUE);
+    if (!is_socket(sock)) {
+	UnlockFile((HANDLE)sock, 0, 0, LK_LEN, LK_LEN);
+	constat_delete((HANDLE)sock);
+    }
+    else {
+	socklist_delete(&sock, NULL);
+    }
+    return _close(fd);
+}

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]