Revision 0cb8677a som/net_helper.c

View differences:

som/net_helper.c
21 21
  int fd;
22 22
};
23 23

  
24
int wait4data(const struct nodeID *s, struct timeval *tout, fd_set *user_fds)
24
int wait4data(const struct nodeID *s, struct timeval *tout, int *user_fds)
25 25
{
26 26
  fd_set fds;
27
  int res;
27
  int i, res, max_fd;
28 28

  
29 29
  FD_ZERO(&fds);
30
  if (user_fds == NULL) {
31
    user_fds = &fds;
30
  max_fd = s->fd;
31
  if (user_fds) {
32
    for (i = 0; user_fds[i] != -1; i++) {
33
      FD_SET(user_fds[i], &fds);
34
      if (user_fds[i] > max_fd) {
35
        max_fd = user_fds[i];
36
      }
37
    }
32 38
  }
33
  FD_SET(s->fd, user_fds);
34
  res = select(s->fd + 1, user_fds, NULL, NULL, tout);
39
  FD_SET(s->fd, &fds);
40
  res = select(max_fd + 1, &fds, NULL, NULL, tout);
35 41
  if (res <= 0) {
36 42
    return res;
37 43
  }
38
  if (FD_ISSET(s->fd, user_fds)) {
44
  if (FD_ISSET(s->fd, &fds)) {
39 45
    return 1;
40 46
  }
41 47

  
48
  /* If execution arrives here, user_fds cannot be 0
49
     (an FD is ready, and it's not s->fd) */
50
  for (i = 0; user_fds[i] != -1; i++) {
51
    if (!FD_ISSET(user_fds[i], &fds)) {
52
      user_fds[i] = -2;
53
    }
54
  }
55

  
42 56
  return 2;
43 57
}
44 58

  

Also available in: Unified diff