Interface SocketCommListener


public interface SocketCommListener
The socket communication listener.
Author:
Christopher Mindus
  • Method Details

    • onCommOpen

      void onCommOpen(SocketCommNIO comm)
      Called when the communication link is opened.
      Parameters:
      comm - The socket communication instance.
    • onCommState

      void onCommState(SocketCommNIO comm)
      Called when the state changes.
    • onCommConnected

      void onCommConnected(SocketCommNIO comm)
      Called when the communication link is connected.
      Parameters:
      comm - The socket communication instance.
    • onCommData

      void onCommData(SocketCommNIO comm, ByteBuffer buf)
      Called when the communication link has received data.

      The listener must consume or copy the entire contents of buf before returning. The buffer is owned by the communication layer and is invalid once this method returns: it is cleared and reused for the next read, and in plain (non-secure) mode it is a single direct buffer shared by every socket served by the same WorkerNIO, so its contents may be replaced by data belonging to another connection.

      The buffer is equally invalid once the listener calls back into comm.close() or comm.send(): a re-entrant path can reach the read loop again and refill the buffer before the call returns. Consume or copy the data before making any such call.

      That rule is enforced rather than merely documented. Once SocketCommNIO.getState() reports CLOSING, the communication layer stops dispatching to this method altogether, on the plain and the secure path alike. Suppression begins at CLOSING, not at CLOSED, so it takes effect when a close is requested rather than when it completes. Reading continues in that state, so the peer's close_notify still arrives and end-of-stream is still detected; only the dispatch is suppressed. A listener that closes from inside this method therefore receives no further callback, where previously it could still be handed data that the peer had sent before the close completed.

      A listener that requires more data than buf currently holds, e.g. a protocol record split across TCP segments or TLS records, must copy the bytes into its own accumulator and retain its parse state across calls. It must never retain a reference to buf.

      Parameters:
      comm - The socket communication instance.
      buf - The received data. Must be fully consumed or copied before returning.
    • onCommTimeout

      void onCommTimeout(SocketCommNIO comm, boolean isReadTimeout)
      Called when the communication link has timed out on a read or write operation.
      Parameters:
      comm - The socket communication instance.
      isReadTimeout - Flag indicating read timeout when true, false indicates write timeout.
    • onCommError

      void onCommError(SocketCommNIO comm, IOException e)
      Called when the communication link is closed.
      Parameters:
      comm - The socket communication instance.
      e - The exception.
    • onCommClosed

      void onCommClosed(SocketCommNIO comm)
      Called when the communication link is closed.
      Parameters:
      comm - The socket communication instance.