@ -109,6 +109,8 @@ static void resolv_free_cb(void *data);
int verbose = 0 ;
int reuse_port = 0 ;
int tcp_incoming_sndbuf = 0 ;
int tcp_outgoing_sndbuf = 0 ;
int is_bind_local_addr = 0 ;
struct sockaddr_storage local_addr_v4 ;
@ -471,6 +473,10 @@ connect_to_remote(EV_P_ struct addrinfo *res,
# endif
setsockopt ( sockfd , SOL_SOCKET , SO_REUSEADDR , & opt , sizeof ( opt ) ) ;
if ( tcp_outgoing_sndbuf > 0 ) {
setsockopt ( sockfd , SOL_SOCKET , SO_SNDBUF , & tcp_outgoing_sndbuf , sizeof ( int ) ) ;
}
/ / setup remote socks
if ( setnonblocking ( sockfd ) = = - 1 )
@ -1538,6 +1544,11 @@ accept_cb(EV_P_ ev_io *w, int revents)
# ifdef SO_NOSIGPIPE
setsockopt ( serverfd , SOL_SOCKET , SO_NOSIGPIPE , & opt , sizeof ( opt ) ) ;
# endif
if ( tcp_incoming_sndbuf > 0 ) {
setsockopt ( serverfd , SOL_SOCKET , SO_SNDBUF , & tcp_incoming_sndbuf , sizeof ( int ) ) ;
}
setnonblocking ( serverfd ) ;
server_t * server = new_server ( serverfd , listener ) ;
@ -1577,6 +1588,8 @@ main(int argc, char **argv)
static struct option long_options [ ] = {
{ " fast-open " , no_argument , NULL , GETOPT_VAL_FAST_OPEN } ,
{ " reuse-port " , no_argument , NULL , GETOPT_VAL_REUSE_PORT } ,
{ " tcp-incoming-sndbuf " , required_argument , NULL , GETOPT_VAL_TCP_INCOMING_SNDBUF } ,
{ " tcp-outgoing-sndbuf " , required_argument , NULL , GETOPT_VAL_TCP_OUTGOING_SNDBUF } ,
{ " no-delay " , no_argument , NULL , GETOPT_VAL_NODELAY } ,
{ " acl " , required_argument , NULL , GETOPT_VAL_ACL } ,
{ " manager-address " , required_argument , NULL ,
@ -1634,6 +1647,12 @@ main(int argc, char **argv)
case GETOPT_VAL_REUSE_PORT :
reuse_port = 1 ;
break ;
case GETOPT_VAL_TCP_INCOMING_SNDBUF :
tcp_incoming_sndbuf = atoi ( optarg ) ;
break ;
case GETOPT_VAL_TCP_OUTGOING_SNDBUF :
tcp_outgoing_sndbuf = atoi ( optarg ) ;
break ;
case ' s ' :
if ( server_num < MAX_REMOTE_NUM ) {
parse_addr ( optarg , & server_addr [ server_num + + ] ) ;
@ -1760,6 +1779,12 @@ main(int argc, char **argv)
if ( reuse_port = = 0 ) {
reuse_port = conf - > reuse_port ;
}
if ( tcp_incoming_sndbuf = = 0 ) {
tcp_incoming_sndbuf = conf - > tcp_incoming_sndbuf ;
}
if ( tcp_outgoing_sndbuf = = 0 ) {
tcp_outgoing_sndbuf = conf - > tcp_outgoing_sndbuf ;
}
if ( fast_open = = 0 ) {
fast_open = conf - > fast_open ;
}
@ -1787,6 +1812,22 @@ main(int argc, char **argv)
}
}
if ( tcp_incoming_sndbuf ! = 0 & & tcp_incoming_sndbuf < SOCKET_BUF_SIZE ) {
tcp_incoming_sndbuf = 0 ;
}
if ( tcp_incoming_sndbuf ! = 0 ) {
LOGI ( " set TCP incoming connection send buffer size to %d " , tcp_incoming_sndbuf ) ;
}
if ( tcp_outgoing_sndbuf ! = 0 & & tcp_outgoing_sndbuf < SOCKET_BUF_SIZE ) {
tcp_outgoing_sndbuf = 0 ;
}
if ( tcp_outgoing_sndbuf ! = 0 ) {
LOGI ( " set TCP outgoing connection send buffer size to %d " , tcp_outgoing_sndbuf ) ;
}
if ( server_num = = 0 ) {
server_addr [ server_num + + ] . host = " 0.0.0.0 " ;
}