Class: Alo7::Net::Connection

Inherits:
Object
  • Object
show all
Includes:
Callbacks
Defined in:
lib/alo7/net/connection.rb

Overview

Note:

This class is considered to be a base class. Use the derived class Server or Client instead of this class directly.

Note:

This class should never be instantiated by user code.

This is a class that is instantiated by the event loop whenever a new connection is created. New connections can be created by accepting a remote client or connecting to a remote server.

Users should overwrite #initialize, following callbacks included from Callbacks to implement their own business logics:

Direct Known Subclasses

Client, Server

Defined Under Namespace

Modules: Callbacks

Instance Method Summary collapse

Methods included from Callbacks

#connection_completed, #post_init, #receive_data, #unbind

Constructor Details

#initialize(*args) ⇒ Connection

Returns a new instance of Connection.

Parameters:


81
82
# File 'lib/alo7/net/connection.rb', line 81

def initialize(*args)
end

Instance Method Details

#await(defer) ⇒ Object

Note:

It keeps the pending defers internally. When unbinding, it fails them with a ConnectionLost error.

Note:

It fails the defer and raise a ConnectionLost error intermediately between unbinding.

Wait the defer succeed and then return anything the defer returns. Or raise the exception from the defer.

Parameters:

  • defer (Defer)

    defer to wait

Returns:

  • anything the defer returns

Raises:

  • (Exception)

    the exception returns from defer


109
110
111
# File 'lib/alo7/net/connection.rb', line 109

def await(defer)
  @impl.await defer
end

#disconnectvoid

This method returns an undefined value.

Close the connection asynchronously after all of the outbound data has been written to the remote end. Alo7::Net::Connection::Callbacks#unbind will be called later after this method returns.


104
105
106
# File 'lib/alo7/net/connection.rb', line 104

def disconnect
  @impl.close_connection_after_writing
end

#send_data(data) ⇒ void

Note:

Data is buffered to be send which means it is not guaranteed to be sent immediately when calling this method.

This method returns an undefined value.

Send the data to the remote end of the connection asynchronously.

Parameters:

  • data (String)

    data to send

See Also:


93
94
95
# File 'lib/alo7/net/connection.rb', line 93

def send_data(data)
  @impl.send_data data
end