Class: HTTPX::UDP
Constant Summary
Constants included from Loggable
Instance Method Summary collapse
-
#close ⇒ Object
:nocov:.
- #connect ⇒ Object
- #connected? ⇒ Boolean
-
#initialize(ip, port, options) ⇒ UDP
constructor
A new instance of UDP.
- #read(size, buffer) ⇒ Object
- #to_io ⇒ Object
-
#write(buffer) ⇒ Object
In JRuby, sendmsg_nonblock is not implemented.
Methods included from Loggable
Constructor Details
#initialize(ip, port, options) ⇒ UDP
Returns a new instance of UDP.
9 10 11 12 13 14 |
# File 'lib/httpx/io/udp.rb', line 9 def initialize(ip, port, ) @host = ip @port = port @io = UDPSocket.new(IPAddr.new(ip).family) @options = end |
Instance Method Details
#close ⇒ Object
:nocov:
28 29 30 31 32 |
# File 'lib/httpx/io/udp.rb', line 28 def close @io.close rescue StandardError nil end |
#connect ⇒ Object
20 |
# File 'lib/httpx/io/udp.rb', line 20 def connect; end |
#connected? ⇒ Boolean
22 23 24 |
# File 'lib/httpx/io/udp.rb', line 22 def connected? true end |
#read(size, buffer) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/httpx/io/udp.rb', line 54 def read(size, buffer) data, _ = @io.recvfrom_nonblock(size) buffer.replace(data) log { "READ: #{buffer.bytesize} bytes..." } buffer.bytesize rescue ::IO::WaitReadable 0 rescue IOError end |
#to_io ⇒ Object
16 17 18 |
# File 'lib/httpx/io/udp.rb', line 16 def to_io @io.to_io end |
#write(buffer) ⇒ Object
In JRuby, sendmsg_nonblock is not implemented
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/httpx/io/udp.rb', line 89 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 |