From 7c321d614e8d91b23434b13bfcf89274797815ec Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Sat, 22 Apr 2017 22:24:06 +0200 Subject: Initial Commit. --- src/meta_net/meta_net_select.c | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/meta_net/meta_net_select.c (limited to 'src/meta_net/meta_net_select.c') diff --git a/src/meta_net/meta_net_select.c b/src/meta_net/meta_net_select.c new file mode 100644 index 0000000..069a671 --- /dev/null +++ b/src/meta_net/meta_net_select.c @@ -0,0 +1,53 @@ +#include +#include + +#include "meta_net.h" + +int JH_meta_net_pre_select +( + struct JH_meta_net socket [const restrict static 1], + const struct JH_parameters params [const restrict static 1], + fd_set in [const restrict static 1], + fd_set out [const restrict static 1], + int max_fd [const restrict static 1] +) +{ + FD_SET(socket->fd, in); + FD_SET(socket->fd, out); + + if ((*max_fd) < socket->fd) + { + *max_fd = socket->fd; + } + + return 0; +} + +int JH_meta_net_post_select +( + struct JH_meta_net socket [const restrict static 1], + const struct JH_parameters params [const restrict static 1], + fd_set in [const restrict static 1], + fd_set out [const restrict static 1] +) +{ + if (FD_ISSET(socket->fd, in)) + { + if (JH_meta_net_read(socket) < 0) + { + /* TODO: Try to reconnect. */ + return -1; + } + } + + if (FD_ISSET(socket->fd, out)) + { + if (JH_meta_net_write(socket) < 0) + { + /* TODO: Try to reconnect. */ + return -1; + } + } + + return 0; +} -- cgit v1.2.3-70-g09d2