Class: Minx::SocketChannel
- Inherits:
-
IOChannel
- Object
- IOChannel
- Minx::SocketChannel
- Defined in:
- lib/minx/socket_channel.rb
Instance Method Summary (collapse)
-
- (Object) connect(host, options = {})
Connect to host on the port specified in the :port option.
-
- (Object) disconnect
Close the connection.
-
- (SocketChannel) initialize(socket)
constructor
A new instance of SocketChannel.
Methods inherited from IOChannel
Constructor Details
- (SocketChannel) initialize(socket)
A new instance of SocketChannel
7 8 9 10 |
# File 'lib/minx/socket_channel.rb', line 7 def initialize(socket) @socket = socket super(@socket) end |
Instance Method Details
- (Object) connect(host, options = {})
Connect to host on the port specified in the :port option.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/minx/socket_channel.rb', line 19 def connect(host, = {}) raise ArgumentError.new("Missing option: port") if [:port].nil? port = [:port] sockaddr = Socket.sockaddr_in(port, host) @socket.connect_nonblock(sockaddr) rescue Errno::EINPROGRESS Minx.yield until ::IO.select([], [@socket], nil, 0) @socket.connect_nonblock(sockaddr) end |
- (Object) disconnect
Close the connection.
34 35 36 |
# File 'lib/minx/socket_channel.rb', line 34 def disconnect @socket.close end |