Browse code

tcp: minor stats fixes

Author: Andrei Pelinescu-Onciul <andrei@iptel.org>

Andrei Pelinescu-Onciul authored on 10/04/2009 10:23:14
Showing 1 changed files
... ...
@@ -506,49 +506,7 @@ again:
506 506
 			else goto error_timeout;
507 507
 		}
508 508
 		if (errno!=EINPROGRESS && errno!=EALREADY){
509
-			switch(errno){
510
-				case ENETUNREACH:
511
-				case EHOSTUNREACH:
512
-#ifdef USE_DST_BLACKLIST
513
-					if (cfg_get(core, core_cfg, use_dst_blacklist))
514
-						dst_blacklist_su(BLST_ERR_CONNECT, type,
515
-									 (union sockaddr_union*)servaddr, 0);
516
-#endif /* USE_DST_BLACKLIST */
517
-					TCP_EV_CONNECT_UNREACHABLE(errno, 0, 0,
518
-									(union sockaddr_union*)servaddr, type);
519
-					break;
520
-				case ETIMEDOUT:
521
-#ifdef USE_DST_BLACKLIST
522
-					if (cfg_get(core, core_cfg, use_dst_blacklist))
523
-						dst_blacklist_su(BLST_ERR_CONNECT, type,
524
-										 (union sockaddr_union*)servaddr, 0);
525
-#endif /* USE_DST_BLACKLIST */
526
-					TCP_EV_CONNECT_TIMEOUT(errno, 0, 0,
527
-									(union sockaddr_union*)servaddr, type);
528
-					break;
529
-				case ECONNREFUSED:
530
-				case ECONNRESET:
531
-#ifdef USE_DST_BLACKLIST
532
-					if (cfg_get(core, core_cfg, use_dst_blacklist))
533
-						dst_blacklist_su(BLST_ERR_CONNECT, type,
534
-										 (union sockaddr_union*)servaddr, 0);
535
-#endif /* USE_DST_BLACKLIST */
536
-					TCP_EV_CONNECT_RST(errno, 0, 0,
537
-									(union sockaddr_union*)servaddr, type);
538
-					break;
539
-				case EAGAIN: /* not posix, but supported on linux and bsd */
540
-					TCP_EV_CONNECT_NO_MORE_PORTS(errno, 0, 0,
541
-									(union sockaddr_union*)servaddr, type);
542
-					break;
543
-				default:
544
-					TCP_EV_CONNECT_ERR(errno, 0, 0,
545
-										(union sockaddr_union*)servaddr, type);
546
-			}
547
-			TCP_STATS_CONNECT_FAILED();
548
-			LOG(L_ERR, "ERROR: tcp_blocking_connect %s: (%d) %s\n",
549
-					su2a((union sockaddr_union*)servaddr, addrlen),
550
-					errno, strerror(errno));
551
-			goto error;
509
+			goto error_errno;
552 510
 		}
553 511
 	}else goto end;
554 512
 	
... ...
@@ -602,10 +560,54 @@ again:
602 602
 						"%s\n",
603 603
 						su2a((union sockaddr_union*)servaddr, addrlen),
604 604
 						err, strerror(err));
605
-				goto error;
605
+				errno=err;
606
+				goto error_errno;
606 607
 			}
607 608
 		}
608 609
 	}
610
+error_errno:
611
+	switch(errno){
612
+		case ENETUNREACH:
613
+		case EHOSTUNREACH:
614
+#ifdef USE_DST_BLACKLIST
615
+			if (cfg_get(core, core_cfg, use_dst_blacklist))
616
+				dst_blacklist_su(BLST_ERR_CONNECT, type,
617
+							 (union sockaddr_union*)servaddr, 0);
618
+#endif /* USE_DST_BLACKLIST */
619
+			TCP_EV_CONNECT_UNREACHABLE(errno, 0, 0,
620
+							(union sockaddr_union*)servaddr, type);
621
+			break;
622
+		case ETIMEDOUT:
623
+#ifdef USE_DST_BLACKLIST
624
+			if (cfg_get(core, core_cfg, use_dst_blacklist))
625
+				dst_blacklist_su(BLST_ERR_CONNECT, type,
626
+								 (union sockaddr_union*)servaddr, 0);
627
+#endif /* USE_DST_BLACKLIST */
628
+			TCP_EV_CONNECT_TIMEOUT(errno, 0, 0,
629
+							(union sockaddr_union*)servaddr, type);
630
+			break;
631
+		case ECONNREFUSED:
632
+		case ECONNRESET:
633
+#ifdef USE_DST_BLACKLIST
634
+			if (cfg_get(core, core_cfg, use_dst_blacklist))
635
+				dst_blacklist_su(BLST_ERR_CONNECT, type,
636
+								 (union sockaddr_union*)servaddr, 0);
637
+#endif /* USE_DST_BLACKLIST */
638
+			TCP_EV_CONNECT_RST(errno, 0, 0,
639
+							(union sockaddr_union*)servaddr, type);
640
+			break;
641
+		case EAGAIN: /* not posix, but supported on linux and bsd */
642
+			TCP_EV_CONNECT_NO_MORE_PORTS(errno, 0, 0,
643
+							(union sockaddr_union*)servaddr, type);
644
+			break;
645
+		default:
646
+			TCP_EV_CONNECT_ERR(errno, 0, 0,
647
+								(union sockaddr_union*)servaddr, type);
648
+	}
649
+	LOG(L_ERR, "ERROR: tcp_blocking_connect %s: (%d) %s\n",
650
+			su2a((union sockaddr_union*)servaddr, addrlen),
651
+			errno, strerror(errno));
652
+	goto error;
609 653
 error_timeout:
610 654
 	/* timeout */
611 655
 #ifdef USE_DST_BLACKLIST
... ...
@@ -614,11 +616,11 @@ error_timeout:
614 614
 							(union sockaddr_union*)servaddr, 0);
615 615
 #endif /* USE_DST_BLACKLIST */
616 616
 	TCP_EV_CONNECT_TIMEOUT(0, 0, 0, (union sockaddr_union*)servaddr, type);
617
-	TCP_STATS_CONNECT_FAILED();
618 617
 	LOG(L_ERR, "ERROR: tcp_blocking_connect %s: timeout %d s elapsed "
619 618
 				"from %d s\n", su2a((union sockaddr_union*)servaddr, addrlen),
620 619
 				elapsed, cfg_get(tcp, tcp_cfg, connect_timeout_s));
621 620
 error:
621
+	TCP_STATS_CONNECT_FAILED();
622 622
 	return -1;
623 623
 end:
624 624
 	return 0;
... ...
@@ -963,6 +965,8 @@ again:
963 963
 		else if (errno!=EAGAIN && errno!=EWOULDBLOCK){
964 964
 			LOG(L_ERR, "tcp_blocking_write: failed to send: (%d) %s\n",
965 965
 					errno, strerror(errno));
966
+			TCP_EV_SEND_TIMEOUT(errno, &c->rcv);
967
+			TCP_STATS_SEND_TIMEOUT();
966 968
 			goto error;
967 969
 		}
968 970
 	}else if (n<len){