class HTTPX::UDP

  1. lib/httpx/io/udp.rb
Superclass: Object

Methods

Public Class

  1. new

Public Instance

  1. close
  2. connect
  3. connected?
  4. read
  5. to_io
  6. write

Included modules

  1. Loggable

Public Class methods

new (uri, _, _)
[show source]
   # File lib/httpx/io/udp.rb
10 def initialize(uri, _, _)
11   ip = IPAddr.new(uri.host)
12   @host = ip.to_s
13   @port = uri.port
14   @io = UDPSocket.new(ip.family)
15 end

Public Instance methods

close ()
[show source]
   # File lib/httpx/io/udp.rb
27 def close
28   @io.close
29 end
connect ()
[show source]
   # File lib/httpx/io/udp.rb
21 def connect; end
connected? ()
[show source]
   # File lib/httpx/io/udp.rb
23 def connected?
24   true
25 end
read (size, buffer)
[show source]
   # File lib/httpx/io/udp.rb
38 def read(size, buffer)
39   data, _ = @io.recvfrom_nonblock(size)
40   buffer.replace(data)
41   buffer.bytesize
42 rescue ::IO::WaitReadable
43   0
44 rescue IOError
45 end
to_io ()
[show source]
   # File lib/httpx/io/udp.rb
17 def to_io
18   @io.to_io
19 end
write (buffer)
[show source]
   # File lib/httpx/io/udp.rb
31 def write(buffer)
32   siz = @io.send(buffer, 0, @host, @port)
33   buffer.shift!(siz)
34   siz
35 end