Revision 4c9e6c8b

View differences:

input-udp.c
30 30
  int id;
31 31
  int interframe;
32 32
  uint64_t start_time;
33
  uint8_t *data;
34
  int size;
35
  int counter;
36
  int every;
33 37
};
34 38

  
35 39
static int listen_udp(int port)
......
87 91
    }
88 92
  }
89 93

  
94
  desc->every = 1;
95

  
90 96
  return 1;
91 97
}
92 98

  
......
137 143
  //res->id = (res->start_time / res->interframe) % INT_MAX; //FIXME
138 144
  res->id = 1;
139 145

  
146
  res->data = NULL;
147
  res->size = 0;
148
  res->counter = 0;
149

  
140 150
  return res;
141 151
}
142 152

  
......
157 167
  size_t buflen = UDP_BUF_SIZE;
158 168
  ssize_t msglen;
159 169
  struct timeval now;
170
  uint8_t *data;
160 171

  
161 172
  fprintf(stderr,"\treading on fd:%d (index:%d)\n", s->fds[fd_index], fd_index);
162 173
  msglen = recv(s->fds[fd_index], buf, buflen, MSG_DONTWAIT);
......
170 181
  }
171 182
  fprintf(stderr,"\treceived %d bytes\n",msglen);
172 183

  
173
  c->data = malloc(sizeof(struct io_udp_header) + msglen);
174
  ((struct io_udp_header*)c->data)->size = msglen;
175
  ((struct io_udp_header*)c->data)->portdiff = fd_index;
176
  memcpy(c->data + sizeof(struct io_udp_header), buf, msglen);
177
  c->size = sizeof(struct io_udp_header) + msglen;
184
  s->data = realloc(s->data, s->size + sizeof(struct io_udp_header) + msglen);
185
  data = s->data + s->size;
186
  ((struct io_udp_header*)data)->size = msglen;
187
  ((struct io_udp_header*)data)->portdiff = fd_index;
188
  memcpy(data + sizeof(struct io_udp_header), buf, msglen);
189
  s->size += sizeof(struct io_udp_header) + msglen;
190

  
191
  if (++s->counter % s->every) {
192
    c->data = NULL;
193
    return 0;
194
  }
178 195

  
196
  c->data = s->data;
197
  s->data = NULL;
198
  c->size = s->size;
199
  s->size = 0;
179 200
  c->id = s->id++;
180 201
  c->attributes_size = 0;
181 202
  c->attributes = NULL;
182 203
  gettimeofday(&now, NULL);
183 204
  c->timestamp = now.tv_sec * 1000000ULL + now.tv_usec;
205
  s->counter = 0;
184 206

  
185 207
  return 1;
186 208
}

Also available in: Unified diff