diff --git a/CHANGES b/CHANGES index e50b295..814da01 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +0.1.13 (2011-06-14) + - Fixed bug in sx_maxsockbuf in rare cases of OS maxsockbuf >2M. + Thanks to Andreas Lundin. + 0.1.12 (2010-10-08) - Fixed bug preventing AS262144 (that's AS4.0 in asdot) to expand. Thanks to Sergey Matveychuk diff --git a/sx_maxsockbuf.c b/sx_maxsockbuf.c index 6912503..c6f400d 100644 --- a/sx_maxsockbuf.c +++ b/sx_maxsockbuf.c @@ -11,6 +11,10 @@ #include "sx_report.h" +#ifndef SX_MAXSOCKBUF_MAX +#define SX_MAXSOCKBUF_MAX (2*1024*1024) +#endif + int sx_maxsockbuf(int s, int dir) { @@ -39,7 +43,7 @@ sx_maxsockbuf(int s, int dir) if(optval==(hiconf+loconf)/2) break; optval=(hiconf+loconf)/2; }; - if(optval>(2*1024*1024)) { + if(optval>SX_MAXSOCKBUF_MAX) { if(phase==0) { phase=1; optval>>=1; continue; } else break; @@ -59,14 +63,16 @@ sx_maxsockbuf(int s, int dir) if(getsockopt(s,SOL_SOCKET,dir,(void*)&voptval,&voptlen)==-1) { sx_report(SX_ERROR,"getsockopt failed: %s\n", strerror(errno)); return -1; - } else { - if(voptval>=1; continue; - } else if(phase==1) { - phase=2; optval-=2048; continue; - } else break; - }; + } else if(voptval>=1; continue; + } else if(phase==1) { + phase=2; optval-=2048; continue; + } else break; + } else if(optval>=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; }; };