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

ruby-changes:40030

From: nobu <ko1@a...>
Date: Mon, 12 Oct 2015 09:11:48 +0900 (JST)
Subject: [ruby-changes:40030] nobu:r52111 (trunk): udpsocket.c: check once first

nobu	2015-10-12 09:11:37 +0900 (Mon, 12 Oct 2015)

  New Revision: 52111

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

  Log:
    udpsocket.c: check once first
    
    * ext/socket/udpsocket.c (udp_connect, udp_bind): check if the
      socket is opened once before retreiving address infos.

  Modified files:
    trunk/ext/socket/udpsocket.c
Index: ext/socket/udpsocket.c
===================================================================
--- ext/socket/udpsocket.c	(revision 52110)
+++ ext/socket/udpsocket.c	(revision 52111)
@@ -44,7 +44,7 @@ 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;
-    VALUE io;
+    rb_io_t *fptr;
 };
 
 static VALUE
@@ -54,7 +54,7 @@ udp_connect_internal(struct udp_arg *arg https://github.com/ruby/ruby/blob/trunk/ext/socket/udpsocket.c#L54
     int fd;
     struct addrinfo *res;
 
-    GetOpenFile(arg->io, fptr);
+    rb_io_check_closed(fptr = arg->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) {
@@ -86,7 +86,7 @@ udp_connect(VALUE sock, VALUE host, VALU https://github.com/ruby/ruby/blob/trunk/ext/socket/udpsocket.c#L86
     struct udp_arg arg;
     VALUE ret;
 
-    arg.io = sock;
+    GetOpenFile(sock, arg.fptr);
     arg.res = rsock_addrinfo(host, port, SOCK_DGRAM, 0);
     ret = rb_ensure(udp_connect_internal, (VALUE)&arg,
 		    rsock_freeaddrinfo, (VALUE)arg.res);
@@ -101,7 +101,7 @@ udp_bind_internal(struct udp_arg *arg) https://github.com/ruby/ruby/blob/trunk/ext/socket/udpsocket.c#L101
     int fd;
     struct addrinfo *res;
 
-    GetOpenFile(arg->io, fptr);
+    rb_io_check_closed(fptr = arg->fptr);
     fd = fptr->fd;
     for (res = arg->res->ai; res; res = res->ai_next) {
 	if (bind(fd, res->ai_addr, res->ai_addrlen) < 0) {
@@ -130,12 +130,11 @@ udp_bind(VALUE sock, VALUE host, VALUE p https://github.com/ruby/ruby/blob/trunk/ext/socket/udpsocket.c#L130
     struct udp_arg arg;
     VALUE ret;
 
-    arg.io = sock;
+    GetOpenFile(sock, arg.fptr);
     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/

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