Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions ext/socket/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,9 @@ rsock_socket0(int domain, int type, int proto)
rb_fd_fix_cloexec(result);

#ifndef SOCK_NONBLOCK
#ifdef _WIN32
if( type != SOCK_DGRAM )
#endif
rsock_make_fd_nonblock(result);
#endif

Expand Down Expand Up @@ -582,10 +585,6 @@ rsock_connect(int fd, const struct sockaddr *sockaddr, int len, int socks, struc
void
rsock_make_fd_nonblock(int fd)
{
#ifdef _WIN32
return;
#endif

int flags;
#ifdef F_GETFL
flags = fcntl(fd, F_GETFL);
Expand Down
2 changes: 0 additions & 2 deletions io.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,8 @@ rb_cloexec_pipe(int descriptors[2])
rb_maygvl_fd_fix_cloexec(descriptors[0]);
rb_maygvl_fd_fix_cloexec(descriptors[1]);

#ifndef _WIN32
rb_fd_set_nonblock(descriptors[0]);
rb_fd_set_nonblock(descriptors[1]);
#endif
#endif

return result;
Expand Down
1 change: 1 addition & 0 deletions test/-ext-/thread_fd/test_thread_fd_close.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
class TestThreadFdClose < Test::Unit::TestCase

def test_thread_fd_close
omit "Windows has a different closing behaviour with nonblock=true" if RUBY_PLATFORM=~/mswin|mingw/
IO.pipe do |r, w|
th = Thread.new do
begin
Expand Down
41 changes: 28 additions & 13 deletions test/fiber/test_io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,20 @@
class TestFiberIO < Test::Unit::TestCase
MESSAGE = "Hello World"

def test_read
omit unless defined?(UNIXSocket)

i, o = UNIXSocket.pair
if RUBY_PLATFORM=~/mswin|mingw/
i.nonblock = true
o.nonblock = true
end

private def read_test_on_io(i,o, read_size: 20)
message = nil

thread = Thread.new do
scheduler = Scheduler.new
Fiber.set_scheduler scheduler

Fiber.schedule do
message = i.read(20)
message = i.read(read_size)
i.close
end

Fiber.schedule do
o.write("Hello World")
o.write(MESSAGE)
o.close
end
end
Expand All @@ -38,6 +30,30 @@ def test_read
assert_predicate(o, :closed?)
end

def test_read_io_pipe
read_test_on_io(*IO.pipe)
end

def test_read_unixsocket
omit unless defined?(UNIXSocket)
read_test_on_io(*UNIXSocket.pair)
end

def test_read_tcp
server = TCPServer.new('localhost', 0)
i = TCPSocket.new('localhost', server.local_address.ip_port)
o = server.accept
server.close
read_test_on_io(i,o)
end

def test_read_udp
omit "nonblocking UDP isn't supported on Windows" if RUBY_PLATFORM=~/mswin|mingw/
i = Addrinfo.udp("localhost", 0).bind
o = i.connect_address.connect
read_test_on_io(i,o, read_size: MESSAGE.bytesize)
end

def test_heavy_read
omit unless defined?(UNIXSocket)

Expand Down Expand Up @@ -67,8 +83,7 @@ def test_heavy_read

def test_epipe_on_read
omit unless defined?(UNIXSocket)
omit "nonblock=true isn't properly supported on Windows" if RUBY_PLATFORM=~/mswin|mingw/

omit "Windows has a different closing behaviour with nonblock=true" if RUBY_PLATFORM=~/mswin|mingw/
i, o = UNIXSocket.pair

error = nil
Expand Down
2 changes: 1 addition & 1 deletion test/socket/test_socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ def test_closed_read
ensure
serv_thread.value.close
server.close
end unless RUBY_PLATFORM.include?("freebsd")
end unless RUBY_PLATFORM =~ /freebsd|mswin|mingw/

def test_connect_timeout
host = "127.0.0.1"
Expand Down