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 560
 						"%s\n",
603 561
 						su2a((union sockaddr_union*)servaddr, addrlen),
604 562
 						err, strerror(err));
605
-				goto error;
563
+				errno=err;
564
+				goto error_errno;
606 565
 			}
607 566
 		}
608 567
 	}
568
+error_errno:
569
+	switch(errno){
570
+		case ENETUNREACH:
571
+		case EHOSTUNREACH:
572
+#ifdef USE_DST_BLACKLIST
573
+			if (cfg_get(core, core_cfg, use_dst_blacklist))
574
+				dst_blacklist_su(BLST_ERR_CONNECT, type,
575
+							 (union sockaddr_union*)servaddr, 0);
576
+#endif /* USE_DST_BLACKLIST */
577
+			TCP_EV_CONNECT_UNREACHABLE(errno, 0, 0,
578
+							(union sockaddr_union*)servaddr, type);
579
+			break;
580
+		case ETIMEDOUT:
581
+#ifdef USE_DST_BLACKLIST
582
+			if (cfg_get(core, core_cfg, use_dst_blacklist))
583
+				dst_blacklist_su(BLST_ERR_CONNECT, type,
584
+								 (union sockaddr_union*)servaddr, 0);
585
+#endif /* USE_DST_BLACKLIST */
586
+			TCP_EV_CONNECT_TIMEOUT(errno, 0, 0,
587
+							(union sockaddr_union*)servaddr, type);
588
+			break;
589
+		case ECONNREFUSED:
590
+		case ECONNRESET:
591
+#ifdef USE_DST_BLACKLIST
592
+			if (cfg_get(core, core_cfg, use_dst_blacklist))
593
+				dst_blacklist_su(BLST_ERR_CONNECT, type,
594
+								 (union sockaddr_union*)servaddr, 0);
595
+#endif /* USE_DST_BLACKLIST */
596
+			TCP_EV_CONNECT_RST(errno, 0, 0,
597
+							(union sockaddr_union*)servaddr, type);
598
+			break;
599
+		case EAGAIN: /* not posix, but supported on linux and bsd */
600
+			TCP_EV_CONNECT_NO_MORE_PORTS(errno, 0, 0,
601
+							(union sockaddr_union*)servaddr, type);
602
+			break;
603
+		default:
604
+			TCP_EV_CONNECT_ERR(errno, 0, 0,
605
+								(union sockaddr_union*)servaddr, type);
606
+	}
607
+	LOG(L_ERR, "ERROR: tcp_blocking_connect %s: (%d) %s\n",
608
+			su2a((union sockaddr_union*)servaddr, addrlen),
609
+			errno, strerror(errno));
610
+	goto error;
609 611
 error_timeout:
610 612
 	/* timeout */
611 613
 #ifdef USE_DST_BLACKLIST
... ...
@@ -614,11 +616,11 @@ error_timeout:
614 616
 							(union sockaddr_union*)servaddr, 0);
615 617
 #endif /* USE_DST_BLACKLIST */
616 618
 	TCP_EV_CONNECT_TIMEOUT(0, 0, 0, (union sockaddr_union*)servaddr, type);
617
-	TCP_STATS_CONNECT_FAILED();
618 619
 	LOG(L_ERR, "ERROR: tcp_blocking_connect %s: timeout %d s elapsed "
619 620
 				"from %d s\n", su2a((union sockaddr_union*)servaddr, addrlen),
620 621
 				elapsed, cfg_get(tcp, tcp_cfg, connect_timeout_s));
621 622
 error:
623
+	TCP_STATS_CONNECT_FAILED();
622 624
 	return -1;
623 625
 end:
624 626
 	return 0;
... ...
@@ -963,6 +965,8 @@ again:
963 965
 		else if (errno!=EAGAIN && errno!=EWOULDBLOCK){
964 966
 			LOG(L_ERR, "tcp_blocking_write: failed to send: (%d) %s\n",
965 967
 					errno, strerror(errno));
968
+			TCP_EV_SEND_TIMEOUT(errno, &c->rcv);
969
+			TCP_STATS_SEND_TIMEOUT();
966 970
 			goto error;
967 971
 		}
968 972
 	}else if (n<len){