NAME

catnet_accept - accept connections on a listening socket

SYNOPSIS

#include <cat/cat.h>

int catnet_accept(cat_session *lsess, cat_session **newsess, int fd_ids);

DESCRIPTION

Accept an incoming connection on a listening socket in lsess and create a new session with the new socket as the specified fd_ids.

The pointer to the new session is returned in newsess.

Session lsess must have been set to a listening state by a call to catnet_listen().

When called, the function will block until a new connection is accepted. If the session is in non-blocking mode and there are no new connections pending, catnet_accept immediately returns CAT_EAGAIN.

When a connection is made, a new session is created, with the new connection inserted as the specified fd_ids.

If fd_ids is given as 0, it will default to the CLIENT descriptors (CAT_CLIENT_RFD and CAT_CLIENT_WFD).

If the newsess argument is NULL, the incoming connection is accepted in lsess instead of creating a new session. If the accepted connection uses CAT_CLIENT_RFD, the listening socket will be closed and lsess will no longer be a listening session.

The function returns CAT_OK if successful, otherwise a negative error code is returned.

SEE ALSO

cat, catnet, catnet_listen, catnet_settimeout