Class: Rendezvous::Socket::CustomSocket
- Inherits:
-
Socket
- Object
- Socket
- Rendezvous::Socket::CustomSocket
- Defined in:
- lib/rendezvous/socket/custom_socket.rb
Instance Method Summary collapse
- #accept ⇒ Object
- #addr ⇒ Object
- #bind(port = 0) ⇒ Object
- #connect(ip, port) ⇒ Object
-
#initialize ⇒ CustomSocket
constructor
A new instance of CustomSocket.
- #listen(buf) ⇒ Object
- #local_port ⇒ Object
Constructor Details
#initialize ⇒ CustomSocket
Returns a new instance of CustomSocket.
6 7 8 9 10 11 12 |
# File 'lib/rendezvous/socket/custom_socket.rb', line 6 def initialize super(AF_INET, SOCK_STREAM, 0) setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) if defined?(SO_REUSEPORT) setsockopt(SOL_SOCKET, SO_REUSEPORT, 1) end end |
Instance Method Details
#accept ⇒ Object
32 33 34 |
# File 'lib/rendezvous/socket/custom_socket.rb', line 32 def accept super[0] end |
#addr ⇒ Object
36 37 38 |
# File 'lib/rendezvous/socket/custom_socket.rb', line 36 def addr ::Socket.unpack_sockaddr_in(getsockname) end |
#bind(port = 0) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/rendezvous/socket/custom_socket.rb', line 19 def bind(port = 0) ip = ::Socket.ip_address_list.detect{|a| a.ipv4_private? }.ip_address $stderr.puts "attempting to bind to #{ip}:#{port}" if $DEBUG addr_local = ::Socket.pack_sockaddr_in(port, ip) super(addr_local) end |
#connect(ip, port) ⇒ Object
26 27 28 29 30 |
# File 'lib/rendezvous/socket/custom_socket.rb', line 26 def connect(ip, port) $stderr.puts "attempting to connect to #{ip}:#{port}" if $DEBUG addr_remote = ::Socket.pack_sockaddr_in(port, ip) super(addr_remote) end |
#listen(buf) ⇒ Object
14 15 16 17 |
# File 'lib/rendezvous/socket/custom_socket.rb', line 14 def listen(buf) $stderr.puts "attempting to listen" if $DEBUG super(buf) end |
#local_port ⇒ Object
40 41 42 |
# File 'lib/rendezvous/socket/custom_socket.rb', line 40 def local_port addr[0] end |