#include <cat.h>
int cat_runsingle(cat_session *session);
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; }