Class: HTTPX::UDP
Constant Summary
Constants included from Loggable
Instance Attribute Summary collapse
-
#ip ⇒ Object
readonly
Returns the value of attribute ip.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
-
#initialize(ip, port) ⇒ UDP
constructor
A new instance of UDP.
- #inspect ⇒ Object
- #read(size, buffer) ⇒ Object
- #to_io ⇒ Object
- #write(buffer) ⇒ Object
Methods included from Loggable
Constructor Details
#initialize(ip, port) ⇒ UDP
Returns a new instance of UDP.
12 13 14 15 16 17 |
# File 'lib/httpx/io/udp.rb', line 12 def initialize(ip, port) @ip = ip.to_s @port = port @io = UDPSocket.new(ip.family) @closed = false end |
Instance Attribute Details
#ip ⇒ Object (readonly)
Returns the value of attribute ip.
10 11 12 |
# File 'lib/httpx/io/udp.rb', line 10 def ip @ip end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
10 11 12 |
# File 'lib/httpx/io/udp.rb', line 10 def port @port end |
Instance Method Details
#close ⇒ Object
50 51 52 53 54 55 |
# File 'lib/httpx/io/udp.rb', line 50 def close return if @closed @io.close ensure @closed = true end |
#closed? ⇒ Boolean
57 58 59 |
# File 'lib/httpx/io/udp.rb', line 57 def closed? @closed end |
#inspect ⇒ Object
61 62 63 |
# File 'lib/httpx/io/udp.rb', line 61 def inspect "#<(fd: #{@io.fileno}): #{@ip}:#{@port})>" end |
#read(size, buffer) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/httpx/io/udp.rb', line 24 def read(size, buffer) data, _ = @io.recvfrom_nonblock(size) buffer.replace(data) buffer.bytesize rescue ::IO::WaitReadable 0 rescue EOFError nil end |
#to_io ⇒ Object
19 20 21 |
# File 'lib/httpx/io/udp.rb', line 19 def to_io @io.to_io end |
#write(buffer) ⇒ Object
44 45 46 47 48 |
# File 'lib/httpx/io/udp.rb', line 44 def write(buffer) siz = @io.send(buffer, 0, @ip, @port) buffer.slice!(0, siz) siz end |