Class: TCPServer
- Defined in:
- lib/polyphony/extensions/socket.rb
Overview
TCPServer extensions
Instance Method Summary collapse
-
#accept ⇒ TCPSocket
New connection.
-
#accept_loop {|TCPSocket| ... } ⇒ nil
Accepts incoming connections in an infinite loop.
-
#close ⇒ TCPServer
Closes the server socket.
-
#initialize(hostname = nil, port = 0) ⇒ TCPServer
constructor
Initializes the TCP server socket.
Methods inherited from TCPSocket
#<<, #closed?, #dont_linger, #feed_loop, #no_delay, #read, #read_nonblock, #readpartial, #recv, #recv_loop, #reuse_addr, #reuse_port, #send, #setsockopt, #write, #write_nonblock
Constructor Details
#initialize(hostname = nil, port = 0) ⇒ TCPServer
Initializes the TCP server socket.
449 450 451 452 453 454 455 |
# File 'lib/polyphony/extensions/socket.rb', line 449 def initialize(hostname = nil, port = 0) addr = Addrinfo.tcp(hostname, port) @io = Socket.new addr.afamily, Socket::SOCK_STREAM @io.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, 1) @io.bind(addr) @io.listen(0) end |
Instance Method Details
#accept ⇒ TCPSocket
Returns new connection.
463 464 465 |
# File 'lib/polyphony/extensions/socket.rb', line 463 def accept Polyphony.backend_accept(@io, TCPSocket) end |
#accept_loop {|TCPSocket| ... } ⇒ nil
Accepts incoming connections in an infinite loop.
471 472 473 |
# File 'lib/polyphony/extensions/socket.rb', line 471 def accept_loop(&block) Polyphony.backend_accept_loop(@io, TCPSocket, &block) end |
#close ⇒ TCPServer
Closes the server socket.
481 482 483 484 |
# File 'lib/polyphony/extensions/socket.rb', line 481 def close @io.close self end |