mirror of
https://github.com/3proxy/3proxy.git
synced 2026-11-27 07:59:41 +08:00
adding state to socket functions
This commit is contained in:
1 parent
d83c1f47f8
commit
8198db8617
18 files changed
+462
-360
No files matched your search
+14
-13
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "proxy.h"
|
||||
|
||||
int socksend(SOCKET sock, unsigned char * buf, int bufsize, int to){
|
||||
int socksend(struct clientparam *param, SOCKET sock, unsigned char * buf, int bufsize, int to){
|
||||
int sent = 0;
|
||||
int res;
|
||||
struct pollfd fds;
|
||||
@@ -16,10 +16,10 @@ int socksend(SOCKET sock, unsigned char * buf, int bufsize, int to){
|
||||
fds.events = POLLOUT;
|
||||
do {
|
||||
if(conf.timetoexit) return 0;
|
||||
res = so._poll(&fds, 1, to*1000);
|
||||
res = param?param->srv->so._poll(param->sostate, &fds, 1, to*1000):so._poll(so.state, &fds, 1, to*1000);
|
||||
if(res < 0 && (errno == EAGAIN || errno == EINTR)) continue;
|
||||
if(res < 1) break;
|
||||
res = so._send(sock, (char *)buf + sent, bufsize - sent, 0);
|
||||
res = param?param->srv->so._send(param->sostate, sock, (char *)buf + sent, bufsize - sent, 0) : so._send(so.state, sock, (char *)buf + sent, bufsize - sent, 0);
|
||||
if(res < 0) {
|
||||
if(errno == EAGAIN || errno == EINTR) continue;
|
||||
break;
|
||||
@@ -30,7 +30,7 @@ int socksend(SOCKET sock, unsigned char * buf, int bufsize, int to){
|
||||
}
|
||||
|
||||
|
||||
int socksendto(SOCKET sock, struct sockaddr * sin, unsigned char * buf, int bufsize, int to){
|
||||
int socksendto(struct clientparam *param, SOCKET sock, struct sockaddr * sin, unsigned char * buf, int bufsize, int to){
|
||||
int sent = 0;
|
||||
int res;
|
||||
struct pollfd fds;
|
||||
@@ -39,10 +39,10 @@ int socksendto(SOCKET sock, struct sockaddr * sin, unsigned char * buf, int bufs
|
||||
do {
|
||||
if(conf.timetoexit) return 0;
|
||||
fds.events = POLLOUT;
|
||||
res = so._poll(&fds, 1, to);
|
||||
res = param?param->srv->so._poll(param->sostate, &fds, 1, to*1000):so._poll(so.state, &fds, 1, to*1000);
|
||||
if(res < 0 && (errno == EAGAIN || errno == EINTR)) continue;
|
||||
if(res < 1) break;
|
||||
res = so._sendto(sock, (char *)buf + sent, bufsize - sent, 0, sin, SASIZE(sin));
|
||||
res = param?param->srv->so._sendto(param->sostate, sock, (char *)buf + sent, bufsize - sent, 0, sin, SASIZE(sin)):so._sendto(so.state, sock, (char *)buf + sent, bufsize - sent, 0, sin, SASIZE(sin));
|
||||
if(res < 0) {
|
||||
if(errno != EAGAIN && errno != EINTR) break;
|
||||
continue;
|
||||
@@ -52,7 +52,7 @@ int socksendto(SOCKET sock, struct sockaddr * sin, unsigned char * buf, int bufs
|
||||
return sent;
|
||||
}
|
||||
|
||||
int sockrecvfrom(SOCKET sock, struct sockaddr * sin, unsigned char * buf, int bufsize, int to){
|
||||
int sockrecvfrom(struct clientparam *param, SOCKET sock, struct sockaddr * sin, unsigned char * buf, int bufsize, int to){
|
||||
struct pollfd fds;
|
||||
SASIZETYPE sasize;
|
||||
int res;
|
||||
@@ -60,10 +60,11 @@ int sockrecvfrom(SOCKET sock, struct sockaddr * sin, unsigned char * buf, int bu
|
||||
fds.fd = sock;
|
||||
fds.events = POLLIN;
|
||||
if(conf.timetoexit) return EOF;
|
||||
if (so._poll(&fds, 1, to)<1) return 0;
|
||||
res = param?param->srv->so._poll(param->sostate, &fds, 1, to*1000):so._poll(so.state, &fds, 1, to*1000);
|
||||
if (res<1) return 0;
|
||||
sasize = SASIZE(sin);
|
||||
do {
|
||||
res = so._recvfrom(sock, (char *)buf, bufsize, 0, (struct sockaddr *)sin, &sasize);
|
||||
res = param?param->srv->so._recvfrom(param->sostate, sock, (char *)buf, bufsize, 0, (struct sockaddr *)sin, &sasize):so._recvfrom(so.state, sock, (char *)buf, bufsize, 0, (struct sockaddr *)sin, &sasize);
|
||||
} while (res < 0 && (errno == EAGAIN || errno == EINTR));
|
||||
return res;
|
||||
}
|
||||
@@ -80,7 +81,7 @@ int sockgetcharcli(struct clientparam * param, int timeosec, int timeousec){
|
||||
return (int)param->clibuf[param->clioffset++];
|
||||
}
|
||||
param->clioffset = param->cliinbuf = 0;
|
||||
if ((len = sockrecvfrom(param->clisock, (struct sockaddr *)¶m->sincr, param->clibuf, param->clibufsize, timeosec*1000 + timeousec))<=0) return EOF;
|
||||
if ((len = sockrecvfrom(param, param->clisock, (struct sockaddr *)¶m->sincr, param->clibuf, param->clibufsize, timeosec*1000 + timeousec))<=0) return EOF;
|
||||
param->cliinbuf = len;
|
||||
param->clioffset = 1;
|
||||
return (int)*param->clibuf;
|
||||
@@ -100,7 +101,7 @@ int sockfillbuffcli(struct clientparam * param, unsigned long size, int timeosec
|
||||
}
|
||||
if(size <= param->cliinbuf) return size;
|
||||
size -= param->cliinbuf;
|
||||
if((len = sockrecvfrom(param->clisock, (struct sockaddr *)¶m->sincr, param->clibuf + param->cliinbuf, (param->clibufsize - param->cliinbuf) < size? param->clibufsize - param->cliinbuf:size, timeosec*1000)) > 0){
|
||||
if((len = sockrecvfrom(param, param->clisock, (struct sockaddr *)¶m->sincr, param->clibuf + param->cliinbuf, (param->clibufsize - param->cliinbuf) < size? param->clibufsize - param->cliinbuf:size, timeosec*1000)) > 0){
|
||||
param->cliinbuf += len;
|
||||
}
|
||||
return param->cliinbuf;
|
||||
@@ -120,7 +121,7 @@ int sockfillbuffsrv(struct clientparam * param, unsigned long size, int timeosec
|
||||
}
|
||||
if(size <= param->srvinbuf) return size;
|
||||
size -= param->srvinbuf;
|
||||
if((len = sockrecvfrom(param->remsock, (struct sockaddr *)¶m->sinsr, param->srvbuf + param->srvinbuf, (param->srvbufsize - param->srvinbuf) < size? param->srvbufsize - param->srvinbuf:size, timeosec*1000)) > 0){
|
||||
if((len = sockrecvfrom(param, param->remsock, (struct sockaddr *)¶m->sinsr, param->srvbuf + param->srvinbuf, (param->srvbufsize - param->srvinbuf) < size? param->srvbufsize - param->srvinbuf:size, timeosec*1000)) > 0){
|
||||
param->srvinbuf += len;
|
||||
param->nreads++;
|
||||
param->statssrv64 += len;
|
||||
@@ -145,7 +146,7 @@ int sockgetcharsrv(struct clientparam * param, int timeosec, int timeousec){
|
||||
return (int)param->srvbuf[param->srvoffset++];
|
||||
}
|
||||
param->srvoffset = param->srvinbuf = 0;
|
||||
if ((len = sockrecvfrom(param->remsock, (struct sockaddr *)¶m->sinsr, param->srvbuf, param->srvbufsize, timeosec*1000 + timeousec))<=0) return EOF;
|
||||
if ((len = sockrecvfrom(param, param->remsock, (struct sockaddr *)¶m->sinsr, param->srvbuf, param->srvbufsize, timeosec*1000 + timeousec))<=0) return EOF;
|
||||
param->srvinbuf = len;
|
||||
param->srvoffset = 1;
|
||||
param->nreads++;
|
||||
|
||||
Reference in new issue
Block a user