Feature #11139 » 0002-socket-accept_nonblock-supports-nonblock-false-kwarg.patch
| ext/socket/init.c | ||
|---|---|---|
|
#endif
|
||
|
int rsock_do_not_reverse_lookup = 1;
|
||
|
static VALUE sym_exception, sym_wait_readable;
|
||
|
static VALUE sym_exception, sym_wait_readable, sym_nonblock;
|
||
|
void
|
||
|
rsock_raise_socket_error(const char *reason, int error)
|
||
| ... | ... | |
|
{
|
||
|
int fd2;
|
||
|
int ex = 1;
|
||
|
int nonblock = 1;
|
||
|
VALUE opts = Qnil;
|
||
|
rb_scan_args(argc, argv, "0:", &opts);
|
||
|
if (!NIL_P(opts) && Qfalse == rb_hash_lookup2(opts, sym_exception, Qundef))
|
||
|
ex = 0;
|
||
|
if (!NIL_P(opts)) {
|
||
|
if (Qfalse == rb_hash_lookup2(opts, sym_exception, Qundef))
|
||
|
ex = 0;
|
||
|
if (Qfalse == rb_hash_lookup2(opts, sym_nonblock, Qundef))
|
||
|
nonblock = 0;
|
||
|
}
|
||
|
rb_secure(3);
|
||
|
rb_io_set_nonblock(fptr);
|
||
|
fd2 = cloexec_accept(fptr->fd, (struct sockaddr*)sockaddr, len, 1);
|
||
|
fd2 = cloexec_accept(fptr->fd, (struct sockaddr*)sockaddr, len, nonblock);
|
||
|
if (fd2 < 0) {
|
||
|
switch (errno) {
|
||
|
case EAGAIN:
|
||
| ... | ... | |
|
#undef rb_intern
|
||
|
sym_exception = ID2SYM(rb_intern("exception"));
|
||
|
sym_wait_readable = ID2SYM(rb_intern("wait_readable"));
|
||
|
sym_nonblock = ID2SYM(rb_intern("nonblock"));
|
||
|
}
|
||
| test/socket/test_nonblock.rb | ||
|---|---|---|
|
assert_equal(Socket.unpack_sockaddr_in(c.getsockname), Socket.unpack_sockaddr_in(sockaddr))
|
||
|
if s.respond_to?(:nonblock?)
|
||
|
assert s.nonblock?, 'accepted socket is non-blocking'
|
||
|
tf = [ true, false ]
|
||
|
assert_equal(tf, tf.map do |nb|
|
||
|
begin
|
||
|
b = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
|
||
|
b.connect(serv.getsockname)
|
||
|
IO.select([serv])
|
||
|
a, _= serv.accept_nonblock(nonblock: nb)
|
||
|
a.nonblock?
|
||
|
ensure
|
||
|
a.close if a
|
||
|
b.close if b
|
||
|
end
|
||
|
end)
|
||
|
end
|
||
|
ensure
|
||
|
serv.close if serv
|
||
|
-
|
||