Class: HTTPX::UDP
Constant Summary
Constants included
from Loggable
Loggable::COLORS, Loggable::USE_DEBUG_LOG
Instance Method Summary
collapse
Methods included from Loggable
#log, #log_exception
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, options)
@host = ip
@port = port
@io = UDPSocket.new(IPAddr.new(ip).family)
@options = options
end
|
Instance Method Details
#close ⇒ Object
26
27
28
|
# File 'lib/httpx/io/udp.rb', line 26
def close
@io.close
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
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/httpx/io/udp.rb', line 51
def read(size, buffer)
ret = @io.recvfrom_nonblock(size, 0, buffer, exception: false)
return 0 if ret == :wait_readable
return if ret.nil?
log { "READ: #{buffer.bytesize} bytes..." }
buffer.bytesize
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
32
33
34
35
36
37
|
# File 'lib/httpx/io/udp.rb', line 32
def write(buffer)
siz = @io.send(buffer.to_s, 0, @host, @port)
log { "WRITE: #{siz} bytes..." }
buffer.shift!(siz)
siz
end
|