Simple The moment you call accept(), something like this:
new_conn = accept(listen_sock, &addr, addr_len);
if (new_conn > 0)
{
if (total_connections < max_connections)
{
total_connections++;
register_connection(new_conn);
}
else
{
send_reject_msg(new_conn);
close(new_conn);
}
}
(and, of course, decrement total_connectionsat the point where you lose connection).
source
share