Class FTW::Connection
In: lib/ftw/connection.rb
lib/ftw/connection.rb
Parent: Object

A network connection. This is TCP.

You can use IO::select on this objects of this type. (at least, in MRI you can)

You can activate SSL/TLS on this connection by invoking FTW::Connection#secure

This class also implements buffering itself because some IO-like classes (OpenSSL::SSL::SSLSocket) do not support IO#ungetbyte

Methods

client?   client?   connect   connect   connected?   connected?   disconnect   disconnect   new   new   peer   peer   pushback   pushback   read   read   readable?   readable?   secure   secure   secured?   secured?   server?   server?   to_io   to_io   writable?   writable?   write   write  

Included Modules

FTW::Poolable Cabin::Inspectable FTW::Poolable Cabin::Inspectable

Classes and Modules

Class FTW::Connection::ConnectRefused
Class FTW::Connection::ConnectTimeout
Class FTW::Connection::InvalidConfiguration
Class FTW::Connection::ReadTimeout
Class FTW::Connection::SecureHandshakeTimeout
Class FTW::Connection::WriteTimeout

Public Class methods

A new network connection. The ‘destination’ argument can be an array of strings or a single string. String format is expected to be "host:port"

Example:

    conn = FTW::Connection.new(["1.2.3.4:80", "1.2.3.5:80"])

If you specify multiple destinations, they are used in a round-robin decision made during reconnection.

A new network connection. The ‘destination’ argument can be an array of strings or a single string. String format is expected to be "host:port"

Example:

    conn = FTW::Connection.new(["1.2.3.4:80", "1.2.3.5:80"])

If you specify multiple destinations, they are used in a round-robin decision made during reconnection.

Public Instance methods

Is this a client connection?

Is this a client connection?

Connect now.

Timeout value is optional. If no timeout is given, this method blocks until a connection is successful or an error occurs.

You should check the return value of this method to determine if a connection was successful.

Possible return values are on error include:

@return [nil] if the connection was successful @return [StandardError or subclass] if the connection failed

Connect now.

Timeout value is optional. If no timeout is given, this method blocks until a connection is successful or an error occurs.

You should check the return value of this method to determine if a connection was successful.

Possible return values are on error include:

@return [nil] if the connection was successful @return [StandardError or subclass] if the connection failed

End this connection, specifying why.

End this connection, specifying why.

The host:port

The host:port

Push back some data onto the connection‘s read buffer.

Push back some data onto the connection‘s read buffer.

Read data from this connection This method blocks until the read succeeds unless a timeout is given.

This method is not guaranteed to read exactly ‘length’ bytes. See IO#sysread

Read data from this connection This method blocks until the read succeeds unless a timeout is given.

This method is not guaranteed to read exactly ‘length’ bytes. See IO#sysread

Is this connection readable? Returns true if it is readable within the timeout period. False otherwise.

The time out is in seconds. Fractional seconds are OK.

Is this connection readable? Returns true if it is readable within the timeout period. False otherwise.

The time out is in seconds. Fractional seconds are OK.

Secure this connection with TLS.

Options:

  • :certificate_store, an OpenSSL::X509::Store
  • :timeout, a timeout threshold in seconds.
  • :ciphers, an OpenSSL ciphers string, see `openssl ciphers` manual for details.
  • :ssl_version, any of: SSLv2, SSLv3, TLSv1, TLSv1.1, TLSv1.2
  • :certificate, an OpenSSL::X509::Certificate
  • :key, an OpenSSL::PKey (like OpenSSL::PKey::RSA)

Both `certificate` and `key` are highly recommended if the connection belongs to a server (not a client connection).

Notes:

  • Version may depend on your platform (openssl compilation settings, JVM version, export restrictions, etc)
    • Available ciphers will depend on your version of Ruby (or JRuby and JVM),

    OpenSSL, etc.

Secure this connection with TLS.

Options:

  • :certificate_store, an OpenSSL::X509::Store
  • :timeout, a timeout threshold in seconds.
  • :ciphers, an OpenSSL ciphers string, see `openssl ciphers` manual for details.
  • :ssl_version, any of: SSLv2, SSLv3, TLSv1, TLSv1.1, TLSv1.2
  • :certificate, an OpenSSL::X509::Certificate
  • :key, an OpenSSL::PKey (like OpenSSL::PKey::RSA)

Both `certificate` and `key` are highly recommended if the connection belongs to a server (not a client connection).

Notes:

  • Version may depend on your platform (openssl compilation settings, JVM version, export restrictions, etc)
    • Available ciphers will depend on your version of Ruby (or JRuby and JVM),

    OpenSSL, etc.

Has this connection been secured?

Has this connection been secured?

Is this a server connection?

Is this a server connection?

Support ‘to_io’ so you can use IO::select on this object.

Support ‘to_io’ so you can use IO::select on this object.

Is this connection writable? Returns true if it is writable within the timeout period. False otherwise.

The time out is in seconds. Fractional seconds are OK.

Is this connection writable? Returns true if it is writable within the timeout period. False otherwise.

The time out is in seconds. Fractional seconds are OK.

Write data to this connection. This method blocks until the write succeeds unless a timeout is given.

This method is not guaranteed to have written the full data given.

Returns the number of bytes written (See also IO#syswrite)

Write data to this connection. This method blocks until the write succeeds unless a timeout is given.

This method is not guaranteed to have written the full data given.

Returns the number of bytes written (See also IO#syswrite)

[Validate]