Class: Griffin::Listener
- Inherits:
-
Object
- Object
- Griffin::Listener
- Defined in:
- lib/griffin/listener.rb
Constant Summary collapse
- DEFAULT_BACKLOG_SIZE =
1024
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(host, port, backlog: DEFAULT_BACKLOG_SIZE) ⇒ Listener
constructor
A new instance of Listener.
- #listen(tcp_opt: true) ⇒ Object
Constructor Details
#initialize(host, port, backlog: DEFAULT_BACKLOG_SIZE) ⇒ Listener
Returns a new instance of Listener.
12 13 14 15 16 |
# File 'lib/griffin/listener.rb', line 12 def initialize(host, port, backlog: DEFAULT_BACKLOG_SIZE) @host = host @port = port @backlog = backlog end |
Instance Method Details
#close ⇒ Object
32 33 34 |
# File 'lib/griffin/listener.rb', line 32 def close @sock.close end |
#listen(tcp_opt: true) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/griffin/listener.rb', line 18 def listen(tcp_opt: true) @sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0) if tcp_opt @sock.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) end @sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEPORT, true) @sock.bind(Addrinfo.tcp(@host, @port)) @sock.listen(@backlog) Griffin.logger.info("Start listening #{@host}:#{@port}") @sock end |