Skip to content

Commit

Permalink
Increase socket buffer size
Browse files Browse the repository at this point in the history
* Unify the buffer size

* TXT RRs are likely to include more contents
* Uncompressed cache result costs more room
  • Loading branch information
lifenjoiner committed Sep 26, 2024
1 parent b518503 commit 60a3f94
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 35 deletions.
16 changes: 7 additions & 9 deletions hosts.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#include "domainstatistic.h"
#include "mmgr.h"

#define CONTEXT_DATA_LENGTH 2048

extern BOOL Ipv6_Enabled;

static BOOL BlockIpv6WhenIpv4Exists = FALSE;
Expand Down Expand Up @@ -134,14 +132,14 @@ Hosts_SocketLoop(void *Unused)

struct timeval TimeLimit = LongTime;

#define LEFT_LENGTH_SL (CONTEXT_DATA_LENGTH - sizeof(IHeader))
#define LEFT_LENGTH_SL (SOCKET_CONTEXT_LENGTH - sizeof(IHeader))

char InnerBuffer[CONTEXT_DATA_LENGTH];
char InnerBuffer[SOCKET_CONTEXT_LENGTH];
MsgContext *InnerMsgCtx = (MsgContext *)InnerBuffer;
IHeader *InnerHeader = (IHeader *)InnerBuffer;
/* char *InnerEntity = InnerBuffer + sizeof(IHeader); */

char OuterBuffer[CONTEXT_DATA_LENGTH];
char OuterBuffer[SOCKET_CONTEXT_LENGTH];
/* MsgContext *OuterMsgCtx = (MsgContext *)OuterBuffer; */
IHeader *OuterHeader = (IHeader *)OuterBuffer;
char *OuterEntity = OuterBuffer + sizeof(IHeader);
Expand All @@ -165,7 +163,7 @@ Hosts_SocketLoop(void *Unused)
Puller.Add(&Puller, InnerSocket, NULL, 0);
Puller.Add(&Puller, OuterSocket, NULL, 0);

if( ModuleContext_Init(&Context, CONTEXT_DATA_LENGTH) != 0 )
if( ModuleContext_Init(&Context, SOCKET_CONTEXT_LENGTH) != 0 )
{
ret = -431;
goto EXIT_1;
Expand Down Expand Up @@ -219,7 +217,7 @@ Hosts_SocketLoop(void *Unused)
NewIdentifier = rand();

if( HostsUtils_GenerateQuery(OuterBuffer,
CONTEXT_DATA_LENGTH,
SOCKET_CONTEXT_LENGTH,
OuterSocket,
&OuterAddress,
MsgContext_IsFromTCP(InnerMsgCtx),
Expand All @@ -242,7 +240,7 @@ Hosts_SocketLoop(void *Unused)

OuterHeader->Parent = (IHeader *)MsgCtxStored;

MMgr_Send(OuterBuffer, CONTEXT_DATA_LENGTH);
MMgr_Send(OuterBuffer, SOCKET_CONTEXT_LENGTH);

} else if( Pulled == OuterSocket )
{
Expand Down Expand Up @@ -274,7 +272,7 @@ Hosts_SocketLoop(void *Unused)
}

if( HostsUtils_CombineRecursedResponse((MsgContext *)InnerBuffer,
CONTEXT_DATA_LENGTH,
SOCKET_CONTEXT_LENGTH,
OuterEntity,
State,
OuterHeader->Domain
Expand Down
2 changes: 0 additions & 2 deletions hostsutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#include "dnsgenerator.h"
#include "goodiplist.h"

#define CONTEXT_DATA_LENGTH 2048

static int HostsUtils_GetCName_Callback(int Number,
HostsRecordType Type,
const char *Data,
Expand Down
6 changes: 3 additions & 3 deletions iheader.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ struct _IHeader{

/* The **variable** context item structure:
#define CONTEXT_DATA_LENGTH 2048
struct _MsgContext{
IHeader h;
char Entity[CONTEXT_DATA_LENGTH - sizeof(IHeader)];
char Entity[SOCKET_CONTEXT_LENGTH - sizeof(IHeader)];
};
*/

#define SOCKET_CONTEXT_LENGTH 4096

#define IHEADER_TAIL(ptr) (void *)((IHeader *)(ptr) + 1)

void IHeader_Reset(IHeader *h);
Expand Down
8 changes: 3 additions & 5 deletions tcpfrontend.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ WINAPI
#endif
TcpFrontend_Work(void *Unused)
{
/* Buffer */
#define BUF_LENGTH 2048
char *ReceiveBuffer;
IHeader *Header;

#define LEFT_LENGTH (BUF_LENGTH - sizeof(IHeader))
#define LEFT_LENGTH (SOCKET_CONTEXT_LENGTH - sizeof(IHeader))
char *Entity;

ReceiveBuffer = SafeMalloc(BUF_LENGTH);
ReceiveBuffer = SafeMalloc(SOCKET_CONTEXT_LENGTH);
if( ReceiveBuffer == NULL )
{
ERRORMSG("No enough memory, 26.\n");
Expand Down Expand Up @@ -103,7 +101,7 @@ TcpFrontend_Work(void *Unused)
Agent
);

MMgr_Send(ReceiveBuffer, BUF_LENGTH);
MMgr_Send(ReceiveBuffer, SOCKET_CONTEXT_LENGTH);

if( IsNewConnected )
{
Expand Down
10 changes: 4 additions & 6 deletions tcpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ extern BOOL Ipv6_Enabled;
#define TIMEOUT_ms_RECV 2000
#define TIMEOUT_ms_ALIVE 100

#define CONTEXT_DATA_LENGTH 2048

extern int TCPM_Keep_Alive;
static const struct timeval TimeOut_Const = {TIMEOUT, 0};

Expand Down Expand Up @@ -543,11 +541,11 @@ TcpM_Works(TcpM *m)
{
int Err;

char ReceiveBuffer[CONTEXT_DATA_LENGTH];
char ReceiveBuffer[SOCKET_CONTEXT_LENGTH];
MsgContext *MsgCtx;
IHeader *Header;

#define LEFT_LENGTH (CONTEXT_DATA_LENGTH - sizeof(IHeader))
#define LEFT_LENGTH (SOCKET_CONTEXT_LENGTH - sizeof(IHeader))
char *Entity;

SocketPuller *p = &(m->Puller);
Expand Down Expand Up @@ -589,7 +587,7 @@ TcpM_Works(TcpM *m)

State = recvfrom(s,
ReceiveBuffer, /* Receiving a header */
CONTEXT_DATA_LENGTH,
SOCKET_CONTEXT_LENGTH,
0,
NULL,
NULL
Expand Down Expand Up @@ -750,7 +748,7 @@ int TcpM_Init(TcpM *m, const char *Services, BOOL Parallel, const char *SocksPro
return -7;
}

if( ModuleContext_Init(&(m->Context), CONTEXT_DATA_LENGTH) != 0 )
if( ModuleContext_Init(&(m->Context), SOCKET_CONTEXT_LENGTH) != 0 )
{
return -12;
}
Expand Down
8 changes: 3 additions & 5 deletions udpfrontend.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ WINAPI
#endif
UdpFrontend_Work(void *Unused)
{
/* Buffer */
#define BUF_LENGTH 2048
char *ReceiveBuffer;
IHeader *Header;

#define LEFT_LENGTH (BUF_LENGTH - sizeof(IHeader))
#define LEFT_LENGTH (SOCKET_CONTEXT_LENGTH - sizeof(IHeader))
char *Entity;

ReceiveBuffer = SafeMalloc(BUF_LENGTH);
ReceiveBuffer = SafeMalloc(SOCKET_CONTEXT_LENGTH);
if( ReceiveBuffer == NULL )
{
ERRORMSG("No enough memory, 26.\n");
Expand Down Expand Up @@ -102,7 +100,7 @@ UdpFrontend_Work(void *Unused)
Agent
);

MMgr_Send(ReceiveBuffer, BUF_LENGTH);
MMgr_Send(ReceiveBuffer, SOCKET_CONTEXT_LENGTH);
}
SafeFree(ReceiveBuffer);
}
Expand Down
8 changes: 3 additions & 5 deletions udpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include "domainstatistic.h"
#include "timedtask.h"

#define CONTEXT_DATA_LENGTH 2048

static void SweepWorks(MsgContext *MsgCtx, int Number, UdpM *Module)
{
IHeader *h = (IHeader *)MsgCtx;
Expand Down Expand Up @@ -79,11 +77,11 @@ UdpM_Works(UdpM *m)

struct sockaddr *addr;

char ReceiveBuffer[CONTEXT_DATA_LENGTH];
char ReceiveBuffer[SOCKET_CONTEXT_LENGTH];
MsgContext *MsgCtx;
IHeader *Header;

#define LEFT_LENGTH (CONTEXT_DATA_LENGTH - sizeof(IHeader))
#define LEFT_LENGTH (SOCKET_CONTEXT_LENGTH - sizeof(IHeader))
char *Entity;

fd_set ReadSet, ReadySet;
Expand Down Expand Up @@ -395,7 +393,7 @@ int UdpM_Init(UdpM *m, const char *Services, BOOL Parallel)
m->Parallels.addrlen = 0;
}

if( ModuleContext_Init(&(m->Context), CONTEXT_DATA_LENGTH) != 0 )
if( ModuleContext_Init(&(m->Context), SOCKET_CONTEXT_LENGTH) != 0 )
{
ret = -143;
goto EXIT_3;
Expand Down

0 comments on commit 60a3f94

Please sign in to comment.