Browse code

- even more tcp receive bs - sip msg.buff & orig are no longer 0 terminated (to avoid an extra copy in the tcp case)

Andrei Pelinescu-Onciul authored on 10/12/2002 19:41:44
Showing 10 changed files
... ...
@@ -16,6 +16,8 @@ x (different way) add request header bitmap field for the modules
16 16
 
17 17
 
18 18
 High priority:
19
+- parse_uri should not copy anymore the uri members (and it should not 0
20
+ terminate them anylonger).
19 21
 x fix/replace T_REF/T_UNREF
20 22
 x review all the tm locking
21 23
 x if () {} else {}
... ...
@@ -60,5 +62,5 @@ x jku: branch hash computation over canonical values
60 60
 - jku: try CRC as opposed to MD5
61 61
 
62 62
 
63
-- freopen stdin, stdou to /dev/null
63
+x freopen stdin, stdout, stderr to /dev/null
64 64
 
... ...
@@ -224,9 +224,10 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p)
224 224
 	}
225 225
 	/* sent requests stats */
226 226
 	else STATS_TX_REQUEST(  msg->first_line.u.request.method_value );
227
+	
227 228
 	pkg_free(buf);
228 229
 	free(to);
229
-	/* received_buf & line_buf will be freed in receiv_msg by free_lump_list*/
230
+	/* received_buf & line_buf will be freed in receive_msg by free_lump_list*/
230 231
 	return 0;
231 232
 
232 233
 error1:
... ...
@@ -633,6 +633,8 @@ int main_loop()
633 633
 			 * so we open all first*/
634 634
 		}
635 635
 #ifdef USE_TCP
636
+			/* start tcp receivers */
637
+		if (tcp_init_children()<0) goto error;
636 638
 			/* start tcp master proc */
637 639
 		process_no++;
638 640
 		if ((pid=fork())<0){
... ...
@@ -641,7 +643,7 @@ int main_loop()
641 641
 		}else if (pid==0){
642 642
 			/* child */
643 643
 			/* is_main=0; */
644
-			tcp_main();
644
+			tcp_main_loop();
645 645
 		}else{
646 646
 			pt[process_no].pid=pid;
647 647
 			strncpy(pt[process_no].desc, "tcp main process", MAX_PT_DESC );
... ...
@@ -686,7 +688,11 @@ int main_loop()
686 686
 		goto error;
687 687
 	}
688 688
 
689
-	if (timer_list){
689
+#ifndef USE_TCP
690
+	/* if we are using tcp we always need the timer */
691
+	if (timer_list)
692
+#endif
693
+	{
690 694
 		/* fork again for the attendant process*/
691 695
 		process_no++;
692 696
 		if ((pid=fork())<0){
... ...
@@ -485,7 +485,7 @@ int parse_msg(char* buf, unsigned int len, struct sip_msg* msg)
485 485
 	
486 486
 error:
487 487
 	/* more debugging, msg->orig is/should be null terminated*/
488
-	LOG(L_ERR, "ERROR: parse_msg: message=<%s>\n", msg->orig);
488
+	LOG(L_ERR, "ERROR: parse_msg: message=<%.*s>\n", (int)msg->len, msg->orig);
489 489
 	return -1;
490 490
 }
491 491
 
... ...
@@ -60,7 +60,14 @@ inline static int process_count()
60 60
 		/* timer process */
61 61
 		+ (timer_list ? 1 : 0 )
62 62
 		/* fifo server */
63
-		+((fifo==NULL || strlen(fifo)==0) ? 0 : 1 );
63
+		+((fifo==NULL || strlen(fifo)==0) ? 0 : 1 )
64
+#ifdef USE_TCP
65
+		+ 1/* tcp main */ + tcp_children_no + 
66
+		(timer_list ? 0: 1) /* add the timer proc. if not already taken
67
+							   into account */
68
+#endif
69
+		
70
+		;
64 71
 }
65 72
 
66 73
 
... ...
@@ -75,7 +75,7 @@ int receive_msg(char* buf, unsigned int len, union sockaddr_union* src_su)
75 75
 	msg->len=len;
76 76
 	/* zero termination (termination of orig message bellow not that
77 77
 	   useful as most of the work is done with scrath-pad; -jiri  */
78
-	buf[len]=0;
78
+	/* buf[len]=0; */ /* WARNING: zero term removed! */
79 79
 	su2ip_addr(&msg->src_ip, src_su);
80 80
 	msg->dst_ip=bind_address->address; /* won't work if listening on 0.0.0.0 */
81 81
 	msg->id=msg_no;
... ...
@@ -86,7 +86,8 @@ int receive_msg(char* buf, unsigned int len, union sockaddr_union* src_su)
86 86
 		goto error01;
87 87
 	}
88 88
 	memcpy(msg->orig, buf, len);
89
-	msg->orig[len]=0; /* null terminate it,good for using str* functions
89
+	/* WARNING: zero term removed! */
90
+	/* msg->orig[len]=0; */ /* null terminate it,good for using str* functions
90 91
 						 on it*/
91 92
 	
92 93
 	if (parse_msg(buf,len, msg)!=0){
... ...
@@ -30,6 +30,7 @@
30 30
 #ifndef _tcp_conn_h
31 31
 #define _tcp_conn_h
32 32
 
33
+#include "ip_addr.h"
33 34
 
34 35
 
35 36
 #define TCP_BUF_SIZE 65535
... ...
@@ -76,8 +77,10 @@ struct tcp_connection{
76 76
 	struct tcp_req req; /* request data */
77 77
 	int refcnt;
78 78
 	int timeout; /* connection timeout, after this it will be removed*/
79
-	struct tcp_connection* next;
79
+	struct tcp_connection* next; /* next, prev in hash table, used by "main" */
80 80
 	struct tcp_connection* prev;
81
+	struct tcp_connection* c_next; /* child next prev (use locally) */
82
+	struct tcp_connection* c_prev;
81 83
 };
82 84
 
83 85
 
... ...
@@ -93,7 +96,8 @@ struct tcp_connection{
93 93
 
94 94
 
95 95
 /* add a tcpconn to a list*/
96
-#define tcpconn_listadd(head, c) \
96
+/* list head, new element, next member, prev member */
97
+#define tcpconn_listadd(head, c, next, prev) \
97 98
 	do{ \
98 99
 		/* add it at the begining of the list*/ \
99 100
 		(c)->next=(head); \
... ...
@@ -104,7 +108,7 @@ struct tcp_connection{
104 104
 
105 105
 
106 106
 /* remove a tcpconn from a list*/
107
-#define tcpconn_listrm(head, c) \
107
+#define tcpconn_listrm(head, c, next, prev) \
108 108
 	do{ \
109 109
 		if ((head)==(c)) (head)=(c)->next; \
110 110
 		if ((c)->next) (c)->next->prev=(c)->prev; \
... ...
@@ -50,7 +50,10 @@
50 50
 #include "pass_fd.h"
51 51
 #include "tcp_conn.h"
52 52
 #include "globals.h"
53
+#include "pt.h"
53 54
 #include "mem/mem.h"
55
+#include "mem/shm_mem.h"
56
+#include "timer.h"
54 57
 
55 58
 
56 59
 
... ...
@@ -77,7 +80,7 @@ struct tcp_child tcp_children[MAX_TCP_CHILDREN];
77 77
 
78 78
 
79 79
 
80
-struct tcp_connection*  tcpconn_add(int sock, union sockaddr_union* su)
80
+struct tcp_connection*  tcpconn_add(int sock, union sockaddr_union* su, int i)
81 81
 {
82 82
 	struct tcp_connection *c;
83 83
 	
... ...
@@ -89,13 +92,14 @@ struct tcp_connection*  tcpconn_add(int sock, union sockaddr_union* su)
89 89
 	}
90 90
 	c->s=sock;
91 91
 	c->su=*su;
92
+	c->sock_idx=i;
92 93
 	c->refcnt=0;
93 94
 	su2ip_addr(&c->ip, su);
94 95
 	init_tcp_req(&c->req);
95 96
 	c->timeout=get_ticks()+TCP_CON_TIMEOUT;
96 97
 
97 98
 	/* add it at the begining of the list*/
98
-	tcpconn_listadd(conn_list, c);
99
+	tcpconn_listadd(conn_list, c, next, prev);
99 100
 	return c;
100 101
 	
101 102
 error:
... ...
@@ -106,7 +110,7 @@ error:
106 106
 
107 107
 void tcpconn_rm(struct tcp_connection* c)
108 108
 {
109
-	tcpconn_listrm(conn_list, c);
109
+	tcpconn_listrm(conn_list, c, next, prev);
110 110
 	shm_free(c);
111 111
 }
112 112
 
... ...
@@ -115,16 +119,16 @@ void tcpconn_rm(struct tcp_connection* c)
115 115
 void tcpconn_timeout()
116 116
 {
117 117
 	struct tcp_connection *c, *next;
118
-	int jiffies;;
118
+	int ticks;;
119 119
 	
120 120
 	
121
-	jiffies=get_ticks();
121
+	ticks=get_ticks();
122 122
 	c=conn_list;
123 123
 	while(c){
124 124
 		next=c->next;
125
-		if ((c->refcnt==0) && (jiffies<c->timeout)) {
126
-			DBG("tcpconn_timeout: timeout for %p (%d < %d)\n",
127
-					c, jiffies, c->timeout);
125
+		if ((c->refcnt==0) && (ticks>c->timeout)) {
126
+			DBG("tcpconn_timeout: timeout for %p (%d > %d)\n",
127
+					c, ticks, c->timeout);
128 128
 			tcpconn_rm(c);
129 129
 		}
130 130
 		c=next;
... ...
@@ -179,20 +183,34 @@ error:
179 179
 static int send2child(struct tcp_connection* tcpconn)
180 180
 {
181 181
 	int i;
182
+	int min_busy;
183
+	int idx;
182 184
 	
185
+	min_busy=tcp_children[0].busy;
186
+	idx=0;
183 187
 	for (i=0; i<tcp_children_no; i++){
184 188
 		if (!tcp_children[i].busy){
185
-			tcp_children[i].busy=1;
186
-			tcp_children[i].n_reqs++;
187
-			tcpconn->refcnt++;
188
-			DBG("send2child: to child %d, %ld\n", i, (long)tcpconn);
189
-			send_fd(tcp_children[i].s, &tcpconn, sizeof(tcpconn), tcpconn->s);
189
+			idx=i;
190
+			min_busy=0;
191
+			break;
190 192
 			return 0;
193
+		}else if (min_busy>tcp_children[i].busy){
194
+			min_busy=tcp_children[i].busy;
195
+			idx=i;
191 196
 		}
192 197
 	}
193
-	if (i==tcp_children_no){
194
-		return -1;
198
+	
199
+	tcp_children[idx].busy++;
200
+	tcp_children[idx].n_reqs++;
201
+	tcpconn->refcnt++;
202
+	if (min_busy){
203
+		LOG(L_WARN, "WARNING: send2child:no free tcp receiver, "
204
+				" connection passed to the least busy one (%d)\n",
205
+				min_busy);
195 206
 	}
207
+	DBG("send2child: to child %d, %ld\n", idx, (long)tcpconn);
208
+	send_fd(tcp_children[idx].s, &tcpconn, sizeof(tcpconn), tcpconn->s);
209
+	
196 210
 	return 0; /* just to fix a warning*/
197 211
 }
198 212
 
... ...
@@ -236,8 +254,8 @@ void tcp_main_loop()
236 236
 	
237 237
 	while(1){
238 238
 		sel_set=master_set;
239
-		timeout->tv_sec=TCP_MAIN_SELECT_TIMEOUT;
240
-		timeout->tv_usec=0;
239
+		timeout.tv_sec=TCP_MAIN_SELECT_TIMEOUT;
240
+		timeout.tv_usec=0;
241 241
 		n=select(maxfd+1, &sel_set, 0 ,0 , &timeout);
242 242
 		if (n<0){
243 243
 			if (errno==EINTR) continue; /* just a signal */
... ...
@@ -260,7 +278,7 @@ void tcp_main_loop()
260 260
 				}
261 261
 				
262 262
 				/* add socket to list */
263
-				tcpconn=tcpconn_add(new_sock, &su);
263
+				tcpconn=tcpconn_add(new_sock, &su, r);
264 264
 				DBG("tcp_main_loop: new connection: %p %d\n",
265 265
 						tcpconn, tcpconn->s);
266 266
 				/* pass it to a child */
... ...
@@ -298,10 +316,11 @@ void tcp_main_loop()
298 298
 read_again:
299 299
 				bytes=read(tcp_children[r].s, response, sizeof(response));
300 300
 				if (bytes==0){
301
-					/* EOF -> bad, chidl has died */
301
+					/* EOF -> bad, child has died */
302 302
 					LOG(L_CRIT, "BUG: tcp_main_loop: dead child %d\n", r);
303 303
 					/* terminating everybody */
304
-					exit(-1);
304
+					FD_CLR(tcp_children[r].s, &master_set);
305
+					/*exit(-1)*/;
305 306
 				}else if (bytes<0){
306 307
 					if (errno==EINTR) goto read_again;
307 308
 					else{
... ...
@@ -351,7 +370,7 @@ read_again:
351 351
 
352 352
 
353 353
 /* starts the tcp processes */
354
-int tcp_main()
354
+int tcp_init_children()
355 355
 {
356 356
 	int r;
357 357
 	int sockfd[2];
... ...
@@ -373,6 +392,7 @@ int tcp_main()
373 373
 			goto error;
374 374
 		}
375 375
 		
376
+		process_no++;
376 377
 		pid=fork();
377 378
 		if (pid<0){
378 379
 			LOG(L_ERR, "ERROR: tcp_main: fork failed: %s\n",
... ...
@@ -385,14 +405,15 @@ int tcp_main()
385 385
 			tcp_children[r].s=sockfd[0];
386 386
 			tcp_children[r].busy=0;
387 387
 			tcp_children[r].n_reqs=0;
388
+			pt[process_no].pid=pid;
389
+			strncpy(pt[process_no].desc, "tcp receiver", MAX_PT_DESC);
388 390
 		}else{
389 391
 			/* child */
390 392
 			close(sockfd[0]);
391 393
 			tcp_receive_loop(sockfd[1]);
392 394
 		}
393 395
 	}
394
-	
395
-	tcp_main_loop();
396
+	return 0;
396 397
 error:
397 398
 	return -1;
398 399
 }
... ...
@@ -45,6 +45,7 @@
45 45
 #include "pass_fd.h"
46 46
 #include "globals.h"
47 47
 #include "receive.h"
48
+#include "timer.h"
48 49
 
49 50
 
50 51
 #define q_memchr memchr
... ...
@@ -59,7 +60,7 @@ int tcp_read(struct tcp_req *r, int fd)
59 59
 	bytes_free=TCP_BUF_SIZE- (int)(r->pos - r->buf);
60 60
 	
61 61
 	if (bytes_free==0){
62
-		fprintf(stderr, "buffer overrun, dropping\n");
62
+		LOG(L_ERR, "ERROR: tcp_read: buffer overrun, dropping\n");
63 63
 		r->error=TCP_REQ_OVERRUN;
64 64
 		return -1;
65 65
 	}
... ...
@@ -71,7 +72,7 @@ again:
71 71
 			return 0; /* nothing has been read */
72 72
 		}else if (errno == EINTR) goto again;
73 73
 		else{
74
-			fprintf(stderr, "error reading: %s\n", strerror(errno));
74
+			LOG(L_ERR, "ERROR: tcp_read: error reading: %s\n",strerror(errno));
75 75
 			r->error=TCP_READ_ERROR;
76 76
 			return -1;
77 77
 		}
... ...
@@ -299,7 +300,8 @@ int tcp_read_headers(struct tcp_req *r, int fd)
299 299
 				break;
300 300
 			
301 301
 			default:
302
-				fprintf(stderr, "BUG: unexpected state %d\n", r->state);
302
+				LOG(L_CRIT, "BUG: tcp_read_headers: unexpected state %d\n",
303
+						r->state);
303 304
 				abort();
304 305
 		}
305 306
 	}
... ...
@@ -310,23 +312,113 @@ skip:
310 310
 
311 311
 
312 312
 
313
+int tcp_read_req(struct tcp_connection* con)
314
+{
315
+	int bytes;
316
+	int state;
317
+	long size;
318
+	struct tcp_req* req;
319
+	int s;
320
+		
321
+		state=0;
322
+		s=con->fd;
323
+		req=&con->req;
324
+		if(req->complete==0 && req->error==TCP_REQ_OK){
325
+			bytes=tcp_read_headers(req, s);
326
+						/* if timeout state=0; goto end__req; */
327
+			DBG("read= %d bytes, parsed=%d, state=%d, error=%d\n",
328
+					bytes, req->parsed-req->buf, req->state, req->error );
329
+			if (bytes==-1){
330
+				LOG(L_ERR, "ERROR: tcp_read_req: error reading \n");
331
+				state=-1;
332
+				goto end_req;
333
+			}
334
+			if (bytes==0){
335
+				DBG( "tcp_read_req: EOF\n");
336
+				state=-1;
337
+				goto end_req;
338
+			}
339
+		
340
+		}
341
+		if (req->error!=TCP_REQ_OK){
342
+			LOG(L_ERR,"ERROR: tcp_read_req: bad request, state=%d, error=%d\n",
343
+					req->state, req->error);
344
+			state=-1;
345
+			goto end_req;
346
+		}
347
+		if (req->complete){
348
+			DBG("tcp_read_req: end of header part\n");
349
+			DBG("tcp_read_req: headers:\n%.*s.\n",
350
+					req->body-req->buf, req->buf);
351
+			if (req->has_content_len){
352
+				DBG("tcp_read_req: content-length= %d\n", req->content_len);
353
+				DBG("tcp_read_req: body:\n%.*s\n", req->content_len,req->body);
354
+			}else{
355
+				req->error=TCP_REQ_BAD_LEN;
356
+				LOG(L_ERR, "ERROR: tcp_read_req: content length not present or"
357
+						" unparsable\n");
358
+				state=-1;
359
+				goto end_req;
360
+			}
361
+			/* if we are here everything is nice and ok*/
362
+			state=0;
363
+			/* just for debugging use sendipv4 as receiving socket */
364
+			DBG("calling receive_msg(%p, %d, )\n",
365
+					req->buf, (int)(req->parsed-req->buf));
366
+			bind_address=sendipv4; /*&tcp_info[con->sock_idx];*/
367
+			receive_msg(req->buf, req->parsed-req->buf, &con->su);
368
+			
369
+			/* prepare for next request */
370
+			size=req->pos-req->body;
371
+			if (size) memmove(req->buf, req->body, size);
372
+			DBG("tcp_read_req: preparing for new request, kept %ld bytes\n",
373
+					size);
374
+			req->pos=req->buf+size;
375
+			req->parsed=req->buf;
376
+			req->body=0;
377
+			req->error=TCP_REQ_OK;
378
+			req->state=H_STARTWS;
379
+			req->complete=req->content_len=req->has_content_len=0;
380
+			req->bytes_to_go=0;
381
+			
382
+		}
383
+		
384
+		
385
+	end_req:
386
+		return state;
387
+}
388
+
389
+
390
+
391
+void release_tcpconn(struct tcp_connection* c, long state, int unix_sock)
392
+{
393
+	long response[2];
394
+	
395
+		DBG( "releasing con %p, state %ld\n", c, state );
396
+		/* release req & signal the parent */
397
+		if (c->fd!=-1) close(c->fd);
398
+		/* errno==EINTR, EWOULDBLOCK a.s.o todo */
399
+		response[0]=(long)c;
400
+		response[1]=state;
401
+		write(unix_sock, response, sizeof(response));
402
+}
403
+
404
+
313 405
 
314 406
 void tcp_receive_loop(int unix_sock)
315 407
 {
316
-	struct tcp_req* req;
317 408
 	struct tcp_connection* list; /* list with connections in use */
318 409
 	struct tcp_connection* con;
319
-	int bytes;
320
-	long size;
410
+	struct tcp_connection* c_next;
321 411
 	int n;
322 412
 	int nfds;
323 413
 	int s;
324 414
 	long state;
325
-	long response[2];
326 415
 	fd_set master_set;
327 416
 	fd_set sel_set;
328 417
 	int maxfd;
329 418
 	struct timeval timeout;
419
+	int ticks;
330 420
 	
331 421
 	
332 422
 	/* init */
... ...
@@ -337,8 +429,8 @@ void tcp_receive_loop(int unix_sock)
337 337
 	
338 338
 	/* listen on the unix socket for the fd */
339 339
 	for(;;){
340
-			timeout->tv_sec=TCP_CHILD_SELECT_TIMEOUT;
341
-			timeout->tv_usec=0;
340
+			timeout.tv_sec=TCP_CHILD_SELECT_TIMEOUT;
341
+			timeout.tv_usec=0;
342 342
 			sel_set=master_set;
343 343
 			nfds=select(maxfd+1, &sel_set, 0 , 0 , &timeout);
344 344
 			if (nfds<0){
... ...
@@ -366,97 +458,52 @@ void tcp_receive_loop(int unix_sock)
366 366
 					LOG(L_ERR, "WARNING: tcp_receive_loop: 0 bytes read\n");
367 367
 					continue;
368 368
 				}
369
-				DBG("received n=%d con=%ld, fd=%d\n", n, con, s);
369
+				con->fd=s;
370
+				DBG("received n=%d con=%p, fd=%d\n", n, con, s);
370 371
 				if (s==-1) {
371 372
 					LOG(L_ERR, "ERROR: tcp_receive_loop: read_fd:"
372 373
 									"no fd read\n");
373 374
 					state=-1;
374
-					goto end_req; /* ?*/
375
+					release_tcpconn(con, state, unix_sock);
375 376
 				}
376 377
 				if (con==0){
377 378
 					LOG(L_ERR, "ERROR: tcp_receive_loop: null pointer\n");
378 379
 					state=-1;
379
-					goto end_req;
380
+					release_tcpconn(con, state, unix_sock);
380 381
 				}
381
-				con->fd=s;
382
+				con->timeout=get_ticks()+TCP_CHILD_TIMEOUT;
382 383
 				FD_SET(s, &master_set);
383 384
 				if (maxfd<s) maxfd=s;
384
-				tcpconn_listadd(list, con);
385
+				tcpconn_listadd(list, con, c_next, c_prev);
385 386
 			}
386
-			for (con=list; con && nfds ; con=con->next){
387
-				if (FD_ISSET(con->fd, &sel_set)){
387
+			ticks=get_ticks();
388
+			for (con=list; con ; con=c_next){
389
+				c_next=con->c_next; /* safe for removing*/
390
+				if (nfds && FD_ISSET(con->fd, &sel_set)){
388 391
 					nfds--;
389
-					req=&con->req;
390
-again:
391
-		while(req->complete==0 && req->error==TCP_REQ_OK){
392
-			bytes=tcp_read_headers(req, s);
393
-						/* if timeout state=0; goto end__req; */
394
-			fprintf(stderr, "read= %d bytes, parsed=%d, state=%d, error=%d\n",
395
-					bytes, req->parsed-req->buf, req->state, req->error );
396
-			if (bytes==-1){
397
-				fprintf(stderr, "ERROR!\n");
398
-				state=-1;
399
-				goto end_req;
400
-			}
401
-			if (bytes==0){
402
-				fprintf(stderr, "EOF!\n");
403
-				state=-1;
404
-				goto end_req;
392
+					state=tcp_read_req(con);
393
+					if (state==-1){
394
+						FD_CLR(con->fd, &master_set);
395
+						tcpconn_listrm(list, con, c_next, c_prev);
396
+						release_tcpconn(con, state, unix_sock);
397
+					}else{
398
+						/* update timeout */
399
+						con->timeout=ticks+TCP_CHILD_TIMEOUT;
400
+					}
401
+				}else{
402
+					/* timeout */
403
+					if (con->timeout<=ticks){
404
+						/* expired, return to "tcp main" */
405
+						DBG("tcp_receive_loop: %p expired (%d, %d)\n",
406
+								con, con->timeout, ticks);
407
+						state=0;
408
+						FD_CLR(con->fd, &master_set);
409
+						tcpconn_listrm(list, con, c_next, c_prev);
410
+						release_tcpconn(con, state, unix_sock);
411
+					}
412
+				}
405 413
 			}
406
-
407
-		}
408
-		if (req->error!=TCP_REQ_OK){
409
-			fprintf(stderr, "bad request, state=%d, error=%d\n",
410
-					req->state, req->error);
411
-			state=-1;
412
-			goto end_req;
413
-		}
414
-		fprintf(stderr, "end of header part\n");
415
-		fprintf(stderr, "headers:\n%.*s.\n",req->body-req->buf, req->buf);
416
-		if (req->has_content_len){
417
-			fprintf(stderr, "content-length= %d\n", req->content_len);
418
-			fprintf(stderr, "body:\n%.*s\n", req->content_len, req->body);
419
-		}else{
420
-			req->error=TCP_REQ_BAD_LEN;
421
-			fprintf(stderr, "content length not present or unparsable\n");
422
-			state=-1;
423
-			goto end_req;
424
-		}
425
-
426
-		/* if we are here everything is nice and ok*/
427
-		state=0;
428
-		/* just for debugging use sendipv4 as receiving socket */
429
-		DBG("calling receive_msg(%p, %d, %p)\n",
430
-				req->buf, (int)(req->parsed-req->buf), &sendipv4->su);
431
-		bind_address=sendipv4;
432
-		receive_msg(req->buf, req->parsed-req->buf, &sendipv4->su);
433
-
434
-		/* prepare for next request */
435
-		size=req->pos-req->body;
436
-		if (size) memmove(req->buf, req->body, size);
437
-		fprintf(stderr, "\npreparing for new request, kept %ld bytes\n", size);
438
-		req->pos=req->buf+size;
439
-		req->parsed=req->buf;
440
-		req->body=0;
441
-		req->error=TCP_REQ_OK;
442
-		req->state=H_STARTWS;
443
-		req->complete=req->content_len=req->has_content_len=0;
444
-		req->bytes_to_go=0;
445
-	
446
-		/* process last req. */
447 414
 		
448
-		goto again;
449
-		
450
-	end_req:
451
-			fprintf(stderr, "end req\n");
452
-		/* release req & signal the parent */
453
-		if (s!=-1) close(s);
454
-		/* errno==EINTR, EWOULDBLOCK a.s.o todo */
455
-		response[0]=con;
456
-		response[1]=state;
457
-		write(unix_sock, response, sizeof(response));
458
-		
459
-	
460 415
 	}
461 416
 }
462 417
 
... ...
@@ -25,6 +25,7 @@ rev_dns=off      # (cmd. line: -R)
25 25
 # for more info: sip_router -h
26 26
 alias=iptel.org
27 27
 alias="foo.bar"
28
+fifo="/tmp/ser_fifo"
28 29
 
29 30
 #modules
30 31