summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-04-22 22:24:06 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-04-22 22:24:06 +0200
commit7c321d614e8d91b23434b13bfcf89274797815ec (patch)
tree58b8e4fcba63b38a052423401df413606a7e8076 /src/meta_net/meta_net_select.c
Initial Commit.
Diffstat (limited to 'src/meta_net/meta_net_select.c')
-rw-r--r--src/meta_net/meta_net_select.c53
1 files changed, 53 insertions, 0 deletions
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 <stdio.h>
+#include <sys/select.h>
+
+#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;
+}