using sendmsg_nonblock instead of #send for udp writes

This commit is contained in:
HoneyryderChuck 2021-04-01 19:06:28 +01:00
parent 6f5dd472f0
commit 6e4ce5a638

View File

@ -39,16 +39,20 @@ module HTTPX
end
end
def write(buffer)
siz = @io.send(buffer.to_s, 0, @host, @port)
log { "WRITE: #{siz} bytes..." }
buffer.shift!(siz)
siz
end
# :nocov:
if (RUBY_ENGINE == "truffleruby" && RUBY_ENGINE_VERSION < "21.1.0") ||
RUBY_VERSION < "2.3"
def write(buffer)
siz = @io.sendmsg_nonblock(buffer.to_s, 0, Socket.sockaddr_in(@port, @host.to_s))
log { "WRITE: #{siz} bytes..." }
buffer.shift!(siz)
siz
rescue ::IO::WaitWritable
0
rescue EOFError
nil
end
def read(size, buffer)
data, _ = @io.recvfrom_nonblock(size)
buffer.replace(data)
@ -59,6 +63,18 @@ module HTTPX
rescue IOError
end
else
def write(buffer)
siz = @io.sendmsg_nonblock(buffer.to_s, 0, Socket.sockaddr_in(@port, @host.to_s), exception: false)
return 0 if siz == :wait_writable
return if siz.nil?
log { "WRITE: #{siz} bytes..." }
buffer.shift!(siz)
siz
end
def read(size, buffer)
ret = @io.recvfrom_nonblock(size, 0, buffer, exception: false)
return 0 if ret == :wait_readable