Browse Source

core: new cfg global parameter tcp_clone_rcvbuf

- control cloning of tcp receive buffer, default is 0 (no cloning), set
  to 1 for cloning
Daniel-Constantin Mierla 13 years ago
parent
commit
691a343907
4 changed files with 36 additions and 1 deletions
  1. 3 0
      cfg.lex
  2. 9 0
      cfg.y
  3. 4 0
      tcp_options.h
  4. 20 1
      tcp_read.c

+ 3 - 0
cfg.lex

@@ -434,6 +434,7 @@ TCP_OPT_KEEPINTVL	"tcp_keepintvl"
 TCP_OPT_KEEPCNT		"tcp_keepcnt"
 TCP_OPT_KEEPCNT		"tcp_keepcnt"
 TCP_OPT_CRLF_PING	"tcp_crlf_ping"
 TCP_OPT_CRLF_PING	"tcp_crlf_ping"
 TCP_OPT_ACCEPT_NO_CL	"tcp_accept_no_cl"
 TCP_OPT_ACCEPT_NO_CL	"tcp_accept_no_cl"
+TCP_CLONE_RCVBUF	"tcp_clone_rcvbuf"
 DISABLE_TLS		"disable_tls"|"tls_disable"
 DISABLE_TLS		"disable_tls"|"tls_disable"
 ENABLE_TLS		"enable_tls"|"tls_enable"
 ENABLE_TLS		"enable_tls"|"tls_enable"
 TLSLOG			"tlslog"|"tls_log"
 TLSLOG			"tlslog"|"tls_log"
@@ -846,6 +847,8 @@ IMPORTFILE      "import_file"
 									return TCP_OPT_CRLF_PING; }
 									return TCP_OPT_CRLF_PING; }
 <INITIAL>{TCP_OPT_ACCEPT_NO_CL}	{ count(); yylval.strval=yytext;
 <INITIAL>{TCP_OPT_ACCEPT_NO_CL}	{ count(); yylval.strval=yytext;
 									return TCP_OPT_ACCEPT_NO_CL; }
 									return TCP_OPT_ACCEPT_NO_CL; }
+<INITIAL>{TCP_CLONE_RCVBUF}		{ count(); yylval.strval=yytext;
+									return TCP_CLONE_RCVBUF; }
 <INITIAL>{DISABLE_TLS}	{ count(); yylval.strval=yytext; return DISABLE_TLS; }
 <INITIAL>{DISABLE_TLS}	{ count(); yylval.strval=yytext; return DISABLE_TLS; }
 <INITIAL>{ENABLE_TLS}	{ count(); yylval.strval=yytext; return ENABLE_TLS; }
 <INITIAL>{ENABLE_TLS}	{ count(); yylval.strval=yytext; return ENABLE_TLS; }
 <INITIAL>{TLSLOG}		{ count(); yylval.strval=yytext; return TLS_PORT_NO; }
 <INITIAL>{TLSLOG}		{ count(); yylval.strval=yytext; return TLS_PORT_NO; }

+ 9 - 0
cfg.y

@@ -492,6 +492,7 @@ extern char *finame;
 %token TCP_OPT_KEEPCNT
 %token TCP_OPT_KEEPCNT
 %token TCP_OPT_CRLF_PING
 %token TCP_OPT_CRLF_PING
 %token TCP_OPT_ACCEPT_NO_CL
 %token TCP_OPT_ACCEPT_NO_CL
+%token TCP_CLONE_RCVBUF
 %token DISABLE_TLS
 %token DISABLE_TLS
 %token ENABLE_TLS
 %token ENABLE_TLS
 %token TLSLOG
 %token TLSLOG
@@ -1232,6 +1233,14 @@ assign_stm:
 		#endif
 		#endif
 	}
 	}
 	| TCP_OPT_ACCEPT_NO_CL EQUAL error { yyerror("boolean value expected"); }
 	| TCP_OPT_ACCEPT_NO_CL EQUAL error { yyerror("boolean value expected"); }
+	| TCP_CLONE_RCVBUF EQUAL NUMBER {
+		#ifdef USE_TCP
+			tcp_set_clone_rcvbuf($3);
+		#else
+			warn("tcp support not compiled in");
+		#endif
+	}
+	| TCP_CLONE_RCVBUF EQUAL error { yyerror("number expected"); }
 	| DISABLE_TLS EQUAL NUMBER {
 	| DISABLE_TLS EQUAL NUMBER {
 		#ifdef USE_TLS
 		#ifdef USE_TLS
 			tls_disable=$3;
 			tls_disable=$3;

+ 4 - 0
tcp_options.h

@@ -157,4 +157,8 @@ void tcp_options_check();
 int tcp_register_cfg();
 int tcp_register_cfg();
 void tcp_options_get(struct cfg_group_tcp* t);
 void tcp_options_get(struct cfg_group_tcp* t);
 
 
+#ifdef USE_TCP
+int tcp_set_clone_rcvbuf(int v);
+#endif /* USE_TCP */
+
 #endif /* tcp_options_h */
 #endif /* tcp_options_h */

+ 20 - 1
tcp_read.c

@@ -121,6 +121,22 @@ static int tcpmain_sock=-1;
 static struct local_timer tcp_reader_ltimer;
 static struct local_timer tcp_reader_ltimer;
 static ticks_t tcp_reader_prev_ticks;
 static ticks_t tcp_reader_prev_ticks;
 
 
+/**
+ * control cloning of TCP receive buffer
+ * - needed for operations working directly inside the buffer
+ *   (like msg_apply_changes())
+ */
+#define TCP_CLONE_RCVBUF
+static int tcp_clone_rcvbuf = 0;
+
+int tcp_set_clone_rcvbuf(int v)
+{
+	int r;
+	r = tcp_clone_rcvbuf;
+	tcp_clone_rcvbuf = v;
+	return r;
+}
+
 #ifdef READ_HTTP11
 #ifdef READ_HTTP11
 static inline char *strfindcasestrz(str *haystack, char *needlez)
 static inline char *strfindcasestrz(str *haystack, char *needlez)
 {
 {
@@ -856,7 +872,6 @@ skip:
  * the content of the stream. Safer, make a clone of buf content in a local
  * the content of the stream. Safer, make a clone of buf content in a local
  * buffer and give that to receive_msg() to link to msg->buf
  * buffer and give that to receive_msg() to link to msg->buf
  */
  */
-#define TCP_CLONE_RCVBUF
 int receive_tcp_msg(char* tcpbuf, unsigned int len, struct receive_info* rcv_info)
 int receive_tcp_msg(char* tcpbuf, unsigned int len, struct receive_info* rcv_info)
 {
 {
 #ifdef TCP_CLONE_RCVBUF
 #ifdef TCP_CLONE_RCVBUF
@@ -868,6 +883,10 @@ int receive_tcp_msg(char* tcpbuf, unsigned int len, struct receive_info* rcv_inf
 #endif
 #endif
 	int blen;
 	int blen;
 
 
+	/* cloning is disabled via parameter */
+	if(likely(tcp_clone_rcvbuf==0))
+		return receive_msg(tcpbuf, len, rcv_info);
+
 	/* min buffer size is BUF_SIZE */
 	/* min buffer size is BUF_SIZE */
 	blen = len;
 	blen = len;
 	if(blen < BUF_SIZE)
 	if(blen < BUF_SIZE)