mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-04 00:00:37 -04:00
using sendmsg_nonblock instead of #send for udp writes
This commit is contained in:
parent
6f5dd472f0
commit
6e4ce5a638
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user