class TCPSocket
Overide stock TCPSocket
code by encapsulating a Socket
instance
Constants
- NO_EXCEPTION
Attributes
io[R]
Public Class Methods
new(remote_host, remote_port, local_host = nil, local_port = nil)
click to toggle source
# File lib/polyphony/extensions/socket.rb, line 123 def initialize(remote_host, remote_port, local_host = nil, local_port = nil) @io = Socket.new Socket::AF_INET, Socket::SOCK_STREAM if local_host && local_port addr = Addrinfo.tcp(local_host, local_port) @io.bind(addr) end return unless remote_host && remote_port addr = Addrinfo.tcp(remote_host, remote_port) @io.connect(addr) end
Public Instance Methods
close()
click to toggle source
# File lib/polyphony/extensions/socket.rb, line 137 def close @io ? @io.close : orig_close end
Also aliased as: orig_close
closed?()
click to toggle source
# File lib/polyphony/extensions/socket.rb, line 147 def closed? @io ? @io.closed? : orig_closed? end
Also aliased as: orig_closed?
dont_linger()
click to toggle source
# File lib/polyphony/extensions/socket.rb, line 151 def dont_linger setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_LINGER, ::Socket::ZERO_LINGER) end
feed_loop(receiver, method = :call, &block)
click to toggle source
# File lib/polyphony/extensions/socket.rb, line 193 def feed_loop(receiver, method = :call, &block) Polyphony.backend_recv_feed_loop(self, receiver, method, &block) end
no_delay()
click to toggle source
# File lib/polyphony/extensions/socket.rb, line 155 def no_delay setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1) end
read(maxlen = nil, buf = nil, buf_pos = 0)
click to toggle source
# File lib/polyphony/extensions/socket.rb, line 168 def read(maxlen = nil, buf = nil, buf_pos = 0) return Polyphony.backend_recv(self, buf, maxlen, buf_pos) if buf return Polyphony.backend_recv(self, buf || +'', maxlen, 0) if maxlen buf = +'' len = buf.bytesize while true Polyphony.backend_recv(self, buf, maxlen || 4096, -1) new_len = buf.bytesize break if new_len == len len = new_len end buf end
Also aliased as: orig_read
read_nonblock(len, str = nil, exception: true)
click to toggle source
# File lib/polyphony/extensions/socket.rb, line 215 def read_nonblock(len, str = nil, exception: true) @io.read_nonblock(len, str, exception: exception) end
readpartial(maxlen, str = +'', buffer_pos = 0, raise_on_eof = true)
click to toggle source
def <<(mesg)
Polyphony.backend_send(self, mesg, 0)
end
# File lib/polyphony/extensions/socket.rb, line 209 def readpartial(maxlen, str = +'', buffer_pos = 0, raise_on_eof = true) result = Polyphony.backend_recv(self, str, maxlen, buffer_pos) raise EOFError if !result && raise_on_eof result end
recv(maxlen, flags = 0, outbuf = nil)
click to toggle source
# File lib/polyphony/extensions/socket.rb, line 184 def recv(maxlen, flags = 0, outbuf = nil) Polyphony.backend_recv(self, outbuf || +'', maxlen, 0) end
recv_loop(maxlen = 8192, &block)
click to toggle source
# File lib/polyphony/extensions/socket.rb, line 188 def recv_loop(maxlen = 8192, &block) Polyphony.backend_recv_loop(self, maxlen, &block) end
Also aliased as: read_loop
reuse_addr()
click to toggle source
# File lib/polyphony/extensions/socket.rb, line 159 def reuse_addr setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_REUSEADDR, 1) end
reuse_port()
click to toggle source
# File lib/polyphony/extensions/socket.rb, line 163 def reuse_port setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_REUSEPORT, 1) end
setsockopt(*args)
click to toggle source
# File lib/polyphony/extensions/socket.rb, line 142 def setsockopt(*args) @io ? @io.setsockopt(*args) : orig_setsockopt(*args) end
Also aliased as: orig_setsockopt
write_nonblock(buf, exception: true)
click to toggle source
# File lib/polyphony/extensions/socket.rb, line 219 def write_nonblock(buf, exception: true) @io.write_nonblock(buf, exception: exception) end