Selaa lähdekoodia

- tcp fix ported from stable
- minor beautifications

Andrei Pelinescu-Onciul 22 vuotta sitten
vanhempi
commit
1c93f76796
3 muutettua tiedostoa jossa 8 lisäystä ja 4 poistoa
  1. 1 0
      TODO
  2. 2 2
      tcp_conn.h
  3. 5 2
      tcp_main.c

+ 1 - 0
TODO

@@ -2,6 +2,7 @@ $Id$
 
 ( - todo, x - done)
 
+- add BUG checks for  fd > 0 && fd <= maxfd to all selects?
 x tcp_main_loop: BUG cases should "conitnue;"
 - change len_gt into and expr (e.g msg:len).
 - sipit: uri == myself doesn't match tls port = 5061

+ 2 - 2
tcp_conn.h

@@ -100,9 +100,9 @@ struct tcp_connection{
 	struct receive_info rcv; /* src & dst ip, ports, proto a.s.o*/
 	struct tcp_req req; /* request data */
 	volatile int refcnt;
-	int type; /* PROTO_TCP or a protocol over it, e.g. TLS */
+	enum sip_protos type; /* PROTO_TCP or a protocol over it, e.g. TLS */
 	int flags; /* connection related flags */
-	int state; /* connection state */
+	enum tcp_conn_states state; /* connection state */
 	void* extra_data; /* extra data associated to the connection, 0 for tcp*/
 	int timeout; /* connection timeout, after this it will be removed*/
 	unsigned addr_hash; /* hash indexes in the 2 tables */

+ 5 - 2
tcp_main.c

@@ -487,11 +487,13 @@ send_it:
 		response[0]=(long)c;
 		response[1]=CONN_ERROR;
 		n=write(unix_tcp_sock, response, sizeof(response));
+		/* CONN_ERROR wil auto-dec refcnt => we must not call tcpconn_put !!*/
 		if (n<0){
-			LOG(L_ERR, "BUG: tcp_send: failed to get fd(write):%s (%d)\n",
+			LOG(L_ERR, "BUG: tcp_send: error return failed (write):%s (%d)\n",
 					strerror(errno), errno);
-			goto release_c;
 		}
+		close(fd);
+		return n; /* error return, no tcpconn_put */
 	}
 end:
 	close(fd);
@@ -853,6 +855,7 @@ read_again:
 					case CONN_ERROR:
 					case CONN_DESTROY:
 					case CONN_EOF:
+						/* WARNING: this will auto-dec. refcnt! */
 						if (pt[r].idx>=0){
 							tcp_children[pt[r].idx].busy--;
 						}else{