- 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.
... | ... |
@@ -54,7 +54,6 @@ |
54 | 54 |
/* maximum number of port aliases x search wildcard possibilities */ |
55 | 55 |
#define TCP_CON_MAX_ALIASES (4*3) |
56 | 56 |
|
57 |
-#define TCP_BUF_SIZE 4096 |
|
58 | 57 |
#define TCP_CHILD_TIMEOUT 5 /* after 5 seconds, the child "returns" |
59 | 58 |
the connection to the tcp master process */ |
60 | 59 |
#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, |
107 | 106 |
struct tcp_req{ |
108 | 107 |
struct tcp_req* next; |
109 | 108 |
/* sockaddr ? */ |
110 |
- char buf[TCP_BUF_SIZE+1]; /* bytes read so far (+0-terminator)*/ |
|
109 |
+ char* buf; /* bytes read so far (+0-terminator)*/ |
|
111 | 110 |
char* start; /* where the message starts, after all the empty lines are |
112 | 111 |
skipped*/ |
113 | 112 |
char* pos; /* current position in buf */ |
114 | 113 |
char* parsed; /* last parsed position */ |
115 | 114 |
char* body; /* body position */ |
115 |
+ unsigned int b_size; /* buffer size-1 (extra space for 0-term)*/ |
|
116 | 116 |
int content_len; |
117 | 117 |
int has_content_len; /* 1 if content_length was parsed ok*/ |
118 | 118 |
int complete; /* 1 if one req has been fully read, 0 otherwise*/ |
... | ... |
@@ -190,9 +190,11 @@ struct tcp_connection{ |
190 | 190 |
#define tcpconn_put(c) atomic_dec_and_test(&((c)->refcnt)) |
191 | 191 |
|
192 | 192 |
|
193 |
-#define init_tcp_req( r) \ |
|
193 |
+#define init_tcp_req( r, rd_buf, rd_buf_size) \ |
|
194 | 194 |
do{ \ |
195 | 195 |
memset( (r), 0, sizeof(struct tcp_req)); \ |
196 |
+ (r)->buf=(rd_buf) ;\ |
|
197 |
+ (r)->b_size=(rd_buf_size)-1; /* space for 0 term. */ \ |
|
196 | 198 |
(r)->parsed=(r)->pos=(r)->start=(r)->buf; \ |
197 | 199 |
(r)->error=TCP_REQ_OK;\ |
198 | 200 |
(r)->state=H_SKIP_EMPTY; \ |
... | ... |
@@ -130,7 +130,7 @@ int tcp_read(struct tcp_connection *c, int* flags) |
130 | 130 |
|
131 | 131 |
r=&c->req; |
132 | 132 |
fd=c->fd; |
133 |
- bytes_free=TCP_BUF_SIZE- (int)(r->pos - r->buf); |
|
133 |
+ bytes_free=r->b_size- (int)(r->pos - r->buf); |
|
134 | 134 |
|
135 | 135 |
if (bytes_free==0){ |
136 | 136 |
LOG(L_ERR, "ERROR: tcp_read: buffer overrun, dropping\n"); |