mirror of
https://github.com/bgp/bgpq4.git
synced 2024-05-11 05:55:05 +00:00
Let OS decide on buffer size
This commit is contained in:
@@ -39,19 +39,15 @@
|
||||
#include "extern.h"
|
||||
#include "sx_report.h"
|
||||
|
||||
#ifndef SX_MAXSOCKBUF_MAX
|
||||
#define SX_MAXSOCKBUF_MAX (2 * 1024 * 1024)
|
||||
#endif
|
||||
|
||||
int
|
||||
sx_maxsockbuf(int s, int dir)
|
||||
{
|
||||
{
|
||||
int optval = 0, voptval;
|
||||
int hiconf = -1, loconf = -1;
|
||||
unsigned int voptlen;
|
||||
int phase = 0, iterations = 0;
|
||||
|
||||
if (s < 0) {
|
||||
if (s < 0) {
|
||||
sx_report(SX_FATAL,"Unable to maximize sockbuf on invalid "
|
||||
"socket %i\n", s);
|
||||
exit(1);
|
||||
@@ -65,30 +61,27 @@ sx_maxsockbuf(int s, int dir)
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
for (;;) {
|
||||
iterations++;
|
||||
|
||||
if (phase == 0)
|
||||
optval<<=1;
|
||||
else {
|
||||
optval <<= 1;
|
||||
else {
|
||||
if (optval == (hiconf + loconf) / 2)
|
||||
break;
|
||||
optval = (hiconf + loconf) / 2;
|
||||
}
|
||||
|
||||
if (optval > SX_MAXSOCKBUF_MAX && phase == 0)
|
||||
break;
|
||||
|
||||
if (setsockopt(s, SOL_SOCKET, dir, (void*)&optval,
|
||||
sizeof(optval)) == -1) {
|
||||
|
||||
if (phase == 0)
|
||||
phase = 1;
|
||||
phase = 1;
|
||||
|
||||
hiconf = optval;
|
||||
hiconf = optval;
|
||||
|
||||
continue;
|
||||
} else {
|
||||
} else {
|
||||
loconf = optval;
|
||||
}
|
||||
|
||||
@@ -99,39 +92,26 @@ sx_maxsockbuf(int s, int dir)
|
||||
sx_report(SX_ERROR,"getsockopt failed: %s\n",
|
||||
strerror(errno));
|
||||
return -1;
|
||||
} else if (voptval < optval) {
|
||||
if (phase == 0) {
|
||||
} else if (voptval < optval) {
|
||||
if (phase == 0) {
|
||||
phase = 1;
|
||||
optval >>= 1;
|
||||
continue;
|
||||
} else if (phase == 1) {
|
||||
} else if (phase == 1) {
|
||||
phase = 2;
|
||||
optval -= 2048;
|
||||
continue;
|
||||
} else
|
||||
break;
|
||||
} else if (voptval >= SX_MAXSOCKBUF_MAX) {
|
||||
/*
|
||||
* ... and getsockopt not failed and voptval>=optval.
|
||||
* Do not allow to increase sockbuf too much even in
|
||||
* case OS permits it
|
||||
*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
voptlen = sizeof(voptval);
|
||||
if (getsockopt(s, SOL_SOCKET, dir, (void*)&voptval,
|
||||
&voptlen) == -1) {
|
||||
sx_report(SX_ERROR,"getsockopt(final stage) failed: %s\n",
|
||||
sx_report(SX_ERROR,"getsockopt(final stage) failed: %s\n",
|
||||
strerror(errno));
|
||||
return -1;
|
||||
} else {
|
||||
/*
|
||||
printf("Finally got %i bytes of recvspace in %i interations\n",
|
||||
voptval, iterations);
|
||||
*/
|
||||
}
|
||||
|
||||
return voptval;
|
||||
} else
|
||||
return voptval;
|
||||
}
|
||||
|
Reference in New Issue
Block a user