mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* io.c (io_getpartial): error message describes what should be
waited after nonblocking error. (rb_io_write_nonblock): ditto. * ext/socket/init.c (s_recvfrom_nonblock): ditto. (s_accept_nonblock): ditto. * ext/socket/socket.c (sock_connect_nonblock): ditto. * ext/socket/ancdata.c (bsock_sendmsg_internal): ditto. (bsock_recvmsg_internal): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22486 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6adda0379c
commit
9cfe35ad50
7 changed files with 131 additions and 5 deletions
14
ChangeLog
14
ChangeLog
|
@ -1,3 +1,17 @@
|
|||
Sun Feb 22 00:51:58 2009 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* io.c (io_getpartial): error message describes what should be
|
||||
waited after nonblocking error.
|
||||
(rb_io_write_nonblock): ditto.
|
||||
|
||||
* ext/socket/init.c (s_recvfrom_nonblock): ditto.
|
||||
(s_accept_nonblock): ditto.
|
||||
|
||||
* ext/socket/socket.c (sock_connect_nonblock): ditto.
|
||||
|
||||
* ext/socket/ancdata.c (bsock_sendmsg_internal): ditto.
|
||||
(bsock_recvmsg_internal): ditto.
|
||||
|
||||
Sun Feb 22 00:31:42 2009 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* ext/socket/ancdata.c (bsock_recvmsg_internal): check recvmsg error
|
||||
|
|
|
@ -1030,8 +1030,11 @@ bsock_sendmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
|
|||
goto retry;
|
||||
}
|
||||
|
||||
if (ss == -1)
|
||||
if (ss == -1) {
|
||||
if (nonblock && errno == EWOULDBLOCK)
|
||||
rb_sys_fail("sendmsg(2) WANT_WRITE");
|
||||
rb_sys_fail("sendmsg(2)");
|
||||
}
|
||||
|
||||
return SSIZET2NUM(ss);
|
||||
}
|
||||
|
@ -1290,8 +1293,11 @@ bsock_recvmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
|
|||
goto retry;
|
||||
}
|
||||
|
||||
if (ss == -1)
|
||||
if (ss == -1) {
|
||||
if (nonblock && errno == EWOULDBLOCK)
|
||||
rb_sys_fail("recvmsg(2) WANT_READ");
|
||||
rb_sys_fail("recvmsg(2)");
|
||||
}
|
||||
|
||||
if (grow_buffer) {
|
||||
int grown = 0;
|
||||
|
|
|
@ -192,6 +192,8 @@ s_recvfrom_nonblock(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from)
|
|||
slen = recvfrom(fd, RSTRING_PTR(str), buflen, flags, (struct sockaddr*)&buf, &alen);
|
||||
|
||||
if (slen < 0) {
|
||||
if (errno == EWOULDBLOCK)
|
||||
rb_sys_fail("recvfrom(2) WANT_READ");
|
||||
rb_sys_fail("recvfrom(2)");
|
||||
}
|
||||
if (slen < RSTRING_LEN(str)) {
|
||||
|
@ -453,6 +455,8 @@ s_accept_nonblock(VALUE klass, rb_io_t *fptr, struct sockaddr *sockaddr, socklen
|
|||
rb_io_set_nonblock(fptr);
|
||||
fd2 = accept(fptr->fd, (struct sockaddr*)sockaddr, len);
|
||||
if (fd2 < 0) {
|
||||
if (errno == EWOULDBLOCK || errno == ECONNABORTED || errno == EPROTO)
|
||||
rb_sys_fail("accept(2) WANT_READ");
|
||||
rb_sys_fail("accept(2)");
|
||||
}
|
||||
make_fd_nonblock(fd2);
|
||||
|
|
|
@ -311,6 +311,8 @@ sock_connect_nonblock(VALUE sock, VALUE addr)
|
|||
rb_io_set_nonblock(fptr);
|
||||
n = connect(fptr->fd, (struct sockaddr*)RSTRING_PTR(addr), RSTRING_LEN(addr));
|
||||
if (n < 0) {
|
||||
if (errno == EINPROGRESS)
|
||||
rb_sys_fail("connect(2) WANT_WRITE");
|
||||
rb_sys_fail("connect(2)");
|
||||
}
|
||||
|
||||
|
|
8
io.c
8
io.c
|
@ -1754,6 +1754,8 @@ io_getpartial(int argc, VALUE *argv, VALUE io, int nonblock)
|
|||
if (n < 0) {
|
||||
if (!nonblock && rb_io_wait_readable(fptr->fd))
|
||||
goto again;
|
||||
if (nonblock && errno == EWOULDBLOCK)
|
||||
rb_sys_fail("WANT_READ");
|
||||
rb_sys_fail_path(fptr->pathv);
|
||||
}
|
||||
else if (n == 0) {
|
||||
|
@ -1952,7 +1954,11 @@ rb_io_write_nonblock(VALUE io, VALUE str)
|
|||
rb_io_set_nonblock(fptr);
|
||||
n = write(fptr->fd, RSTRING_PTR(str), RSTRING_LEN(str));
|
||||
|
||||
if (n == -1) rb_sys_fail_path(fptr->pathv);
|
||||
if (n == -1) {
|
||||
if (errno == EWOULDBLOCK)
|
||||
rb_sys_fail("WANT_WRITE");
|
||||
rb_sys_fail_path(fptr->pathv);
|
||||
}
|
||||
|
||||
return LONG2FIX(n);
|
||||
}
|
||||
|
|
|
@ -857,6 +857,30 @@ class TestIO < Test::Unit::TestCase
|
|||
end)
|
||||
end
|
||||
|
||||
def test_read_nonblock_error
|
||||
return if !have_nonblock?
|
||||
with_pipe {|r, w|
|
||||
begin
|
||||
r.read_nonblock 4096
|
||||
rescue Errno::EWOULDBLOCK
|
||||
assert_match(/WANT_READ/, $!.message)
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def test_write_nonblock_error
|
||||
return if !have_nonblock?
|
||||
with_pipe {|r, w|
|
||||
begin
|
||||
loop {
|
||||
w.write_nonblock "a"*100000
|
||||
}
|
||||
rescue Errno::EWOULDBLOCK
|
||||
assert_match(/WANT_WRITE/, $!.message)
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def test_gets
|
||||
pipe(proc do |w|
|
||||
w.write "foobarbaz"
|
||||
|
|
|
@ -124,9 +124,18 @@ class TestSocketNonblock < Test::Unit::TestCase
|
|||
af, port, host, addr = serv.addr
|
||||
c = TCPSocket.new(addr, port)
|
||||
s = serv.accept
|
||||
return c, s
|
||||
if block_given?
|
||||
begin
|
||||
yield c, s
|
||||
ensure
|
||||
serv.close if serv
|
||||
c.close if !c.closed?
|
||||
s.close if !s.closed?
|
||||
end
|
||||
else
|
||||
return c, s
|
||||
end
|
||||
ensure
|
||||
serv.close if serv && !serv.closed?
|
||||
end
|
||||
|
||||
def test_tcp_recv_nonblock
|
||||
|
@ -181,4 +190,65 @@ class TestSocketNonblock < Test::Unit::TestCase
|
|||
end
|
||||
=end
|
||||
|
||||
def test_sendmsg_nonblock_error
|
||||
tcp_pair {|c, s|
|
||||
begin
|
||||
loop {
|
||||
c.sendmsg_nonblock("a" * 100000)
|
||||
}
|
||||
rescue Errno::EWOULDBLOCK
|
||||
assert_match(/WANT_WRITE/, $!.message)
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def test_recvmsg_nonblock_error
|
||||
tcp_pair {|c, s|
|
||||
begin
|
||||
c.recvmsg_nonblock(4096)
|
||||
rescue Errno::EWOULDBLOCK
|
||||
assert_match(/WANT_READ/, $!.message)
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def test_recv_nonblock_error
|
||||
tcp_pair {|c, s|
|
||||
begin
|
||||
c.recv_nonblock(4096)
|
||||
rescue Errno::EWOULDBLOCK
|
||||
assert_match(/WANT_READ/, $!.message)
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def test_connect_nonblock_error
|
||||
serv = TCPServer.new("127.0.0.1", 0)
|
||||
af, port, host, addr = serv.addr
|
||||
c = Socket.new(:INET, :STREAM)
|
||||
begin
|
||||
c.connect_nonblock(Socket.sockaddr_in(port, "127.0.0.1"))
|
||||
rescue Errno::EINPROGRESS
|
||||
assert_match(/WANT_WRITE/, $!.message)
|
||||
end
|
||||
ensure
|
||||
serv.close if serv && !serv.closed?
|
||||
c.close if c && !c.closed?
|
||||
end
|
||||
|
||||
def test_accept_nonblock_error
|
||||
serv = Socket.new(:INET, :STREAM)
|
||||
serv.bind(Socket.sockaddr_in(0, "127.0.0.1"))
|
||||
serv.listen(5)
|
||||
port = serv.local_address.ip_port
|
||||
begin
|
||||
s, _ = serv.accept_nonblock
|
||||
rescue Errno::EWOULDBLOCK, Errno::ECONNABORTED, Errno::EPROTO
|
||||
assert_match(/WANT_READ/, $!.message)
|
||||
end
|
||||
ensure
|
||||
serv.close if serv && !serv.closed?
|
||||
s.close if s && !s.closed?
|
||||
end
|
||||
|
||||
end if defined?(Socket)
|
||||
|
|
Loading…
Reference in a new issue