Revision 975180d3

View differences:

net_helper-ml.c
159 159
 * @return the index of a free slot in the sending msgs buffer, -1 if no free slot available.
160 160
 */
161 161
static int next_S() {
162
	const int size = 1024;
163
	if (sendingBuffer[sIdx]==NULL) {
164
		sendingBuffer[sIdx] = malloc(size);
165
	}
166
	else {
162
	if (sendingBuffer[sIdx]) {
167 163
		int count;
168 164
		for (count=0;count<NH_BUFFER_SIZE;count++) {
169
			sIdx = (++sIdx)%NH_BUFFER_SIZE;
165
			sIdx = (sIdx+1)%NH_BUFFER_SIZE;
170 166
			if (sendingBuffer[sIdx]==NULL)
171 167
				break;
172 168
		}
173
		if (count==NH_BUFFER_SIZE)
169
		if (count==NH_BUFFER_SIZE) {
174 170
			return -1;
175
		else {
176
			sendingBuffer[sIdx] = malloc(size);
177 171
		}
178 172
	}
179 173
	return sIdx;
......
433 427
	int index = next_S();
434 428
	if (index<0) {
435 429
		// free(buffer_ptr);
436
		fprintf(stderr,"Net-helper: buffer full\n ");
430
		fprintf(stderr,"Net-helper: send buffer full\n ");
431
		return -1;
432
	}
433
	sendingBuffer[index] = malloc(buffer_size);
434
	if (! sendingBuffer[index]){
435
		fprintf(stderr,"Net-helper: memory full, can't send!\n ");
437 436
		return -1;
438 437
	}
439
	sendingBuffer[index] = realloc(sendingBuffer[index],buffer_size);
440 438
	memset(sendingBuffer[index],0,buffer_size);
441 439
	memcpy(sendingBuffer[index],buffer_ptr,buffer_size);
442 440
	// free(buffer_ptr);

Also available in: Unified diff