Revision 4136911a loop.c

View differences:

loop.c
31 31
  }
32 32
}
33 33

  
34
static int wait4data(struct nodeID *s)
35
{
36
  fd_set fds;
37
  int res;
38
  struct timeval tv;
39
  int fd = getFD(s);
40

  
41
  FD_ZERO(&fds);
42
  FD_SET(fd, &fds);
43
  tout_init(&tv);
44
  res = select(fd + 1, &fds, NULL, NULL, &tv);
45
  if (FD_ISSET(fd, &fds)) {
46
    return fd;
47
  }
48

  
49
  return -1;
50
}
51

  
52 34
void loop(struct nodeID *s, int csize, int buff_size)
53 35
{
54 36
  int done = 0;
......
61 43
  topParseData(NULL, 0);
62 44
  stream_init(buff_size, s);
63 45
  while (!done) {
64
    int len;
65
    int fd;
46
    int len, res;
47
    struct timeval tv;
66 48

  
67
    fd = wait4data(s);
68
    if (fd > 0) {
49
    tout_init(&tv);
50
    res = wait4data(s, tv);
51
    if (res > 0) {
69 52
      struct nodeID *remote;
70 53

  
71
      len = recv_data(s, &remote, buff, BUFFSIZE);
54
      len = recv_from_peer(s, &remote, buff, BUFFSIZE);
72 55
      switch (buff[0] /* Message Type */) {
73 56
        case MSG_TYPE_TOPOLOGY:
74 57
          topParseData(buff, len);
......
107 90
  
108 91
  source_init(fname, s);
109 92
  while (!done) {
110
    int len;
111
    int fd;
93
    int len, res;
94
    struct timeval tv;
112 95

  
113
    fd = wait4data(s);
114
    if (fd > 0) {
96
    tout_init(&tv);
97
    res = wait4data(s, tv);
98
    if (res > 0) {
115 99
      struct nodeID *remote;
116 100

  
117
      len = recv_data(s, &remote, buff, BUFFSIZE);
101
      len = recv_from_peer(s, &remote, buff, BUFFSIZE);
118 102
      switch (buff[0] /* Message Type */) {
119 103
        case MSG_TYPE_TOPOLOGY:
120 104
          fprintf(stderr, "Top Parse\n");

Also available in: Unified diff