class Socket

Socket overrides (eventually rewritten in C)

Constants

NO_EXCEPTION
ZERO_LINGER

Public Class Methods

getaddrinfo(*args) click to toggle source
# File lib/polyphony/extensions/socket.rb, line 111
def getaddrinfo(*args)
  Polyphony::ThreadPool.process { orig_getaddrinfo(*args) }
end
Also aliased as: orig_getaddrinfo
orig_getaddrinfo(*args)
Alias for: getaddrinfo

Public Instance Methods

accept() click to toggle source
# File lib/polyphony/extensions/socket.rb, line 16
def accept
  Polyphony.backend_accept(self, TCPSocket)
end
accept_loop(&block) click to toggle source
# File lib/polyphony/extensions/socket.rb, line 20
def accept_loop(&block)
  Polyphony.backend_accept_loop(self, TCPSocket, &block)
end
connect(addr) click to toggle source
# File lib/polyphony/extensions/socket.rb, line 26
def connect(addr)
  addr = Addrinfo.new(addr) if addr.is_a?(String)
  Polyphony.backend_connect(self, addr.ip_address, addr.ip_port)
end
dont_linger() click to toggle source
# File lib/polyphony/extensions/socket.rb, line 93
def dont_linger
  setsockopt(Socket::SOL_SOCKET, Socket::SO_LINGER, ZERO_LINGER)
end
feed_loop(receiver, method = :call, &block) click to toggle source
# File lib/polyphony/extensions/socket.rb, line 57
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 97
def no_delay
  setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
end
orig_read(maxlen = nil, buf = nil, buf_pos = 0)
Alias for: read
read(maxlen = nil, buf = nil, buf_pos = 0) click to toggle source
# File lib/polyphony/extensions/socket.rb, line 32
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_loop(maxlen = 8192, &block)
Alias for: recv_loop
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 86
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
end
recv(maxlen, flags = 0, outbuf = nil) click to toggle source
# File lib/polyphony/extensions/socket.rb, line 48
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 52
def recv_loop(maxlen = 8192, &block)
  Polyphony.backend_recv_loop(self, maxlen, &block)
end
Also aliased as: read_loop
recvfrom(maxlen, flags = 0) click to toggle source
# File lib/polyphony/extensions/socket.rb, line 61
def recvfrom(maxlen, flags = 0)
  buf = +''
  while true
    result = recvfrom_nonblock(maxlen, flags, buf, **NO_EXCEPTION)
    case result
    when nil then raise IOError
    when :wait_readable then Polyphony.backend_wait_io(self, false)
    else
      return result
    end
  end
end
reuse_addr() click to toggle source
# File lib/polyphony/extensions/socket.rb, line 101
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 105
def reuse_port
  setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_REUSEPORT, 1)
end