Class: HTTPX::UDP
Constant Summary
Constants included from Loggable
Instance Method Summary collapse
- #close ⇒ Object
- #connect ⇒ Object
- #connected? ⇒ Boolean
-
#initialize(uri, _, _) ⇒ UDP
constructor
A new instance of UDP.
- #read(size, buffer) ⇒ Object
- #to_io ⇒ Object
- #write(buffer) ⇒ Object
Methods included from Loggable
Constructor Details
#initialize(uri, _, _) ⇒ UDP
Returns a new instance of UDP.
10 11 12 13 14 15 |
# File 'lib/httpx/io/udp.rb', line 10 def initialize(uri, _, _) ip = IPAddr.new(uri.host) @host = ip.to_s @port = uri.port @io = UDPSocket.new(ip.family) end |
Instance Method Details
#close ⇒ Object
27 28 29 |
# File 'lib/httpx/io/udp.rb', line 27 def close @io.close end |
#connect ⇒ Object
21 |
# File 'lib/httpx/io/udp.rb', line 21 def connect; end |
#connected? ⇒ Boolean
23 24 25 |
# File 'lib/httpx/io/udp.rb', line 23 def connected? true end |
#read(size, buffer) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/httpx/io/udp.rb', line 38 def read(size, buffer) data, _ = @io.recvfrom_nonblock(size) buffer.replace(data) buffer.bytesize rescue ::IO::WaitReadable 0 rescue IOError end |
#to_io ⇒ Object
17 18 19 |
# File 'lib/httpx/io/udp.rb', line 17 def to_io @io.to_io end |
#write(buffer) ⇒ Object
31 32 33 34 35 |
# File 'lib/httpx/io/udp.rb', line 31 def write(buffer) siz = @io.send(buffer, 0, @host, @port) buffer.shift!(siz) siz end |