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

ruby-changes:40524

From: nobu <ko1@a...>
Date: Tue, 17 Nov 2015 11:16:18 +0900 (JST)
Subject: [ruby-changes:40524] nobu:r52605 (trunk): init.c: is_socket

nobu	2015-11-17 11:15:55 +0900 (Tue, 17 Nov 2015)

  New Revision: 52605

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

  Log:
    init.c: is_socket
    
    * ext/socket/init.c (is_socket): extract predicate to see if the
      given fd is a socket.

  Modified files:
    trunk/ext/socket/init.c
Index: ext/socket/init.c
===================================================================
--- ext/socket/init.c	(revision 52604)
+++ ext/socket/init.c	(revision 52605)
@@ -42,23 +42,28 @@ rsock_raise_socket_error(const char *rea https://github.com/ruby/ruby/blob/trunk/ext/socket/init.c#L42
     rb_raise(rb_eSocket, "%s: %s", reason, gai_strerror(error));
 }
 
-VALUE
-rsock_init_sock(VALUE sock, int fd)
+#ifdef _WIN32
+#define is_socket(fd) rb_w32_is_socket(fd)
+#else
+static int
+is_socket(int fd)
 {
-    rb_io_t *fp;
-#ifndef _WIN32
     struct stat sbuf;
 
     if (fstat(fd, &sbuf) < 0)
         rb_sys_fail("fstat(2)");
+    return S_ISSOCK(sbuf.st_mode);
+}
+#endif
+
+VALUE
+rsock_init_sock(VALUE sock, int fd)
+{
+    rb_io_t *fp;
+
     rb_update_max_fd(fd);
-    if (!S_ISSOCK(sbuf.st_mode))
-        rb_raise(rb_eArgError, "not a socket file descriptor");
-#else
-    rb_update_max_fd(fd);
-    if (!rb_w32_is_socket(fd))
+    if (!is_socket(fd))
         rb_raise(rb_eArgError, "not a socket file descriptor");
-#endif
 
     MakeOpenFile(sock, fp);
     fp->fd = fd;

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

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