mirror of
https://github.com/3proxy/3proxy.git
synced 2026-05-13 05:51:38 +00:00
Allocate udp buffer dynamically
This commit is contained in:
parent
cbab76fe41
commit
0e13f57139
5 changed files with 21 additions and 10 deletions
|
|
@ -163,14 +163,14 @@ int start_proxy_thread(struct child * chp){
|
|||
_3proxy_sem_lock(conf.threadinit);
|
||||
#ifdef _WIN32
|
||||
#ifndef _WINCE
|
||||
h = (HANDLE)_beginthreadex((LPSECURITY_ATTRIBUTES )NULL, 32768+conf.stacksize, (void *)startsrv, (void *) chp, (DWORD)0, &thread);
|
||||
h = (HANDLE)_beginthreadex((LPSECURITY_ATTRIBUTES )NULL, 16384+conf.stacksize, (void *)startsrv, (void *) chp, (DWORD)0, &thread);
|
||||
#else
|
||||
h = (HANDLE)CreateThread((LPSECURITY_ATTRIBUTES )NULL, 32768+conf.stacksize, (void *)startsrv, (void *) chp, (DWORD)0, &thread);
|
||||
h = (HANDLE)CreateThread((LPSECURITY_ATTRIBUTES )NULL, 16384+conf.stacksize, (void *)startsrv, (void *) chp, (DWORD)0, &thread);
|
||||
#endif
|
||||
if(h)CloseHandle(h);
|
||||
#else
|
||||
pthread_attr_init(&pa);
|
||||
pthread_attr_setstacksize(&pa,PTHREAD_STACK_MIN + (65536+conf.stacksize));
|
||||
pthread_attr_setstacksize(&pa,PTHREAD_STACK_MIN + (32768+conf.stacksize));
|
||||
pthread_attr_setdetachstate(&pa,PTHREAD_CREATE_DETACHED);
|
||||
pthread_create(&thread, &pa, startsrv, (void *)chp);
|
||||
pthread_attr_destroy(&pa);
|
||||
|
|
|
|||
|
|
@ -349,6 +349,14 @@ int MODULEMAINFUNC (int argc, char** argv){
|
|||
#ifndef NOUDPMAIN
|
||||
if(isudp) {
|
||||
if(!udp_table.ihashtable)inithashtable(&udp_table, 64, 256, 65536);
|
||||
srv.udpbuf = malloc(UDPBUFSIZE);
|
||||
srv.udpbuf2 = malloc(UDPBUFSIZE);
|
||||
if(!srv.udpbuf || !srv.udpbuf2) {
|
||||
#ifndef STDMAIN
|
||||
haveerror = 2;
|
||||
#endif
|
||||
return 11;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
srv.service = defparam.service = childdef.service;
|
||||
|
|
@ -995,8 +1003,8 @@ int MODULEMAINFUNC (int argc, char** argv){
|
|||
if(hashresolv(&udp_table, &defparam, &toparam, NULL)) {
|
||||
int i, len=0;
|
||||
|
||||
if(toparam->udp_nhops - 1){
|
||||
for(i=1; i < toparam->udp_nhops - 1; i++){
|
||||
if(toparam->udp_nhops){
|
||||
for(i=1; i < toparam->udp_nhops; i++){
|
||||
len+=socks5_udp_build_hdr(srv.udpbuf2+len, &toparam->udp_relay[i-1]);
|
||||
}
|
||||
len += socks5_udp_build_hdr(srv.udpbuf2+len, &toparam->req);
|
||||
|
|
@ -1241,6 +1249,10 @@ void srvfree(struct srvparam * srv){
|
|||
if(srv->onetns) free(srv->onetns);
|
||||
#endif
|
||||
if(srv->so.freefunc) srv->so.freefunc(srv->so.state);
|
||||
#ifndef NOUDPMAIN
|
||||
if(srv->udpbuf) free(srv->udpbuf);
|
||||
if(srv->udpbuf2) free(srv->udpbuf2);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -569,11 +569,9 @@ struct srvparam {
|
|||
uint16_t targetport;
|
||||
unsigned char replace;
|
||||
time_t time_start;
|
||||
#ifndef NOUDPMAIN
|
||||
unsigned char udpbuf[UDPBUFSIZE];
|
||||
unsigned char udpbuf2[UDPBUFSIZE];
|
||||
unsigned char *udpbuf;
|
||||
unsigned char *udpbuf2;
|
||||
int udplen;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct clientparam {
|
||||
|
|
|
|||
|
|
@ -75,7 +75,6 @@ void * udppmchild(struct clientparam* param) {
|
|||
param->srvinbuf = 0;
|
||||
param->nwrites++;
|
||||
param->clisock = param->srv->srvsock;
|
||||
param->udp_nhops++;
|
||||
param->waitserver64 = 0x7fffffffffffffff;
|
||||
param->res = udpsockmap(param, conf.timeouts[STRING_L]);
|
||||
_3proxy_sem_lock(udpinit);
|
||||
|
|
|
|||
|
|
@ -57,6 +57,8 @@ int udpsockmap(struct clientparam *param, int timeo)
|
|||
int nhops = param->udp_nhops;
|
||||
int clisock_idx = -1, ctrlsock_idx = -1, ctrlsocksrv_idx = -1;
|
||||
int firstpacket = 1;
|
||||
|
||||
if(param->srv->service == S_UDPPM) nhops++;
|
||||
if (param->srvbufsize < UDPBUFSIZE) {
|
||||
unsigned char *newbuf = realloc(param->srvbuf, UDPBUFSIZE);
|
||||
if (!newbuf) return 21;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue