interface

SocketHandler

interface SocketHandler<Data = unknown, DataBinaryType extends BinaryType = 'buffer'>

  • binaryType?: unknown

    Choose what ArrayBufferView is passed to the SocketHandler.data callback.

  • socket: Socket<Data>,
    error?: Error
    ): void | Promise<void>;
  • socket: Socket<Data>,
    error: Error
    ): void | Promise<void>;

    Called when the socket fails to be created.

    The promise returned by Bun.connect rejects after this function is called.

    When connectError is specified, the rejected promise is not added to the promise rejection queue (so it isn't reported as an unhandled promise rejection, since connectError handles it).

    When connectError is not specified, the rejected promise is added to the promise rejection queue.

  • socket: Socket<Data>,
    data: BinaryTypeList[DataBinaryType]
    ): void | Promise<void>;
  • socket: Socket<Data>
    ): void | Promise<void>;
  • socket: Socket<Data>
    ): void | Promise<void>;

    Called when the other end shuts down its side of the socket by sending a TCP FIN packet.

  • socket: Socket<Data>,
    error: Error
    ): void | Promise<void>;
  • socket: Socket<Data>,
    success: boolean,
    authorizationError: null | Error
    ): void;

    Called when the TLS handshake completes.

    @param success

    Whether the server authorized the connection despite authorizationError

    @param authorizationError

    The certificate authorization error, or null if there was none

  • socket: Socket<Data>
    ): void | Promise<void>;

    Called when the socket connects. For TLS sockets with no handshake handler, this is called only after the handshake completes.

  • socket: Socket<Data>
    ): void | Promise<void>;

    Called when a message times out.