TCPConnectionNotify

[Source]

Notifications for TCP connections.

For an example of using this class please see the documentation for the TCPConnection and TCPListener actors.

interface ref TCPConnectionNotify

Public Functions

accepted

[Source]

Called when a TCPConnection is accepted by a TCPListener.

fun ref accepted(
  conn: TCPConnection ref)
: None val

Parameters

Returns

proxy_via

[Source]

Called before before attempting to connect to the destination server In order to connect via proxy, return the host & service for the proxy server.

An implementation of this function might look like:

let _proxy_host = "some-proxy.example.com"
let _proxy_service = "80"
var _destination_host: ( None | String )
var _destination_service: ( None | String )

fun ref proxy_via(host: String, service: String): (String, String) =>
  _destination_host = host
  _destination_service = service
  ( _proxy_host, _proxy_service )
fun ref proxy_via(
  host: String val,
  service: String val)
: (String val , String val)

Parameters

Returns

connecting

[Source]

Called if name resolution succeeded for a TCPConnection and we are now waiting for a connection to the server to succeed. The count is the number of connections we're trying. The notifier will be informed each time the count changes, until a connection is made or connect_failed() is called.

fun ref connecting(
  conn: TCPConnection ref,
  count: U32 val)
: None val

Parameters

Returns

connected

[Source]

Called when we have successfully connected to the server.

fun ref connected(
  conn: TCPConnection ref)
: None val

Parameters

Returns

connect_failed

[Source]

Called when we have failed to connect to all possible addresses for the server. At this point, the connection will never be established.

It is expected to implement proper error handling. You need to opt in to ignoring errors, which can be implemented like this:

fun ref connect_failed(conn: TCPConnection ref) =>
  None
fun ref connect_failed(
  conn: TCPConnection ref)
: None val

Parameters

Returns

auth_failed

[Source]

A raw TCPConnection has no authentication mechanism. However, when protocols are wrapped in other protocols, this can be used to report an authentication failure in a lower level protocol (e.g. SSL).

fun ref auth_failed(
  conn: TCPConnection ref)
: None val

Parameters

Returns

sent

[Source]

Called when data is sent on the connection. This gives the notifier an opportunity to modify sent data before it is written. To swallow data, return an empty string.

fun ref sent(
  conn: TCPConnection ref,
  data: (String val | Array[U8 val] val))
: (String val | Array[U8 val] val)

Parameters

Returns

sentv

[Source]

Called when multiple chunks of data are sent to the connection in a single call. This gives the notifier an opportunity to modify the sent data chunks before they are written. To swallow the send, return an empty Array[String].

fun ref sentv(
  conn: TCPConnection ref,
  data: ByteSeqIter val)
: ByteSeqIter val

Parameters

Returns

received

[Source]

Called when new data is received on the connection. Return true if you want to continue receiving messages without yielding until you read max_size on the TCPConnection. Return false to cause the TCPConnection to yield now.

Includes the number of times during the current behavior, that received has been called. This allows the notifier to end reads on a regular basis.

fun ref received(
  conn: TCPConnection ref,
  data: Array[U8 val] iso,
  times: USize val)
: Bool val

Parameters

Returns

expect

[Source]

Called when the connection has been told to expect a certain quantity of bytes. This allows nested notifiers to change the expected quantity, which allows a lower level protocol to handle any framing (e.g. SSL).

fun ref expect(
  conn: TCPConnection ref,
  qty: USize val)
: USize val

Parameters

Returns

closed

[Source]

Called when the connection is closed.

fun ref closed(
  conn: TCPConnection ref)
: None val

Parameters

Returns

throttled

[Source]

Called when the connection starts experiencing TCP backpressure. You should respond to this by pausing additional calls to write and writev until you are informed that pressure has been released. Failure to respond to the throttled notification will result in outgoing data queuing in the connection and increasing memory usage.

fun ref throttled(
  conn: TCPConnection ref)
: None val

Parameters

Returns

unthrottled

[Source]

Called when the connection stops experiencing TCP backpressure. Upon receiving this notification, you should feel free to start making calls to write and writev again.

fun ref unthrottled(
  conn: TCPConnection ref)
: None val

Parameters

Returns

© 2016-2020, The Pony Developers
© 2014-2015, Causality Ltd.
Licensed under the BSD 2-Clause License.
https://stdlib.ponylang.io/net-TCPConnectionNotify