NAME

cat_runsingle - place a single session in server mode

SYNOPSIS

#include <cat.h>

int cat_runsingle(cat_session *session);

DESCRIPTION

Places a single session in server mode, where the session reads data from any descriptors ready for reading, filters the data through any registered filters, and writes to the corresponding peer (data from the client is sent to the server and vice versa).

The function returns when any of the filters or the I/O Handler signals end-of-file, or when the session times out if a timeout has been set with catnet_settimeout.

A cat_runsingle() function with a separate argument for timeout can be implemented as follows:

 #define FDS      (CAT_SERVER_RFD | CAT_CLIENT_RFD)
 #define FWD(FD)  ((FD) == CAT_CLIENT_RFD ? CAT_SERVER_WFD : CAT_CLIENT_WFD) 

 int
 cat_runsingle(cat_session *session, int timeout)
 {
     int ret, n, fd, fds;
     cat_buffer *buf;

     while ((fds = cat_poll(session, FDS, timeout)) > 0) {
          for (fd = 1, n = 0; n < CAT_NFDS; n++, fd <<= 1) {
              if (fd & fds) {
                  if ((ret = cat_recv(session, fd, &buf)) > 0) {
                      ret = cat_send(session, FWD(fd), buf);
                  }
                  if (ret < 0) {
                      return ret;
                  }
              }
          }
     }
     return fds;
 } 

SEE ALSO

cat, cat_pushfilter, catnet_settimeout