Revision ad6c7e81 net_helper-ml.c

View differences:

net_helper-ml.c
23 23
struct event_base *base;
24 24

  
25 25
#define NH_BUFFER_SIZE 100
26
#define NH_MSG_MAXSIZE 1024
27 26

  
28 27
static int sIdx = 0;
29 28
static int rIdx = 0;
......
56 55
 * @return the index of a free slot in the received msgs buffer, -1 if no free slot available.
57 56
 */
58 57
static int next_R() {
58
	const int size = 1024;
59 59
	if (receivedBuffer[rIdx][0]==NULL) {
60
		receivedBuffer[rIdx][0] = malloc(NH_MSG_MAXSIZE);
60
		receivedBuffer[rIdx][0] = malloc(size);
61 61
	}
62 62
	else {
63 63
		int count;
......
69 69
		if (count==NH_BUFFER_SIZE)
70 70
			return -1;
71 71
		else {
72
			receivedBuffer[rIdx][0] = malloc(NH_MSG_MAXSIZE);
72
			receivedBuffer[rIdx][0] = malloc(size);
73 73
		}
74 74
	}
75
	memset(receivedBuffer[rIdx][0],0,NH_MSG_MAXSIZE);
75
	memset(receivedBuffer[rIdx][0],0,size);
76 76
	return rIdx;
77 77
}
78 78

  
......
81 81
 * @return the index of a free slot in the sending msgs buffer, -1 if no free slot available.
82 82
 */
83 83
static int next_S() {
84
	const int size = 1024;
84 85
	if (sendingBuffer[sIdx]==NULL) {
85
		sendingBuffer[sIdx] = malloc(NH_MSG_MAXSIZE);
86
		sendingBuffer[sIdx] = malloc(size);
86 87
	}
87 88
	else {
88 89
		int count;
......
94 95
		if (count==NH_BUFFER_SIZE)
95 96
			return -1;
96 97
		else {
97
			sendingBuffer[sIdx] = malloc(NH_MSG_MAXSIZE);
98
			sendingBuffer[sIdx] = malloc(size);
98 99
		}
99 100
	}
100
	memset(sendingBuffer[sIdx],0,NH_MSG_MAXSIZE);
101 101
	return sIdx;
102 102
}
103 103

  
......
193 193
		fprintf(stderr,"Net-helper: Connection %d could not be established to send msg %d.\n ", connectionID,p->bIdx);
194 194
		free(sendingBuffer[p->bIdx]);
195 195
		sendingBuffer[p->bIdx] = NULL;
196
		free(p);
196
		p->mSize = -1;
197 197
	}
198 198
	//	event_base_loopbreak(base);
199 199
}
......
239 239
				memset(receivedBuffer[index][1], 0, sizeof(struct nodeID));
240 240
				nodeID *remote; remote = (nodeID*)(receivedBuffer[index][1]);
241 241
				receivedBuffer[index][0] = realloc(receivedBuffer[index][0],buflen+sizeof(int));
242
				*(receivedBuffer[index][0]) = buflen;
242
				memset(receivedBuffer[index][0],0,buflen+sizeof(int));
243
				memcpy(receivedBuffer[index][0],&buflen,sizeof(int));
244
				//*(receivedBuffer[index][0]) = buflen;
243 245
				memcpy((receivedBuffer[index][0])+sizeof(int),buffer,buflen);
244 246
				  // get the socketID of the sender
245 247
				remote->addr = malloc(SOCKETID_SIZE);
......
326 328
		// free(buffer_ptr);
327 329
		return -1;
328 330
	}
331
	sendingBuffer[index] = realloc(sendingBuffer[index],buffer_size);
332
	memset(sendingBuffer[index],0,buffer_size);
329 333
	memcpy(sendingBuffer[index],buffer_ptr,buffer_size);
330 334
	// free(buffer_ptr);
331 335
	msgData_cb *p = malloc(sizeof(msgData_cb));
......
346 350
		while (sendingBuffer[current] != NULL)
347 351
			event_base_loop(base,EVLOOP_ONCE);//  EVLOOP_NONBLOCK
348 352
//		fprintf(stderr,"Net-helper: Back from eventlib loop with status %d.\n", ok);
353
		int size = p->mSize;
349 354
		free(p);
350
		return buffer_size;
355
		return size;
351 356
	}
352 357

  
353 358
}

Also available in: Unified diff