فهرست منبع

Added NOCR and MACROEATER compile-time speed-up options.
NOCR replaces a 'for' cycle with 'memchr' and
MACROEATER replaces 'eater' functions with macros.
The -V command-line options shows now which of these options
are enabled. A signal handler is added which calls
exit(0) on INT signal ... good for profiling.

-Jiri

Jiri Kuthan 24 سال پیش
والد
کامیت
726efa25b0
4فایلهای تغییر یافته به همراه102 افزوده شده و 7 حذف شده
  1. 11 3
      Makefile
  2. 35 1
      main.c
  3. 20 1
      parser_f.c
  4. 36 2
      parser_f.h

+ 11 - 3
Makefile

@@ -14,6 +14,14 @@ depends= $(sources:.c=.d)
 
 NAME=sip_router
 
+# compile-time options
+# NOCR disables seeking for CRs -- breaks standard but is fast
+# recommended: on (speed-up, no implementation really sends CR)
+# MACROEATER replaces frequently called parser helper functions
+# with macros
+# recommanded: on (speed-up)
+DEFS=-DNOCR -DMACROEATER
+
 # platform dependent settings
 
 ARCH = $(shell uname -s)
@@ -21,7 +29,7 @@ ARCH = $(shell uname -s)
 ifeq ($(ARCH), Linux)
 
 CC=gcc
-CFLAGS=-O2 -Wcast-align #-Wmissing-prototypes  -Wall
+CFLAGS=-O2 -pg -Wcast-align #-Wmissing-prototypes  -Wall
 LEX=flex
 YACC=bison
 YACC_FLAGS=-d -b cfg
@@ -54,7 +62,7 @@ LIBS=-lfl
 endif
 
 
-MKDEP=gcc -M
+MKDEP=gcc -M $(DEFS)
 
 ALLDEP=Makefile
 
@@ -62,7 +70,7 @@ ALLDEP=Makefile
 
 
 %.o:%.c $(ALLDEP)
-	$(CC) $(CFLAGS) -c $< -o $@
+	$(CC) $(CFLAGS) $(DEFS) -c $< -o $@
 
 %.d: %.c
 	$(MKDEP) $< >$@

+ 35 - 1
main.c

@@ -20,6 +20,9 @@
 #include "udp_server.h"
 #include "globals.h"
 
+#include <signal.h>
+
+
 
 #ifdef DEBUG_DMALLOC
 #include <dmalloc.h>
@@ -28,6 +31,20 @@
 
 static char id[]="@(#) $Id$";
 static char version[]="sip_router 0.6";
+static char flags[]="NOCR:"
+#ifdef NOCR
+"On"
+#else
+"Off"
+#endif
+", MACROEATER:"
+#ifdef MACROEATER
+"On"
+#else
+"Off"
+#endif
+;
+
 static char help_msg[]= "\
 Usage: sip_router -l address [-l address] [options]\n\
 Options:\n\
@@ -196,7 +213,17 @@ int main_loop()
 	return -1;
 
 }
-	
+
+/* added by jku; allows for regular exit on a specific signal;
+   good for profiling which only works if exited regularly and
+   not by default signal handlers
+*/	
+
+static void sig_usr(int signo)
+{
+	DPrint("INT received, program terminates\n");
+	exit(0);
+}
 	
 	
 	
@@ -209,6 +236,12 @@ int main(int argc, char** argv)
 	char *tmp;
 	struct utsname myname;
 
+	/* added by jku: add exit handler */
+        if (signal(SIGINT, sig_usr) == SIG_ERR ) {
+ 		DPrint("ERROR: no signal handler can be installed\n");
+                goto error;
+        }
+
 	/* process command line (get port no, cfg. file path etc) */
 	opterr=0;
 	while((c=getopt(argc,argv,"f:p:l:n:rRvdDEVh"))!=-1){
@@ -266,6 +299,7 @@ int main(int argc, char** argv)
 					break;
 			case 'V':
 					printf("version: %s\n", version);
+					printf("flags: %s\n", flags );
 					printf("%s\n",id);
 					exit(0);
 					break;

+ 20 - 1
parser_f.c

@@ -13,18 +13,35 @@ char* eat_line(char* buffer, unsigned int len)
 	char* nl;
 	char c;
 
+	/* jku .. replace for search with a library function; not conformant
+ 		  as I do not care about CR
+	*/
+#ifdef NOCR
+	nl=(char *)memchr( buffer, '\n', len );
+	if ( nl ) { 
+		c=* nl;
+		if ( nl + 1 < buffer+len)  nl++;
+		if (( nl+1<buffer+len) && * nl=='\r')  nl++;
+	} else  nl=buffer+len;
+#else
 	for(nl=buffer;(nl<buffer+len)&& (*nl!='\r')&&(*nl!='\n') ;nl++);
 	c=*nl;
 	if (nl+1<buffer+len)  nl++;
 	if ((nl+1<buffer+len) &&
 			((c=='\r' && *nl=='\n')|| (c=='\n' && *nl=='\r'))) 
 		nl++;
+#endif
+	
+	/* end of jku */
 	return nl;
 }
 
 
 
 /* returns pointer to first non  white char or after the end  of the buffer */
+
+#ifndef MACROEATER
+
 char* eat_space(char* buffer, unsigned int len)
 {
 	char* p;
@@ -34,7 +51,6 @@ char* eat_space(char* buffer, unsigned int len)
 }
 
 
-
 /* returns pointer after the token (first whitespace char or CR/LF) */
 char* eat_token(char* buffer, unsigned int len)
 {
@@ -59,6 +75,9 @@ char* eat_token2(char* buffer, unsigned int len, char delim)
 	return p;
 }
 
+/* EoMACROEATER */
+#endif
+
 
 
 /* returns true if line started  at buffer contains only white space */

+ 36 - 2
parser_f.h

@@ -6,10 +6,44 @@
 #define parser_f_h
 
 char* eat_line(char* buffer, unsigned int len);
+int is_empty(char* buffer, unsigned int len);
+
+#ifdef MACROEATER
+
+/* turn the most frequently called functions into macros */
+
+
+#define eat_space(buffer,len)                                          \
+  ( {   char *p;                                                     	\
+        for(p=(buffer);(p<(buffer)+(len))&& (*p==' ' || *p=='\t') ;p++);\
+        p;                                                              \
+  } )
+
+#define eat_token(buffer,len)						\
+  ( { char *p;								\
+      for (p=(buffer);(p<(buffer)+(len))&&				\
+                        (*p!=' ')&&(*p!='\t')&&(*p!='\n')&&(*p!='\r');	\
+                p++);							\
+      p;								\
+  } )
+
+#define eat_token2(buffer,len,delim)					\
+  ( { char *p;								\
+      for (p=(buffer);(p<(buffer)+(len))&&				\
+                        (*p!=(delim))&&(*p!='\n')&&(*p!='\r');		\
+                p++);							\
+      p;								\
+  } )
+
+
+#else
+
+
 char* eat_space(char* buffer, unsigned int len);
 char* eat_token(char* buffer, unsigned int len);
 char* eat_token2(char* buffer, unsigned int len, char delim);
-int is_empty(char* buffer, unsigned int len);
+
+/* EoMACROEATER */
+#endif
 
 #endif
-