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

ruby-changes:40020

From: nobu <ko1@a...>
Date: Sat, 10 Oct 2015 19:04:54 +0900 (JST)
Subject: [ruby-changes:40020] nobu:r52101 (trunk): udpsocket.c: refix r52097

nobu	2015-10-10 19:04:44 +0900 (Sat, 10 Oct 2015)

  New Revision: 52101

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

  Log:
    udpsocket.c: refix r52097
    
    * ext/socket/udpsocket.c (udp_connect, udp_bind): get open files
      inside ensure functions.

  Modified files:
    trunk/ChangeLog
    trunk/ext/socket/udpsocket.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 52100)
+++ ChangeLog	(revision 52101)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Oct 10 19:04:42 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* ext/socket/udpsocket.c (udp_connect, udp_bind): get open files
+	  inside ensure functions.
+
 Sat Oct 10 18:35:12 2015  Koichi Sasada  <ko1@a...>
 
 	* vm_insnhelper.c (vm_call_method0): do not propagate enable_fastpath,
Index: ext/socket/udpsocket.c
===================================================================
--- ext/socket/udpsocket.c	(revision 52100)
+++ ext/socket/udpsocket.c	(revision 52101)
@@ -44,15 +44,18 @@ udp_init(int argc, VALUE *argv, VALUE so https://github.com/ruby/ruby/blob/trunk/ext/socket/udpsocket.c#L44
 struct udp_arg
 {
     struct rb_addrinfo *res;
-    int fd;
+    VALUE io;
 };
 
 static VALUE
 udp_connect_internal(struct udp_arg *arg)
 {
-    int fd = arg->fd;
+    rb_io_t *fptr;
+    int fd;
     struct addrinfo *res;
 
+    GetOpenFile(arg->io, fptr);
+    fd = fptr->fd;
     for (res = arg->res->ai; res; res = res->ai_next) {
 	if (rsock_connect(fd, res->ai_addr, res->ai_addrlen, 0) >= 0) {
 	    return Qtrue;
@@ -80,19 +83,35 @@ udp_connect_internal(struct udp_arg *arg https://github.com/ruby/ruby/blob/trunk/ext/socket/udpsocket.c#L83
 static VALUE
 udp_connect(VALUE sock, VALUE host, VALUE port)
 {
-    rb_io_t *fptr;
     struct udp_arg arg;
     VALUE ret;
 
-    GetOpenFile(sock, fptr);
+    arg.io = sock;
     arg.res = rsock_addrinfo(host, port, SOCK_DGRAM, 0);
-    arg.fd = fptr->fd;
     ret = rb_ensure(udp_connect_internal, (VALUE)&arg,
 		    rsock_freeaddrinfo, (VALUE)arg.res);
     if (!ret) rsock_sys_fail_host_port("connect(2)", host, port);
     return INT2FIX(0);
 }
 
+static VALUE
+udp_bind_internal(struct udp_arg *arg)
+{
+    rb_io_t *fptr;
+    int fd;
+    struct addrinfo *res;
+
+    GetOpenFile(arg->io, fptr);
+    fd = fptr->fd;
+    for (res = arg->res->ai; res; res = res->ai_next) {
+	if (bind(fd, res->ai_addr, res->ai_addrlen) < 0) {
+	    continue;
+	}
+	return Qtrue;
+    }
+    return Qfalse;
+}
+
 /*
  * call-seq:
  *   udpsocket.bind(host, port) #=> 0
@@ -108,22 +127,14 @@ udp_connect(VALUE sock, VALUE host, VALU https://github.com/ruby/ruby/blob/trunk/ext/socket/udpsocket.c#L127
 static VALUE
 udp_bind(VALUE sock, VALUE host, VALUE port)
 {
-    rb_io_t *fptr;
-    struct rb_addrinfo *res0;
-    struct addrinfo *res;
-
-    GetOpenFile(sock, fptr);
-    res0 = rsock_addrinfo(host, port, SOCK_DGRAM, 0);
-    for (res = res0->ai; res; res = res->ai_next) {
-	if (bind(fptr->fd, res->ai_addr, res->ai_addrlen) < 0) {
-	    continue;
-	}
-	rb_freeaddrinfo(res0);
-	return INT2FIX(0);
-    }
-    rb_freeaddrinfo(res0);
+    struct udp_arg arg;
+    VALUE ret;
 
-    rsock_sys_fail_host_port("bind(2)", host, port);
+    arg.io = sock;
+    arg.res = rsock_addrinfo(host, port, SOCK_DGRAM, 0);
+    ret = rb_ensure(udp_bind_internal, (VALUE)&arg,
+		    rsock_freeaddrinfo, (VALUE)arg.res);
+    if (!ret) rsock_sys_fail_host_port("bind(2)", host, port);
 
     return INT2FIX(0);
 }

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

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