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(ip, port, options)
[show source]
   # File lib/httpx/io/udp.rb
 9 def initialize(ip, port, options)
10   @host = ip
11   @port = port
12   @io = UDPSocket.new(IPAddr.new(ip).family)
13   @options = options
14 end

Public Instance methods

close()
[show source]
   # File lib/httpx/io/udp.rb
26 def close
27   @io.close
28 end
connect()
[show source]
   # File lib/httpx/io/udp.rb
20 def connect; end
connected?()
[show source]
   # File lib/httpx/io/udp.rb
22 def connected?
23   true
24 end
read(size, buffer)
[show source]
   # File lib/httpx/io/udp.rb
51 def read(size, buffer)
52   ret = @io.recvfrom_nonblock(size, 0, buffer, exception: false)
53   return 0 if ret == :wait_readable
54   return if ret.nil?
55 
56   log { "READ: #{buffer.bytesize} bytes..." }
57 
58   buffer.bytesize
59 rescue IOError
60 end
to_io()
[show source]
   # File lib/httpx/io/udp.rb
16 def to_io
17   @io.to_io
18 end
write(buffer)

In JRuby, sendmsg_nonblock is not implemented

[show source]
   # File lib/httpx/io/udp.rb
32 def write(buffer)
33   siz = @io.send(buffer.to_s, 0, @host, @port)
34   log { "WRITE: #{siz} bytes..." }
35   buffer.shift!(siz)
36   siz
37 end