Class: Async::IO::TCPServer

Inherits:
TCPSocket show all
Includes:
Server
Defined in:
lib/async/io/tcp_socket.rb

Overview

Asynchronous TCP server wrappper.

Constant Summary

Constants inherited from Generic

Generic::WRAPPERS

Instance Attribute Summary

Attributes inherited from TCPSocket

#buffer

Attributes inherited from Generic

#timeout

Instance Method Summary collapse

Methods included from Server

#accept_each

Methods inherited from TCPSocket

#read, #write

Methods included from Peer

#connected?, #protocol, #sync, #sync=, #type

Methods inherited from Generic

#connected?, #dup, #nonblock, #nonblock=, #nonblock?, #read, #wait, wrap, wrap_blocking_method, wraps, #write

Constructor Details

#initialize(*args) ⇒ TCPServer

Returns a new instance of TCPServer.



104
105
106
107
108
109
110
111
# File 'lib/async/io/tcp_socket.rb', line 104

def initialize(*args)
  if args.first.is_a? ::TCPServer
    super(args.first)
  else
    # We assume this operation doesn't block (for long):
    super(::TCPServer.new(*args))
  end
end

Instance Method Details

#accept(timeout: nil, task: Task.current) ⇒ Object Also known as: accept_nonblock, sysaccept



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/async/io/tcp_socket.rb', line 113

def accept(timeout: nil, task: Task.current)
  peer, address = async_send(:accept_nonblock, timeout: timeout)
  
  wrapper = TCPSocket.new(peer)
  
  wrapper.timeout = self.timeout
  
  return wrapper, address unless block_given?
  
  begin
    yield wrapper, address
  ensure
    wrapper.close
  end
end