NAME

catnet_listener - run a listener and serve connections

SYNOPSIS

#include <cat/cat.h>

int catnet_listener(const char *ports[], catnet_sessfunc *newsession);

DESCRIPTION

This function blocks and waits for connections to all the ports specified in the ports argument. This argument consists of an array of strings, each of which will be used as an argument to catnet_listen(). The last element of the ports array must be NULL.

The newsession() function will be called to handle each new connection. The function should match the following prototype:

  typedef int catnet_sessfunc(cat_session *sess, const char *port);

The newsession() function is called when the session has been successfully accepted. The call is issued with the sess argument set to the new session for the accepted connection, and the port argument set to the ports array string that matched the incoming call.

Depending on the platform and other issues, newsession() may be called as a separate process or as a separate thread of the same process. The second argument to newsession() is the port to which the connection was made. This pointer is identical to the one in the ports array that was given as the extra argument. CAT_CLIENT_RFD and CAT_CLIENT_WFD will be connected to the client and CAT_SERVER_RFD and CAT_SERVER_WFD will remain unchanged.

If newsession() returns zero or CAT_CONTINUE, data will continue to be forwarded between the client and the server sides. If the function returns any other code (preferably CAT_EOF), the session will be closed.

catnet_listener() is implemented on top of catsock_run(), and should be used in place of that function.

SEE ALSO

cat, catnet

catnet_listen, catsock_run