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

ruby-changes:38266

From: normal <ko1@a...>
Date: Mon, 20 Apr 2015 11:11:27 +0900 (JST)
Subject: [ruby-changes:38266] normal:r50347 (trunk): connect_nonblock(..., exception: false) does not raise EISCONN

normal	2015-04-20 11:11:10 +0900 (Mon, 20 Apr 2015)

  New Revision: 50347

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

  Log:
    connect_nonblock(..., exception: false) does not raise EISCONN
    
    * ext/socket/socket.c (sock_connect_nonblock): do not raise EISCONN
      [ruby-core:68926] [Feature #11072]
    * test/socket/test_nonblock.rb: check non-EISCONN on 2nd connect
    
    This is to reduce exceptions for code which issues a
    (IMHO, unnecessary) second connect() syscall.

  Modified files:
    trunk/ChangeLog
    trunk/ext/socket/socket.c
    trunk/test/socket/test_nonblock.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 50346)
+++ ChangeLog	(revision 50347)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Apr 20 11:10:46 2015  Eric Wong  <e@8...>
+
+	* ext/socket/socket.c (sock_connect_nonblock): do not raise EISCONN
+	  [ruby-core:68926] [Feature #11072]
+	* test/socket/test_nonblock.rb: check non-EISCONN on 2nd connect
+
 Sun Apr 19 12:19:17 2015  Chad Brewbaker  <crb002@g...>
 
 	* ext/{etc,openssl,tk}: Adding parens and comparisons around
Index: ext/socket/socket.c
===================================================================
--- ext/socket/socket.c	(revision 50346)
+++ ext/socket/socket.c	(revision 50347)
@@ -509,6 +509,12 @@ sock_connect_nonblock(int argc, VALUE *a https://github.com/ruby/ruby/blob/trunk/ext/socket/socket.c#L509
             }
             rb_readwrite_sys_fail(RB_IO_WAIT_WRITABLE, "connect(2) would block");
 	}
+	if (errno == EISCONN) {
+            if (!NIL_P(opts) &&
+                    Qfalse == rb_hash_lookup2(opts, sym_exception, Qundef)) {
+                return INT2FIX(0);
+            }
+	}
 	rsock_sys_fail_raddrinfo_or_sockaddr("connect(2)", addr, rai);
     }
 
Index: test/socket/test_nonblock.rb
===================================================================
--- test/socket/test_nonblock.rb	(revision 50346)
+++ test/socket/test_nonblock.rb	(revision 50347)
@@ -69,6 +69,8 @@ class TestSocketNonblock < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/test/socket/test_nonblock.rb#L69
       assert_equal :wait_writable, rv
     end
     assert_equal([ [], [c], [] ], IO.select(nil, [c], nil, 60))
+    assert_equal(0, c.connect_nonblock(servaddr, exception: false),
+                 'there should be no EISCONN error')
     s, sockaddr = serv.accept
     assert_equal(Socket.unpack_sockaddr_in(c.getsockname),
                  Socket.unpack_sockaddr_in(sockaddr))

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

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