Revision 607fb914
som/net_helper-ml.c | ||
---|---|---|
267 | 267 |
* @param arg |
268 | 268 |
*/ |
269 | 269 |
static void connReady_cb (int connectionID, void *arg) { |
270 |
|
|
270 |
char mt; |
|
271 | 271 |
msgData_cb *p; |
272 | 272 |
p = (msgData_cb *)arg; |
273 | 273 |
if (p == NULL) return; |
... | ... | |
276 | 276 |
return; |
277 | 277 |
} |
278 | 278 |
mlSendData(connectionID,(char *)(sendingBuffer[p->bIdx]),p->mSize,p->msgType,NULL); |
279 |
/**/char mt = ((char*)sendingBuffer[p->bIdx])[0]; ++snd_counter;
|
|
279 |
/**/ mt = ((char*)sendingBuffer[p->bIdx])[0]; ++snd_counter;
|
|
280 | 280 |
if (mt!=MSG_TYPE_TOPOLOGY && |
281 | 281 |
mt!=MSG_TYPE_CHUNK && mt!=MSG_TYPE_SIGNALLING) { |
282 | 282 |
fprintf(stderr,"Net-helper ERROR! Sent message # %d of type %c and size %d\n", |
... | ... | |
317 | 317 |
*/ |
318 | 318 |
static void recv_data_cb(char *buffer, int buflen, unsigned char msgtype, recv_params *arg) { |
319 | 319 |
// TODO: lacks a void* arg... moreover: recv_params has a msgtype, but there is also a msgtype explicit argument... |
320 |
char str[SOCKETID_STRING_SIZE]; |
|
320 | 321 |
// fprintf(stderr, "Net-helper : called back with some news...\n"); |
321 | 322 |
/**/ ++recv_counter; |
322 |
char str[SOCKETID_STRING_SIZE]; |
|
323 | 323 |
if (arg->remote_socketID != NULL) |
324 | 324 |
mlSocketIDToString(arg->remote_socketID,str,SOCKETID_STRING_SIZE); |
325 | 325 |
else |
... | ... | |
356 | 356 |
struct nodeID *net_helper_init(const char *IPaddr, int port) { |
357 | 357 |
|
358 | 358 |
struct timeval tout = NH_ML_INIT_TIMEOUT; |
359 |
int s; |
|
359 |
int s, i;
|
|
360 | 360 |
base = event_base_new(); |
361 | 361 |
lookup_array = calloc(lookup_max,sizeof(struct nodeID *)); |
362 | 362 |
|
... | ... | |
368 | 368 |
me->connID = -10; // dirty trick to spot later if the ml has called back ... |
369 | 369 |
me->refcnt = 1; |
370 | 370 |
|
371 |
int i; |
|
372 | 371 |
for (i=0;i<NH_BUFFER_SIZE;i++) { |
373 | 372 |
sendingBuffer[i] = NULL; |
374 | 373 |
receivedBuffer[i].data = NULL; |
... | ... | |
436 | 435 |
*/ |
437 | 436 |
int send_to_peer(const struct nodeID *from, struct nodeID *to, const uint8_t *buffer_ptr, int buffer_size) |
438 | 437 |
{ |
438 |
msgData_cb *p; |
|
439 |
int current; |
|
440 |
send_params params = {0,0,0,0}; |
|
441 |
|
|
439 | 442 |
// if buffer is full, discard the message and return an error flag |
440 | 443 |
int index = next_S(); |
441 | 444 |
if (index<0) { |
... | ... | |
447 | 450 |
memset(sendingBuffer[index],0,buffer_size); |
448 | 451 |
memcpy(sendingBuffer[index],buffer_ptr,buffer_size); |
449 | 452 |
// free(buffer_ptr); |
450 |
msgData_cb *p = malloc(sizeof(msgData_cb));
|
|
453 |
p = malloc(sizeof(msgData_cb)); |
|
451 | 454 |
p->bIdx = index; p->mSize = buffer_size; p->msgType = (unsigned char)buffer_ptr[0]; p->conn_cb_called = false; p->cancelled = false; |
452 |
int current = p->bIdx;
|
|
453 |
send_params params = {0,0,0,0}; |
|
455 |
current = p->bIdx; |
|
456 |
|
|
454 | 457 |
to->connID = mlOpenConnection(to->addr,&connReady_cb,p, params); |
455 | 458 |
if (to->connID<0) { |
456 | 459 |
free_sending_buffer(current); |
Also available in: Unified diff