mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50347 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
038c0e5a80
commit
b88296be43
3 changed files with 14 additions and 0 deletions
|
@ -1,3 +1,9 @@
|
|||
Mon Apr 20 11:10:46 2015 Eric Wong <e@80x24.org>
|
||||
|
||||
* 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@gmail.com>
|
||||
|
||||
* ext/{etc,openssl,tk}: Adding parens and comparisons around
|
||||
|
|
|
@ -509,6 +509,12 @@ sock_connect_nonblock(int argc, VALUE *argv, VALUE sock)
|
|||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -69,6 +69,8 @@ class TestSocketNonblock < Test::Unit::TestCase
|
|||
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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue