Project

General

Profile

Feature #13362 ยป 0001-socket-avoid-fcntl-for-read-write_nonblock-on-Linux.patch

normalperson (Eric Wong), 03/24/2017 05:51 AM

View differences:

ext/socket/lib/socket.rb
scm_rights: false, exception: true)
__recvmsg_nonblock(dlen, flags, clen, scm_rights, exception)
end
# Linux-specific optimizations to avoid fcntl for IO#read_nonblock
# and IO#write_nonblock using MSG_DONTWAIT
# Do other platforms suport MSG_DONTWAIT reliably?
if RUBY_PLATFORM =~ /linux/ && Socket.const_defined?(:MSG_DONTWAIT)
def read_nonblock(len, str = nil, exception: true) # :nodoc:
case rv = __recv_nonblock(len, 0, str, exception)
when '' # recv_nonblock returns empty string on EOF
exception ? raise(EOFError, 'end of file reached') : nil
else
rv
end
end
def write_nonblock(buf, exception: true) # :nodoc:
__sendmsg_nonblock(buf, 0, nil, nil, exception)
end
end
end
class Socket < BasicSocket
test/socket/test_basicsocket.rb
sock.close
end
end
def test_read_write_nonblock
socks do |sserv, ssock, csock|
buf = String.new
assert_equal :wait_readable, ssock.read_nonblock(1, buf, exception: false)
assert_equal 5, csock.write_nonblock('hello')
IO.select([ssock])
assert_same buf, ssock.read_nonblock(5, buf, exception: false)
assert_equal 'hello', buf
buf = '*' * 16384
n = 0
case w = csock.write_nonblock(buf, exception: false)
when Integer
n += w
when :wait_writable
break
end while true
assert_equal :wait_writable, w
assert_raise(IO::WaitWritable) { loop { csock.write_nonblock(buf) } }
assert_operator n, :>, 0
csock.close
case r = ssock.read_nonblock(16384, buf, exception: false)
when String
next
when nil
break
else
flunk "unexpected read_nonblock return: #{r.inspect}"
end while true
assert_raise(EOFError) { ssock.read_nonblock(1) }
end
end
end if defined?(BasicSocket)
-
    (1-1/1)