Browse code

- tls shutdown on close support - some tcp bug fixes (error handling in case of bad fds, or impossible events [like conn==0])

Andrei Pelinescu-Onciul authored on 09/07/2003 16:37:02
Showing 3 changed files
... ...
@@ -40,7 +40,7 @@ export makefile_defs
40 40
 VERSION = 0
41 41
 PATCHLEVEL = 8
42 42
 SUBLEVEL =   12
43
-EXTRAVERSION = dev-t08
43
+EXTRAVERSION = dev-t09
44 44
 
45 45
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
46 46
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -41,6 +41,7 @@
41 41
  *  2003-04-14  set sockopts to TOS low delay (andrei)
42 42
  *  2003-06-30  moved tcp new connect checking & handling to
43 43
  *               handle_new_connect (andrei)
44
+ *  2003-07-09  tls_close called before closing the tcp connection (andrei)
44 45
  */
45 46
 
46 47
 
... ...
@@ -520,6 +521,10 @@ void tcpconn_timeout(fd_set* set)
520 521
 				DBG("tcpconn_timeout: timeout for hash=%d - %p (%d > %d)\n",
521 522
 						h, c, ticks, c->timeout);
522 523
 				fd=c->s;
524
+#ifdef USE_TLS
525
+				if (c->type==PROTO_TLS)
526
+					tls_close(c, fd);
527
+#endif
523 528
 				_tcpconn_rm(c);
524 529
 				if (fd>0) {
525 530
 					FD_CLR(fd, set);
... ...
@@ -861,6 +866,10 @@ read_again:
861 866
 							if (tcpconn->refcnt==0){ 
862 867
 								DBG("tcp_main_loop: destroying connection\n");
863 868
 								fd=tcpconn->s;
869
+#ifdef USE_TLS
870
+								if (tcpconn->type==PROTO_TLS)
871
+									tls_close(tcpconn, fd);
872
+#endif
864 873
 								_tcpconn_rm(tcpconn);
865 874
 								close(fd);
866 875
 							}else{
... ...
@@ -600,31 +600,30 @@ void tcp_receive_loop(int unix_sock)
600 600
 				if (n<0){
601 601
 					if (errno == EWOULDBLOCK || errno == EAGAIN ||
602 602
 							errno == EINTR){
603
-						continue;
603
+						goto skip;
604 604
 					}else{
605 605
 						LOG(L_CRIT,"BUG: tcp_receive_loop: read_fd: %s\n",
606 606
 							strerror(errno));
607 607
 						abort(); /* big error*/
608 608
 					}
609 609
 				}
610
+				DBG("received n=%d con=%p, fd=%d\n", n, con, s);
610 611
 				if (n==0){
611 612
 					LOG(L_ERR, "WARNING: tcp_receive_loop: 0 bytes read\n");
612
-					continue;
613
+					goto skip;
614
+				}
615
+				if (con==0){
616
+					LOG(L_CRIT, "BUG: tcp_receive_loop: null pointer\n");
617
+					goto skip;
613 618
 				}
614 619
 				con->fd=s;
615
-				DBG("received n=%d con=%p, fd=%d\n", n, con, s);
616 620
 				if (s==-1) {
617 621
 					LOG(L_ERR, "ERROR: tcp_receive_loop: read_fd:"
618 622
 									"no fd read\n");
619 623
 					resp=CONN_ERROR;
620 624
 					con->state=S_CONN_BAD;
621 625
 					release_tcpconn(con, resp, unix_sock);
622
-				}
623
-				if (con==0){
624
-					LOG(L_ERR, "ERROR: tcp_receive_loop: null pointer\n");
625
-					resp=CONN_ERROR;
626
-					con->state=S_CONN_BAD;
627
-					release_tcpconn(con, resp, unix_sock);
626
+					goto skip;
628 627
 				}
629 628
 #ifdef USE_TLS
630 629
 				if (con->type==PROTO_TLS) tls_tcpconn_update_fd(con, s);
... ...
@@ -634,6 +633,7 @@ void tcp_receive_loop(int unix_sock)
634 633
 				if (maxfd<s) maxfd=s;
635 634
 				tcpconn_listadd(list, con, c_next, c_prev);
636 635
 			}
636
+skip:
637 637
 			ticks=get_ticks();
638 638
 			for (con=list; con ; con=c_next){
639 639
 				c_next=con->c_next; /* safe for removing*/