Browse code

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 authored on 06/01/2012 10:42:10
Showing 4 changed files
... ...
@@ -434,6 +434,7 @@ TCP_OPT_KEEPINTVL	"tcp_keepintvl"
434 434
 TCP_OPT_KEEPCNT		"tcp_keepcnt"
435 435
 TCP_OPT_CRLF_PING	"tcp_crlf_ping"
436 436
 TCP_OPT_ACCEPT_NO_CL	"tcp_accept_no_cl"
437
+TCP_CLONE_RCVBUF	"tcp_clone_rcvbuf"
437 438
 DISABLE_TLS		"disable_tls"|"tls_disable"
438 439
 ENABLE_TLS		"enable_tls"|"tls_enable"
439 440
 TLSLOG			"tlslog"|"tls_log"
... ...
@@ -846,6 +847,8 @@ IMPORTFILE      "import_file"
846 846
 									return TCP_OPT_CRLF_PING; }
847 847
 <INITIAL>{TCP_OPT_ACCEPT_NO_CL}	{ count(); yylval.strval=yytext;
848 848
 									return TCP_OPT_ACCEPT_NO_CL; }
849
+<INITIAL>{TCP_CLONE_RCVBUF}		{ count(); yylval.strval=yytext;
850
+									return TCP_CLONE_RCVBUF; }
849 851
 <INITIAL>{DISABLE_TLS}	{ count(); yylval.strval=yytext; return DISABLE_TLS; }
850 852
 <INITIAL>{ENABLE_TLS}	{ count(); yylval.strval=yytext; return ENABLE_TLS; }
851 853
 <INITIAL>{TLSLOG}		{ count(); yylval.strval=yytext; return TLS_PORT_NO; }
... ...
@@ -492,6 +492,7 @@ extern char *finame;
492 492
 %token TCP_OPT_KEEPCNT
493 493
 %token TCP_OPT_CRLF_PING
494 494
 %token TCP_OPT_ACCEPT_NO_CL
495
+%token TCP_CLONE_RCVBUF
495 496
 %token DISABLE_TLS
496 497
 %token ENABLE_TLS
497 498
 %token TLSLOG
... ...
@@ -1232,6 +1233,14 @@ assign_stm:
1232 1232
 		#endif
1233 1233
 	}
1234 1234
 	| TCP_OPT_ACCEPT_NO_CL EQUAL error { yyerror("boolean value expected"); }
1235
+	| TCP_CLONE_RCVBUF EQUAL NUMBER {
1236
+		#ifdef USE_TCP
1237
+			tcp_set_clone_rcvbuf($3);
1238
+		#else
1239
+			warn("tcp support not compiled in");
1240
+		#endif
1241
+	}
1242
+	| TCP_CLONE_RCVBUF EQUAL error { yyerror("number expected"); }
1235 1243
 	| DISABLE_TLS EQUAL NUMBER {
1236 1244
 		#ifdef USE_TLS
1237 1245
 			tls_disable=$3;
... ...
@@ -157,4 +157,8 @@ void tcp_options_check();
157 157
 int tcp_register_cfg();
158 158
 void tcp_options_get(struct cfg_group_tcp* t);
159 159
 
160
+#ifdef USE_TCP
161
+int tcp_set_clone_rcvbuf(int v);
162
+#endif /* USE_TCP */
163
+
160 164
 #endif /* tcp_options_h */
... ...
@@ -121,6 +121,22 @@ static int tcpmain_sock=-1;
121 121
 static struct local_timer tcp_reader_ltimer;
122 122
 static ticks_t tcp_reader_prev_ticks;
123 123
 
124
+/**
125
+ * control cloning of TCP receive buffer
126
+ * - needed for operations working directly inside the buffer
127
+ *   (like msg_apply_changes())
128
+ */
129
+#define TCP_CLONE_RCVBUF
130
+static int tcp_clone_rcvbuf = 0;
131
+
132
+int tcp_set_clone_rcvbuf(int v)
133
+{
134
+	int r;
135
+	r = tcp_clone_rcvbuf;
136
+	tcp_clone_rcvbuf = v;
137
+	return r;
138
+}
139
+
124 140
 #ifdef READ_HTTP11
125 141
 static inline char *strfindcasestrz(str *haystack, char *needlez)
126 142
 {
... ...
@@ -856,7 +872,6 @@ skip:
856 856
  * the content of the stream. Safer, make a clone of buf content in a local
857 857
  * buffer and give that to receive_msg() to link to msg->buf
858 858
  */
859
-#define TCP_CLONE_RCVBUF
860 859
 int receive_tcp_msg(char* tcpbuf, unsigned int len, struct receive_info* rcv_info)
861 860
 {
862 861
 #ifdef TCP_CLONE_RCVBUF
... ...
@@ -868,6 +883,10 @@ int receive_tcp_msg(char* tcpbuf, unsigned int len, struct receive_info* rcv_inf
868 868
 #endif
869 869
 	int blen;
870 870
 
871
+	/* cloning is disabled via parameter */
872
+	if(likely(tcp_clone_rcvbuf==0))
873
+		return receive_msg(tcpbuf, len, rcv_info);
874
+
871 875
 	/* min buffer size is BUF_SIZE */
872 876
 	blen = len;
873 877
 	if(blen < BUF_SIZE)