mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2024-12-22 14:22:23 +00:00
Add set buffer sizes code to Phy<>
This commit is contained in:
parent
7295fcfa86
commit
40e0a34a5c
@ -655,6 +655,36 @@ public:
|
|||||||
return (PhySocket *)&sws;
|
return (PhySocket *)&sws;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try to set buffer sizes as close to the given value as possible
|
||||||
|
*
|
||||||
|
* This will try the specified value and then lower values in 16K increments
|
||||||
|
* until one works.
|
||||||
|
*
|
||||||
|
* @param sock Socket
|
||||||
|
* @param bufferSize Desired buffer sizes
|
||||||
|
*/
|
||||||
|
inline void setBufferSizes(const PhySocket *sock,int bufferSize)
|
||||||
|
{
|
||||||
|
PhySocketImpl &sws = *(reinterpret_cast<PhySocketImpl *>(sock));
|
||||||
|
if (bufferSize > 0) {
|
||||||
|
int bs = bufferSize;
|
||||||
|
while (bs >= 65536) {
|
||||||
|
int tmpbs = bs;
|
||||||
|
if (::setsockopt(sws.sock,SOL_SOCKET,SO_RCVBUF,(const char *)&tmpbs,sizeof(tmpbs)) == 0)
|
||||||
|
break;
|
||||||
|
bs -= 16384;
|
||||||
|
}
|
||||||
|
bs = bufferSize;
|
||||||
|
while (bs >= 65536) {
|
||||||
|
int tmpbs = bs;
|
||||||
|
if (::setsockopt(sws.sock,SOL_SOCKET,SO_SNDBUF,(const char *)&tmpbs,sizeof(tmpbs)) == 0)
|
||||||
|
break;
|
||||||
|
bs -= 16384;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempt to send data to a stream socket (non-blocking)
|
* Attempt to send data to a stream socket (non-blocking)
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user