Browse code

- tcp fix ported from stable - minor beautifications

Andrei Pelinescu-Onciul authored on 25/08/2003 13:21:19
Showing 3 changed files
... ...
@@ -2,6 +2,7 @@ $Id$
2 2
 
3 3
 ( - todo, x - done)
4 4
 
5
+- add BUG checks for  fd > 0 && fd <= maxfd to all selects?
5 6
 x tcp_main_loop: BUG cases should "conitnue;"
6 7
 - change len_gt into and expr (e.g msg:len).
7 8
 - sipit: uri == myself doesn't match tls port = 5061
... ...
@@ -100,9 +100,9 @@ struct tcp_connection{
100 100
 	struct receive_info rcv; /* src & dst ip, ports, proto a.s.o*/
101 101
 	struct tcp_req req; /* request data */
102 102
 	volatile int refcnt;
103
-	int type; /* PROTO_TCP or a protocol over it, e.g. TLS */
103
+	enum sip_protos type; /* PROTO_TCP or a protocol over it, e.g. TLS */
104 104
 	int flags; /* connection related flags */
105
-	int state; /* connection state */
105
+	enum tcp_conn_states state; /* connection state */
106 106
 	void* extra_data; /* extra data associated to the connection, 0 for tcp*/
107 107
 	int timeout; /* connection timeout, after this it will be removed*/
108 108
 	unsigned addr_hash; /* hash indexes in the 2 tables */
... ...
@@ -487,11 +487,13 @@ send_it:
487 487
 		response[0]=(long)c;
488 488
 		response[1]=CONN_ERROR;
489 489
 		n=write(unix_tcp_sock, response, sizeof(response));
490
+		/* CONN_ERROR wil auto-dec refcnt => we must not call tcpconn_put !!*/
490 491
 		if (n<0){
491
-			LOG(L_ERR, "BUG: tcp_send: failed to get fd(write):%s (%d)\n",
492
+			LOG(L_ERR, "BUG: tcp_send: error return failed (write):%s (%d)\n",
492 493
 					strerror(errno), errno);
493
-			goto release_c;
494 494
 		}
495
+		close(fd);
496
+		return n; /* error return, no tcpconn_put */
495 497
 	}
496 498
 end:
497 499
 	close(fd);
... ...
@@ -853,6 +855,7 @@ read_again:
853 853
 					case CONN_ERROR:
854 854
 					case CONN_DESTROY:
855 855
 					case CONN_EOF:
856
+						/* WARNING: this will auto-dec. refcnt! */
856 857
 						if (pt[r].idx>=0){
857 858
 							tcp_children[pt[r].idx].busy--;
858 859
 						}else{