Revision 15edce59 chunker_player/tcp_chunk_puller.c

View differences:

chunker_player/tcp_chunk_puller.c
18 18
#include <netinet/in.h>
19 19
#include <unistd.h>
20 20

  
21
#define TCP_BUF_SIZE 65536
21
#define TCP_BUF_SIZE 65536*16
22 22

  
23 23
static int listen_port = 0;
24 24
static int accept_fd = -1;
......
49 49
	
50 50
	printf("listening on port %$d\n", port);
51 51
	
52
	listen(accept_fd, 10);
53
	
54 52
	if(pthread_create( &AcceptThread, NULL, &AcceptThreadProc, NULL) != 0)
55 53
	{
56 54
		fprintf(stderr,"TCP-INPUT-MODULE: could not start accepting thread!!\n");
......
67 65
    int fd = -1;
68 66
    
69 67
    isRunning = 1;
68

  
69
    listen(accept_fd, 10);
70 70
    
71 71
    while(isRunning)
72 72
    {
......
98 98
static void* RecvThreadProc(void* params)
99 99
{
100 100
	int ret = -1;
101
	int fragment_size = 0;
101
	uint32_t fragment_size = 0;
102 102
	uint8_t* buffer = (uint8_t*) malloc(TCP_BUF_SIZE);
103
	while(isReceving)
104
	{
103

  
104
	fprintf(stderr,"TCP-INPUT-MODULE: receive thread created\n");
105

  
106
	while(isReceving) {
105 107
		ret=recv(socket_fd, &fragment_size, sizeof(uint32_t), 0);
106
		if(ret <= sizeof(uint32_t))
107
			continue;
108
		
108
		fragment_size = ntohl(fragment_size);
109

  
110
fprintf(stderr, "TCP-INPUT-MODULE: received %d bytes. Fragment size: %d\n", ret, fragment_size);
111
		if(ret <= 0) {
112
			break;
113
		}
114

  
109 115
		ret=recv(socket_fd, buffer, fragment_size, 0);
110
		while(ret <= fragment_size)
116
fprintf(stderr, "TCP-INPUT-MODULE: received %d bytes.\n", ret);
117
		while(ret < fragment_size)
111 118
			ret+=recv(socket_fd, buffer+ret, fragment_size-ret, 0);
112 119
		
113 120
		if(enqueueBlock(buffer, fragment_size))
114 121
			fprintf(stderr, "TCP-INPUT-MODULE: could not enqueue a received chunk!! \n");
115 122
	}
116 123
	free(buffer);
117
	
124
	close(socket_fd);
125
	socket_fd = -1;
126

  
118 127
	return NULL;
119 128
}
120 129

  

Also available in: Unified diff