dragon.infrastructure.connection.Connection

class Connection

Bases: object

Uni-directional connection implemented over dragon.channels

__init__(*, inbound_initializer=None, outbound_initializer=None, options=None, policy=Policy((WaitMode(2), ReturnWhen(2))))

Initializes the Connection object.

The object is initialized in an inbound direction, an outbound direction, or both. These initializers can be either

  • a Channel object, whose lifecycle is assumed externally managed

  • a bytes-like descriptor, attached to lazily, destroyed automatically

  • a string name, for a rendezvous in Global services.

Parameters:
  • inbound_initializer – an initializer for the inbound channel

  • outbound_initializer – an initializer for the outbound channel

  • options – a ConnectionOptions object

  • policy – a Policy object

Methods

__init__(*[, inbound_initializer, ...])

Initializes the Connection object.

close()

Send an end-of-transmission and detach from channel resources.

fileno()

Get the c_uid for the connection

ghost_close()

Force the connection into a closed state without sending EOT

open()

Construct the underlying channel resources if not already present.

poll([timeout, event_mask])

Wait for an event to occur on the connection, such as data is available.

recv()

Receive an object that was sent into the connection.

recv_bytes([maxlength])

Receive bytes data from the connection.

recv_bytes_into(buffer[, offset])

Receive bytes data from the connection placing it into the provided buffer.

send(obj)

Send an object that can later be received.

send_bytes(buffer[, offset, size])

Send bytes data into the connection.

thread_wait(timeout, done_ev, ready)

Thread waiter signaling with an ev.

Attributes

closed

True if the connection is closed

inbound_channel

The inbound channel

outbound_channel

The outbound channel

readable

True if the connection is readable

writable

True if the connection is writable

class State

Bases: Enum

CLOSED = 1
ATTACHED = 2
READY = 3
UNBACKED = 4
UNATTACHED = 5
classmethod __contains__(member)

Return True if member is a member of this enum raises TypeError if member is not an enum member

note: in 3.12 TypeError will no longer be raised, and True will also be returned if member is the value of a member in this enum

classmethod __getitem__(name)

Return the member matching name.

classmethod __len__()

Return the number of members (no aliases)

__init__(*, inbound_initializer=None, outbound_initializer=None, options=None, policy=Policy((WaitMode(2), ReturnWhen(2))))

Initializes the Connection object.

The object is initialized in an inbound direction, an outbound direction, or both. These initializers can be either

  • a Channel object, whose lifecycle is assumed externally managed

  • a bytes-like descriptor, attached to lazily, destroyed automatically

  • a string name, for a rendezvous in Global services.

Parameters:
  • inbound_initializer – an initializer for the inbound channel

  • outbound_initializer – an initializer for the outbound channel

  • options – a ConnectionOptions object

  • policy – a Policy object

open()

Construct the underlying channel resources if not already present.

send(obj)

Send an object that can later be received.

Parameters:

obj (obj) – Python object to send

recv()

Receive an object that was sent into the connection.

Returns:

returns an object

Return type:

obj

ghost_close()

Force the connection into a closed state without sending EOT

This ‘ghosts’ the receiver on the other end, which won’t be getting an EOT message from this object, but when using externally managed Channels on this object that is what one might want to do, in order to transfer use of that Channel.

thread_wait(timeout, done_ev, ready)

Thread waiter signaling with an ev.

close()

Send an end-of-transmission and detach from channel resources. Channels are ref-counted and automatically cleaned up once all processes detach.

property inbound_channel

The inbound channel

property outbound_channel

The outbound channel

property closed

True if the connection is closed

property readable

True if the connection is readable

property writable

True if the connection is writable

fileno()

Get the c_uid for the connection

Returns:

returns the underlying c_uid

Return type:

int

poll(timeout=0.0, event_mask=<EventType.POLLIN: 1>)

Wait for an event to occur on the connection, such as data is available.

Parameters:
send_bytes(buffer, offset=0, size=None)

Send bytes data into the connection.

Parameters:
  • buffer (bytearray or bytes ) – bytes data to send

  • offset (int ) – offset into the buffer to start sending from

  • size – number of bytes to send or all of it

recv_bytes(maxlength=None)

Receive bytes data from the connection.

Parameters:

maxlength (int ) – maximum number of bytes data to receive

Returns:

bytes data

Return type:

bytearray

recv_bytes_into(buffer, offset=0)

Receive bytes data from the connection placing it into the provided buffer.

Parameters:
  • buffer (bytes or bytearray ) – bytes or bytes array to write into

  • offset (int ) – bytes offset to start writing data at

Returns:

number of bytes received

Return type:

int