Browse code

- fixed tls on same port as tcp init problem (e.g. for -l 127.0.0.1:5080) - added a new tcp connection flag, set when the tcp connection is removed from the main pool - fixed tcp_read_req reported bytes count (necessary for certain types of poll stategies)

Andrei Pelinescu-Onciul authored on 28/10/2005 20:59:37
Showing 5 changed files
... ...
@@ -60,7 +60,7 @@ MAIN_NAME=ser
60 60
 VERSION = 0
61 61
 PATCHLEVEL = 10
62 62
 SUBLEVEL =   99
63
-EXTRAVERSION = -dev20-tcp
63
+EXTRAVERSION = -dev21-tcp
64 64
 
65 65
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
66 66
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -369,6 +369,12 @@ int add_listen_iface(char* name, unsigned short port, unsigned short proto,
369 369
 #endif
370 370
 				port_no;
371 371
 		}
372
+#ifdef USE_TLS
373
+		else if ((c_proto==PROTO_TLS) && (proto==0)){
374
+			/* -l  ip:port => on udp:ip:port; tcp:ip:port and tls:ip:port+1? */
375
+			port++;
376
+		}
377
+#endif
372 378
 		if (new_sock2list(name, port, c_proto, flags, list)<0){
373 379
 			LOG(L_ERR, "ERROR: add_listen_iface: new_sock2list failed\n");
374 380
 			goto error;
... ...
@@ -58,6 +58,7 @@
58 58
 
59 59
 /* tcp connection flags */
60 60
 #define F_CONN_NON_BLOCKING 1
61
+#define F_CONN_REMOVED      2 /* no longer  in "main" listen fd list */
61 62
 
62 63
 
63 64
 enum tcp_req_errors {	TCP_REQ_INIT, TCP_REQ_OK, TCP_READ_ERROR,
... ...
@@ -414,6 +414,7 @@ struct tcp_connection* tcpconn_new(int sock, union sockaddr_union* su,
414 414
 	c->rcv.proto_reserved2=0;
415 415
 	c->state=state;
416 416
 	c->extra_data=0;
417
+	c->flags|=F_CONN_REMOVED;
417 418
 #ifdef USE_TLS
418 419
 	if (type==PROTO_TLS){
419 420
 		if (tls_tcpconn_init(c, sock)==-1) goto error;
... ...
@@ -1102,6 +1103,7 @@ inline static int handle_tcpconn_ev(struct tcp_connection* tcpconn, int fd_i)
1102 1102
 	/* pass it to child, so remove it from the io watch list */
1103 1103
 	DBG("handle_tcpconn_ev: data available on %p %d\n", tcpconn, tcpconn->s);
1104 1104
 	if (io_watch_del(&io_h, tcpconn->s, fd_i, 0)==-1) goto error;
1105
+	tcpconn->flags|=F_CONN_REMOVED;
1105 1106
 	tcpconn_ref(tcpconn); /* refcnt ++ */
1106 1107
 	if (send2child(tcpconn)<0){
1107 1108
 		LOG(L_ERR,"ERROR: handle_tcpconn_ev: no children available\n");
... ...
@@ -1205,6 +1207,7 @@ inline static int handle_tcp_child(struct tcp_child* tcp_c, int fd_i)
1205 1205
 			tcpconn_put(tcpconn);
1206 1206
 			/* must be after the de-ref*/
1207 1207
 			io_watch_add(&io_h, tcpconn->s, F_TCPCONN, tcpconn);
1208
+			tcpconn->flags&=~F_CONN_REMOVED;
1208 1209
 			DBG("handle_tcp_child: CONN_RELEASE  %p refcnt= %d\n", 
1209 1210
 											tcpconn, tcpconn->refcnt);
1210 1211
 			break;
... ...
@@ -1311,8 +1314,10 @@ inline static int handle_ser_child(struct process_table* p, int fd_i)
1311 1311
 	}
1312 1312
 	switch(cmd){
1313 1313
 		case CONN_ERROR:
1314
-			if (tcpconn->s!=-1)
1314
+			if (!(tcpconn->flags & F_CONN_REMOVED) && (tcpconn->s!=-1)){
1315 1315
 				io_watch_del(&io_h, tcpconn->s, -1, IO_FD_CLOSING);
1316
+				tcpconn->flags|=F_CONN_REMOVED;
1317
+			}
1316 1318
 			tcpconn_destroy(tcpconn); /* will close also the fd */
1317 1319
 			break;
1318 1320
 		case CONN_GET_FD:
... ...
@@ -1339,6 +1344,7 @@ inline static int handle_ser_child(struct process_table* p, int fd_i)
1339 1339
 			/* update the timeout*/
1340 1340
 			tcpconn->timeout=get_ticks()+tcp_con_lifetime;
1341 1341
 			io_watch_add(&io_h, tcpconn->s, F_TCPCONN, tcpconn);
1342
+			tcpconn->flags&=~F_CONN_REMOVED;
1342 1343
 			break;
1343 1344
 		default:
1344 1345
 			LOG(L_CRIT, "BUG: handle_ser_child: unknown cmd %d\n", cmd);
... ...
@@ -1423,7 +1429,10 @@ static inline void tcpconn_timeout(int force)
1423 1423
 #endif
1424 1424
 				_tcpconn_rm(c);
1425 1425
 				if ((fd>0)&&(c->refcnt==0)) {
1426
-					io_watch_del(&io_h, fd, -1, IO_FD_CLOSING);
1426
+					if (!(c->flags & F_CONN_REMOVED)){
1427
+						io_watch_del(&io_h, fd, -1, IO_FD_CLOSING);
1428
+						c->flags|=F_CONN_REMOVED;
1429
+					}
1427 1430
 					close(fd);
1428 1431
 				}
1429 1432
 				tcp_connections_no--;
... ...
@@ -400,6 +400,7 @@ skip:
400 400
 int tcp_read_req(struct tcp_connection* con, int* bytes_read)
401 401
 {
402 402
 	int bytes;
403
+	int total_bytes;
403 404
 	int resp;
404 405
 	long size;
405 406
 	struct tcp_req* req;
... ...
@@ -407,6 +408,7 @@ int tcp_read_req(struct tcp_connection* con, int* bytes_read)
407 407
 	char c;
408 408
 		
409 409
 		bytes=-1;
410
+		total_bytes=0;
410 411
 		resp=CONN_RELEASE;
411 412
 		s=con->fd;
412 413
 		req=&con->req;
... ...
@@ -437,6 +439,7 @@ again:
437 437
 				resp=CONN_ERROR;
438 438
 				goto end_req;
439 439
 			}
440
+			total_bytes+=bytes;
440 441
 			/* eof check:
441 442
 			 * is EOF if eof on fd and req.  not complete yet,
442 443
 			 * if req. is complete we might have a second unparsed
... ...
@@ -533,7 +536,7 @@ again:
533 533
 		
534 534
 		
535 535
 	end_req:
536
-		if (bytes_read) *bytes_read=bytes;
536
+		if (bytes_read) *bytes_read=total_bytes;
537 537
 		return resp;
538 538
 }
539 539