IConnection

Description

interface Tinman.Core.IO.Sockets.IConnection

Derived from

IDisposable

Base interface for network connections.

Network connections provided by IConnection implementations are connection oriented and reliable.

See also

IEndPoint

Public / Methods

Close


public method Close → ()

Performs a graceful shutdown of the connection.

After gracefully closing a connection, its local endpoint might remain unusable for some time (for example, see the TIME_WAIT state of TCP/IP). Calling this method more than once is allowed but will have no effect. It will be called implicitly when the connection is disposed. However, calling Close explicitly allows the caller to handle the IOException, if thrown.

Connections to well-behaving clients should be terminated with a graceful shutdown.

IOException

If an I/O error has occurred.

Discard


public method Discard → ()

Discards the connection.

When discarding a connection, the remote peer receives an error (and will throw an IOException, for example). After a connection has been discarded, its local endpoint will be reusable immediately.

Connections to misbehaving clients should be terminated with a forceful discard.

IOException

If an I/O error has occurred.

Receive


public method Receive → (2)

buffer in : ByteBuffer

[not-null]
The byte buffer where to store the received bytes.

timeout opt : int32 = 0

[>=0]
The receive timeout in milliseconds or 0 for no timeout.

returns → bool

true if exactly N bytes have been received and written to buffer in,
false iff the remote peer has been closed (via Close, for example) or timeout opt has elapsed. In this case, up to N-1 bytes may have been received and written to buffer in.

Receives a sequence of bytes from this network connection.

The number of bytes to receive (N) is the number of ByteBuffer.Remaining bytes in the given ByteBuffer. The received bytes will be written to the buffer in beginning at its current ByteBuffer.Position, incrementing it while receiving. If necessary, the method will block until all data has been received.

IOException

If an I/O error has occurred.

Send


public method Send → (2)

buffer in : ByteBuffer

[not-null]
The byte buffer that holds the bytes to send.

timeout opt : int32 = 0

[>=0]
The send timeout in milliseconds or 0 for no timeout.

returns → bool

true if exactly N bytes have been read from buffer in and sent,
false if timeout opt has elapsed. In this case, up to N-1 bytes may have been read from buffer in and sent.

Sends a sequence of bytes over this network connection.

The number of bytes to send (N) is the number of ByteBuffer.Remaining bytes in the given ByteBuffer. The bytes to send will be read from the buffer in beginning at its current ByteBuffer.Position, incrementing it while sending. If necessary, the method will block until all data has been sent (or buffered) by the network layer.

IOException

If an I/O error has occurred.

Public / Attributes

End​Point


public attribute EndPoint → (get)

value : IEndPoint

[not-null]
The remote network endpoint.

Returns the network endpoint of the remote side of this connection.