Infinity.TcpConnection

g GObject.Object GObject.Object Infinity.TcpConnection Infinity.TcpConnection GObject.Object->Infinity.TcpConnection

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

new (io, remote_addr, remote_port)

class

new_and_open (io, remote_addr, remote_port)

class

new_resolve (io, resolver)

close ()

get_keepalive ()

get_remote_address ()

get_remote_port ()

open ()

send (data)

set_keepalive (keepalive)

Virtual Methods

Inherited:

GObject.Object (7)

do_error (error)

do_received (data, len)

do_sent (data, len)

Properties

Name

Type

Flags

Short Description

device-index

int

r/w

The index of the device to use for the connection

device-name

str

r/w

The name of the device to use for the connection, such as `eth0’

io

Infinity.Io

r/w/co

I/O handler

keepalive

Infinity.Keepalive

r/w

The keepalive settings for the connection

local-address

Infinity.IpAddress

r

The local address of the connection

local-port

int

r

The local port of the connection

remote-address

Infinity.IpAddress

r/w

Address to connect to

remote-port

int

r/w

Port to connect to

resolver

Infinity.NameResolver

r/w/c

The hostname resolver

status

Infinity.TcpConnectionStatus

r

Status of the TCP connection

Signals

Inherited:

GObject.Object (1)

Name

Short Description

error

This signal is emitted when an error occurred with the connection.

received

This signal is emitted whenever data has been received from the connection.

sent

This signal is emitted whenever data has been sent over the connection.

Fields

Inherited:

GObject.Object (1)

Name

Type

Access

Description

parent

GObject.Object

r

Class Details

class Infinity.TcpConnection(**kwargs)
Bases:

GObject.Object

Abstract:

No

Structure:

Infinity.TcpConnectionClass

Infinity.TcpConnection is an opaque data type. You should only access it via the public API functions.

classmethod new(io, remote_addr, remote_port)
Parameters:
Returns:

A new Infinity.TcpConnection. Free with GObject.Object.unref().

Return type:

Infinity.TcpConnection

Creates a new Infinity.TcpConnection. The arguments are stored as properties for an eventual Infinity.TcpConnection.open() call, this function itself does not establish a connection.

classmethod new_and_open(io, remote_addr, remote_port)
Parameters:
Raises:

GLib.Error

Returns:

A new Infinity.TcpConnection, or None on error. Free with GObject.Object.unref().

Return type:

Infinity.TcpConnection

Creates a new Infinity.TcpConnection and connects it to the given TCP endpoint. Like Infinity.TcpConnection.new(), but calls Infinity.TcpConnection.open().

classmethod new_resolve(io, resolver)
Parameters:
Returns:

A new Infinity.TcpConnection. Free with GObject.Object.unref().

Return type:

Infinity.TcpConnection

Creates a new Infinity.TcpConnection and instead of setting the remote IP address and port number directly, a hostname resolver is used to look up the remote hostname before connecting. This has the advantage that all available addresses for that hostname are tried before giving up.

The argument is stored as a property for an eventual Infinity.TcpConnection.open() call, this function itself does not establish a connection.

close()

Closes a TCP connection that is either open or currently connecting.

get_keepalive()
Returns:

The current keepalive configuration for self, owned by self.

Return type:

Infinity.Keepalive

Returns the current keepalive settings for self.

get_remote_address()
Returns:

A Infinity.IpAddress owned by self. You do not need to free it, but need to make your own copy if you want to keep it longer than self's lifetime.

Return type:

Infinity.IpAddress

Returns the IP address of the remote site.

get_remote_port()
Returns:

The port of the remote site.

Return type:

int

Returns the port of the remote site to which self is (or was) connected or connecting.

open()
Raises:

GLib.Error

Returns:

False if an error occurred and True otherwise.

Return type:

bool

Attempts to open self. Make sure to have set the “remote-address” and “remote-port” property before calling this function. If an error occurs, the function returns False and error is set. Note however that the connection might not be fully open when the function returns (check the “status” property if you need to know). If an asynchronous error occurs while the connection is being opened, the “error” signal is emitted.

send(data)
Parameters:

data (bytes) – The data to send.

Sends data through the TCP connection. The data is not sent immediately, but enqueued to a buffer and will be sent as soon as kernel space becomes available. The “sent” signal will be emitted when data has really been sent.

set_keepalive(keepalive)
Parameters:

keepalive (Infinity.Keepalive) – New keepalive settings for the connection.

Raises:

GLib.Error

Returns:

True if the new keeplalive values were set, or False on error.

Return type:

bool

Sets the keepalive settings for self. When this function is not called, the system defaults are used. If the connection is closed, then the function always succeeds and stores the keepalive values internally. The values are actually set on the underlying socket when the connection is opened. If the connection is already open, the function might fail if the system call fails.

do_error(error) virtual
Parameters:

error (GLib.Error) –

do_received(data, len) virtual
Parameters:
do_sent(data, len) virtual
Parameters:

Signal Details

Infinity.TcpConnection.signals.error(tcp_connection, error)
Signal Name:

error

Flags:

RUN_LAST

Parameters:

This signal is emitted when an error occurred with the connection. If the error is fatal, the connection will change its status to Infinity.TcpConnectionStatus.CLOSED.

Infinity.TcpConnection.signals.received(tcp_connection, data, length)
Signal Name:

received

Flags:

RUN_LAST

Parameters:
  • tcp_connection (Infinity.TcpConnection) – The object which received the signal

  • data (object or None) – A object referring to the data that has been received.

  • length (int) – A int holding the number of bytes that has been received.

This signal is emitted whenever data has been received from the connection.

Infinity.TcpConnection.signals.sent(tcp_connection, data, length)
Signal Name:

sent

Flags:

RUN_LAST

Parameters:
  • tcp_connection (Infinity.TcpConnection) – The object which received the signal

  • data (object or None) – A object referring to the data that has been sent.

  • length (int) – A int holding the number of bytes that has been sent.

This signal is emitted whenever data has been sent over the connection.

Property Details

Infinity.TcpConnection.props.device_index
Name:

device-index

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE

The index of the device to use for the connection

Infinity.TcpConnection.props.device_name
Name:

device-name

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE

The name of the device to use for the connection, such as `eth0’

Infinity.TcpConnection.props.io
Name:

io

Type:

Infinity.Io

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

I/O handler

Infinity.TcpConnection.props.keepalive
Name:

keepalive

Type:

Infinity.Keepalive

Default Value:

None

Flags:

READABLE, WRITABLE

The keepalive settings for the connection

Infinity.TcpConnection.props.local_address
Name:

local-address

Type:

Infinity.IpAddress

Default Value:

None

Flags:

READABLE

The local address of the connection

Infinity.TcpConnection.props.local_port
Name:

local-port

Type:

int

Default Value:

0

Flags:

READABLE

The local port of the connection

Infinity.TcpConnection.props.remote_address
Name:

remote-address

Type:

Infinity.IpAddress

Default Value:

None

Flags:

READABLE, WRITABLE

Address to connect to

Infinity.TcpConnection.props.remote_port
Name:

remote-port

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE

Port to connect to

Infinity.TcpConnection.props.resolver
Name:

resolver

Type:

Infinity.NameResolver

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT

The hostname resolver

Infinity.TcpConnection.props.status
Name:

status

Type:

Infinity.TcpConnectionStatus

Default Value:

Infinity.TcpConnectionStatus.CLOSED

Flags:

READABLE

Status of the TCP connection