NetConnection

Generic interface implementing a stream type connection with input/output buffers. Used on both server and client side. Direct methods:

  • Connect. Starts the connecting process with the given peer address. This function returns:
    • true: the connect continues. Later on, if the connect:
      • succeeds → the ConnectHandler is called,
      • fails → the CloseHandler is called, indicating the error.
    • false: the connect failed right from the beginning. No other notifications are sent to application.
  • FlushAndClose. Initialize the closing, sends all data in output buffer, then closes connection.
  • ForceClose. Instantly closes the connection. Unsent data in output buffer is lost.
  • RequestReadEvents. Enables/disables the network reading. Useful when data is arriving too fast and the application cannot process that fast.
  • RequestWriteEvents. Enables/disables the network writing. No useful situations.
  • Write. Writes data to connection output buffer. No limit here. The connection will proceed in writing the buffered data to network, emptying the output buffer. The network writes are asynchronous and independent from application.
  • inbuf. Returns a reference to connection's input buffer. This buffer persistently stores the incoming network data.

To interact with the connection, the application must provide several PERMANENT callbacks, for notification receiving:

  • ConnectHandler. Called when the connection is fully established. This notification is sent only for client side connections. For server side connections, this is useless, as the acceptor spawns only completely established connections.
  • CloseHandler. Called when the connection got closed, no matter which side initiated the close.
  • ReadHandler. Called when new data arrived from the network. Use inbuf() to access the data.
  • WriteHandler. Called when there is some free space on the network. No useful situations.

NetConnection is extended by: TcpConnection, SslConnection.

See NetFactory.