summaryrefslogtreecommitdiff
blob: f1261760853a9bef98fccfbdb17565d9ac85c438 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#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);

   if (socket->out.length != 0)
   {
      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 ((socket->out.length != 0) && FD_ISSET(socket->fd, out))
   {
      if (JH_meta_net_write(socket) < 0)
      {
         /* TODO: Try to reconnect. */
         return -1;
      }
   }

   return 0;
}