Synopsis
typedef unsigned (*CTL_TCP_ACCEPT_FN_t)(CTL_SOCKET_t);
Description

The Accept callback performs two functions:

When a SYN (synchronize, or "connect") packet arrives for a bound port, a check is first made to determine if there is a free socket and that the number of open sockets for the port is less than the max_connections value for that port.

If that check is passes, a socket is allocated and the port's accept callback is invoked, to make the final pass/fail judgment.

For example:

unsigned tcpAcceptCallbackFn(SOCKET s)
{
  // SOCKET s is not yet readable or writable, but does have
  // valid endpoint information.  You may choose to accept or
  // reject the connection based upon the remote TCP's IP
  // address, for example.

  // If the connection is accepted, ctl_tcp_use_callback() or
  // ctl_tcp_use_event() should be called to set up processing
  // of the TCP data.

  // Now is the time to adjust per-socket memory limits using
  // ctl_tcp_set_socket_options(), before the response is made
  // to the remote TCP's synchroization packet.

  if (we accept connection)
    return 1;
  else
    return 0;
}