Kaynağa Gözat

tested and ifdef-ed the Stats hack; to be done:L put it in shmem

Jiri Kuthan 24 yıl önce
ebeveyn
işleme
0a974a1d3a
6 değiştirilmiş dosya ile 39 ekleme ve 3 silme
  1. 3 1
      Makefile
  2. 12 1
      forward.c
  3. 9 0
      main.c
  4. 3 1
      profile/profile.cfg
  5. 8 0
      receive.c
  6. 4 0
      stats.h

+ 3 - 1
Makefile

@@ -21,7 +21,9 @@ NAME=ser
 # MACROEATER replaces frequently called parser helper functions
 # with macros
 # recommanded: on (speed-up)
-DEFS=-DNOCR -DMACROEATER
+# STATS allows to print out number of packets processed on CTRL-C; implementation
+#  still nasty and reports per-process
+DEFS=-DNOCR -DMACROEATER -DSTATS
 
 # platform dependent settings
 

+ 12 - 1
forward.c

@@ -28,7 +28,9 @@
 #define MAX_VIA_LINE_SIZE      240
 #define MAX_RECEIVED_SIZE  57
 
+#ifdef STATS
 #include "stats.h"
+#endif
 
 /* checks if ip is in host(name) and ?host(ip)=name? 
  * ip must be in network byte order!
@@ -333,14 +335,19 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p)
 
 	p->tx++;
 	p->tx_bytes+=new_len;
+#ifdef STATS
 	stats.total_tx++;
+#endif
 
 	if (udp_send(new_buf, new_len, (struct sockaddr*) to,
 				sizeof(struct sockaddr_in))==-1){
 			p->errors++;
 			p->ok=0;
 			goto error;
-	} else stats.ok_tx_rq++;
+	} 
+#ifdef STATS
+	else stats.ok_tx_rq++;
+#endif
 
 	free(new_buf);
 	free(to);
@@ -445,11 +452,15 @@ int forward_reply(struct sip_msg* msg)
 
 
 	
+#ifdef STATS
 	stats.total_tx++;
+#endif
 	if (udp_send(new_buf,new_len, (struct sockaddr*) to, 
 					sizeof(struct sockaddr_in))==-1)
 		goto error;
+#ifdef STATS
 	else stats.ok_tx_rs++;
+#endif
 	
 	free(new_buf);
 	free(to);

+ 9 - 0
main.c

@@ -21,7 +21,10 @@
 #include "globals.h"
 
 #include <signal.h>
+
+#ifdef STATS
 #include "stats.h"
+#endif
 
 
 
@@ -113,8 +116,10 @@ int process_no = 0;
 /* cfg parsing */
 int cfg_errors=0;
 
+#ifdef STATS
 /* jku: RX/TX statistics -- remember, they are process specific */
 struct stats_s stats;
+#endif
 
 
 #define MAX_FD 32 /* maximum number of inherited open file descriptors,
@@ -226,9 +231,11 @@ int main_loop()
 static void sig_usr(int signo)
 {
 	DPrint("INT received, program terminates\n");
+#ifdef STATS
 	DPrint("ok_rx_rq\t%d\nok_rx_rs\t%d\nok_tx_rq\t%d\nok_tx_rs\t%d\ntotal_rx\t%d\ntotal_tx\t%d\n\n",
 		stats.ok_rx_rq, stats.ok_rx_rs, stats.ok_tx_rq, stats.ok_tx_rs, stats.total_rx, stats.total_tx );
 	DPrint("Thank you for flying ser\n");
+#endif
 	exit(0);
 }
 	
@@ -378,8 +385,10 @@ int main(int argc, char** argv)
 		addresses_no++;
 	}
 
+#ifdef STATS
 	/* jku: initialize statistic */
  	memset(&stats,0,sizeof(struct stats_s));
+#endif
 	
 	/* get ips */
 	printf("Listening on ");

+ 3 - 1
profile/profile.cfg

@@ -1,8 +1,10 @@
 # first sort out iptel.org requests from those destined somewhere else
 ####################################################################################
 
+port=5080
+
 route[0] {
 
-forward( uri:host, uri:port );
+forward( 127.0.0.1, 9 );
 
 }

+ 8 - 0
receive.c

@@ -17,13 +17,17 @@
 #include <dmalloc.h>
 #endif
 
+#ifdef STATS
 #include "stats.h"
+#endif
 
 int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
 {
 	struct sip_msg msg;
 
+#ifdef STATS
 	stats.total_rx++;	
+#endif
 
 	memset(&msg,0, sizeof(struct sip_msg)); /* init everything to 0 */
 	/* fill in msg */
@@ -57,8 +61,10 @@ int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
 					"error while trying script\n");
 			goto error;
 		}
+#ifdef STATS
 		/* jku -- update statistics  */
 		else stats.ok_rx_rq++;	
+#endif
 	}else if (msg.first_line.type==SIP_REPLY){
 		/* sanity checks */
 		if (msg.via1.error!=VIA_PARSE_OK){
@@ -71,8 +77,10 @@ int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
 		}
 		/* check if via1 == us */
 
+#ifdef STATS
 		/* jku -- update statistics  */
 		stats.ok_rx_rs++;	
+#endif
 		
 		/* send the msg */
 		if (forward_reply(&msg)==0){

+ 4 - 0
stats.h

@@ -1,6 +1,8 @@
 #ifndef stats_h
 #define stats_h
 
+#ifdef STATS
+
 struct stats_s {
 
 	/* total/valid, received/sent, request/response */
@@ -16,3 +18,5 @@ struct stats_s {
 extern struct stats_s stats;
 
 #endif
+
+#endif