Parcourir la source

tcp: config option for the read buffer size

- the read buffer size can now be configured both at runtime and
  from ser.cfg (tcp_rd_buf_size). A high value will help
  performance for tcp connections with lots of traffic, however it
  will increase the memory consumption. As a rule of thumb use
  high values(e.g. 32768, 65536) on servers which open only a few
  tcp connections and have very heavy traffic on them and a low
  value (e.g. 4096, 2048) on servers that are expected to have
  lots of open connections (50k - 100k+). Note also that this
  value will also limit the maximum sip datagram size that can be
  received on tcp. The default value is 4096.
Andrei Pelinescu-Onciul il y a 16 ans
Parent
commit
827cd3beca
2 fichiers modifiés avec 6 ajouts et 4 suppressions
  1. 5 3
      tcp_conn.h
  2. 1 1
      tcp_read.c

+ 5 - 3
tcp_conn.h

@@ -54,7 +54,6 @@
 /* maximum number of port aliases x search wildcard possibilities */
 /* maximum number of port aliases x search wildcard possibilities */
 #define TCP_CON_MAX_ALIASES (4*3) 
 #define TCP_CON_MAX_ALIASES (4*3) 
 
 
-#define TCP_BUF_SIZE	4096 
 #define TCP_CHILD_TIMEOUT 5 /* after 5 seconds, the child "returns" 
 #define TCP_CHILD_TIMEOUT 5 /* after 5 seconds, the child "returns" 
 							 the connection to the tcp master process */
 							 the connection to the tcp master process */
 #define TCP_MAIN_SELECT_TIMEOUT 5 /* how often "tcp main" checks for timeout*/
 #define TCP_MAIN_SELECT_TIMEOUT 5 /* how often "tcp main" checks for timeout*/
@@ -107,12 +106,13 @@ enum conn_cmds { CONN_DESTROY=-3, CONN_ERROR=-2, CONN_EOF=-1, CONN_RELEASE,
 struct tcp_req{
 struct tcp_req{
 	struct tcp_req* next;
 	struct tcp_req* next;
 	/* sockaddr ? */
 	/* sockaddr ? */
-	char buf[TCP_BUF_SIZE+1]; /* bytes read so far (+0-terminator)*/
+	char* buf; /* bytes read so far (+0-terminator)*/
 	char* start; /* where the message starts, after all the empty lines are
 	char* start; /* where the message starts, after all the empty lines are
 					skipped*/
 					skipped*/
 	char* pos; /* current position in buf */
 	char* pos; /* current position in buf */
 	char* parsed; /* last parsed position */
 	char* parsed; /* last parsed position */
 	char* body; /* body position */
 	char* body; /* body position */
+	unsigned int b_size; /* buffer size-1 (extra space for 0-term)*/
 	int content_len;
 	int content_len;
 	int has_content_len; /* 1 if content_length was parsed ok*/
 	int has_content_len; /* 1 if content_length was parsed ok*/
 	int complete; /* 1 if one req has been fully read, 0 otherwise*/
 	int complete; /* 1 if one req has been fully read, 0 otherwise*/
@@ -190,9 +190,11 @@ struct tcp_connection{
 #define tcpconn_put(c) atomic_dec_and_test(&((c)->refcnt))
 #define tcpconn_put(c) atomic_dec_and_test(&((c)->refcnt))
 
 
 
 
-#define init_tcp_req( r) \
+#define init_tcp_req( r, rd_buf, rd_buf_size) \
 	do{ \
 	do{ \
 		memset( (r), 0, sizeof(struct tcp_req)); \
 		memset( (r), 0, sizeof(struct tcp_req)); \
+		(r)->buf=(rd_buf) ;\
+		(r)->b_size=(rd_buf_size)-1; /* space for 0 term. */ \
 		(r)->parsed=(r)->pos=(r)->start=(r)->buf; \
 		(r)->parsed=(r)->pos=(r)->start=(r)->buf; \
 		(r)->error=TCP_REQ_OK;\
 		(r)->error=TCP_REQ_OK;\
 		(r)->state=H_SKIP_EMPTY; \
 		(r)->state=H_SKIP_EMPTY; \

+ 1 - 1
tcp_read.c

@@ -130,7 +130,7 @@ int tcp_read(struct tcp_connection *c, int* flags)
 
 
 	r=&c->req;
 	r=&c->req;
 	fd=c->fd;
 	fd=c->fd;
-	bytes_free=TCP_BUF_SIZE- (int)(r->pos - r->buf);
+	bytes_free=r->b_size- (int)(r->pos - r->buf);
 	
 	
 	if (bytes_free==0){
 	if (bytes_free==0){
 		LOG(L_ERR, "ERROR: tcp_read: buffer overrun, dropping\n");
 		LOG(L_ERR, "ERROR: tcp_read: buffer overrun, dropping\n");