浏览代码

- 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 20 年之前
父节点
当前提交
06c04bc2b1
共有 5 个文件被更改,包括 23 次插入4 次删除
  1. 1 1
      Makefile.defs
  2. 6 0
      socket_info.c
  3. 1 0
      tcp_conn.h
  4. 11 2
      tcp_main.c
  5. 4 1
      tcp_read.c

+ 1 - 1
Makefile.defs

@@ -60,7 +60,7 @@ MAIN_NAME=ser
 VERSION = 0
 PATCHLEVEL = 10
 SUBLEVEL =   99
-EXTRAVERSION = -dev20-tcp
+EXTRAVERSION = -dev21-tcp
 
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")

+ 6 - 0
socket_info.c

@@ -369,6 +369,12 @@ int add_listen_iface(char* name, unsigned short port, unsigned short proto,
 #endif
 				port_no;
 		}
+#ifdef USE_TLS
+		else if ((c_proto==PROTO_TLS) && (proto==0)){
+			/* -l  ip:port => on udp:ip:port; tcp:ip:port and tls:ip:port+1? */
+			port++;
+		}
+#endif
 		if (new_sock2list(name, port, c_proto, flags, list)<0){
 			LOG(L_ERR, "ERROR: add_listen_iface: new_sock2list failed\n");
 			goto error;

+ 1 - 0
tcp_conn.h

@@ -58,6 +58,7 @@
 
 /* tcp connection flags */
 #define F_CONN_NON_BLOCKING 1
+#define F_CONN_REMOVED      2 /* no longer  in "main" listen fd list */
 
 
 enum tcp_req_errors {	TCP_REQ_INIT, TCP_REQ_OK, TCP_READ_ERROR,

+ 11 - 2
tcp_main.c

@@ -414,6 +414,7 @@ struct tcp_connection* tcpconn_new(int sock, union sockaddr_union* su,
 	c->rcv.proto_reserved2=0;
 	c->state=state;
 	c->extra_data=0;
+	c->flags|=F_CONN_REMOVED;
 #ifdef USE_TLS
 	if (type==PROTO_TLS){
 		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)
 	/* pass it to child, so remove it from the io watch list */
 	DBG("handle_tcpconn_ev: data available on %p %d\n", tcpconn, tcpconn->s);
 	if (io_watch_del(&io_h, tcpconn->s, fd_i, 0)==-1) goto error;
+	tcpconn->flags|=F_CONN_REMOVED;
 	tcpconn_ref(tcpconn); /* refcnt ++ */
 	if (send2child(tcpconn)<0){
 		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)
 			tcpconn_put(tcpconn);
 			/* must be after the de-ref*/
 			io_watch_add(&io_h, tcpconn->s, F_TCPCONN, tcpconn);
+			tcpconn->flags&=~F_CONN_REMOVED;
 			DBG("handle_tcp_child: CONN_RELEASE  %p refcnt= %d\n", 
 											tcpconn, tcpconn->refcnt);
 			break;
@@ -1311,8 +1314,10 @@ inline static int handle_ser_child(struct process_table* p, int fd_i)
 	}
 	switch(cmd){
 		case CONN_ERROR:
-			if (tcpconn->s!=-1)
+			if (!(tcpconn->flags & F_CONN_REMOVED) && (tcpconn->s!=-1)){
 				io_watch_del(&io_h, tcpconn->s, -1, IO_FD_CLOSING);
+				tcpconn->flags|=F_CONN_REMOVED;
+			}
 			tcpconn_destroy(tcpconn); /* will close also the fd */
 			break;
 		case CONN_GET_FD:
@@ -1339,6 +1344,7 @@ inline static int handle_ser_child(struct process_table* p, int fd_i)
 			/* update the timeout*/
 			tcpconn->timeout=get_ticks()+tcp_con_lifetime;
 			io_watch_add(&io_h, tcpconn->s, F_TCPCONN, tcpconn);
+			tcpconn->flags&=~F_CONN_REMOVED;
 			break;
 		default:
 			LOG(L_CRIT, "BUG: handle_ser_child: unknown cmd %d\n", cmd);
@@ -1423,7 +1429,10 @@ static inline void tcpconn_timeout(int force)
 #endif
 				_tcpconn_rm(c);
 				if ((fd>0)&&(c->refcnt==0)) {
-					io_watch_del(&io_h, fd, -1, IO_FD_CLOSING);
+					if (!(c->flags & F_CONN_REMOVED)){
+						io_watch_del(&io_h, fd, -1, IO_FD_CLOSING);
+						c->flags|=F_CONN_REMOVED;
+					}
 					close(fd);
 				}
 				tcp_connections_no--;

+ 4 - 1
tcp_read.c

@@ -400,6 +400,7 @@ skip:
 int tcp_read_req(struct tcp_connection* con, int* bytes_read)
 {
 	int bytes;
+	int total_bytes;
 	int resp;
 	long size;
 	struct tcp_req* req;
@@ -407,6 +408,7 @@ int tcp_read_req(struct tcp_connection* con, int* bytes_read)
 	char c;
 		
 		bytes=-1;
+		total_bytes=0;
 		resp=CONN_RELEASE;
 		s=con->fd;
 		req=&con->req;
@@ -437,6 +439,7 @@ again:
 				resp=CONN_ERROR;
 				goto end_req;
 			}
+			total_bytes+=bytes;
 			/* eof check:
 			 * is EOF if eof on fd and req.  not complete yet,
 			 * if req. is complete we might have a second unparsed
@@ -533,7 +536,7 @@ again:
 		
 		
 	end_req:
-		if (bytes_read) *bytes_read=bytes;
+		if (bytes_read) *bytes_read=total_bytes;
 		return resp;
 }