Sha256: 5167c4053b99c0e21901e6364b4f2be028db04a7d6b54731d721ea7d9b314fa3
Contents?: true
Size: 1.28 KB
Versions: 1
Compression:
Stored size: 1.28 KB
Contents
# frozen_string_literal: true require "socket" require "ipaddr" module HTTPX class UDP include Loggable def initialize(uri, _, options) ip = IPAddr.new(uri.host) @host = ip.to_s @port = uri.port @io = UDPSocket.new(ip.family) @options = options end def to_io @io.to_io end def connect; end def connected? true end if RUBY_VERSION < "2.3" # :nocov: def close @io.close rescue StandardError nil end # :nocov: else def close @io.close end end def write(buffer) siz = @io.send(buffer, 0, @host, @port) log { "WRITE: #{siz} bytes..." } buffer.shift!(siz) siz end # :nocov: if RUBY_VERSION < "2.3" def read(size, buffer) data, _ = @io.recvfrom_nonblock(size) buffer.replace(data) log { "READ: #{buffer.bytesize} bytes..." } buffer.bytesize rescue ::IO::WaitReadable 0 rescue IOError end else def read(size, buffer) ret = @io.recvfrom_nonblock(size, 0, buffer, exception: false) return 0 if ret == :wait_readable return if ret.nil? buffer.bytesize rescue IOError end end # :nocov: end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
httpx-0.11.0 | lib/httpx/io/udp.rb |