diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-10-27 13:04:08 -0700 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-10-27 13:04:08 -0700 |
commit | 40e0a34a5c22276e5546dc7835eec87282ac9484 (patch) | |
tree | d6e10b542517279af5e5cdc12f8f1d644f4ee6dc /osdep | |
parent | 7295fcfa86aafdca76ac0210ca59ad9a70a2d67a (diff) | |
download | infinitytier-40e0a34a5c22276e5546dc7835eec87282ac9484.tar.gz infinitytier-40e0a34a5c22276e5546dc7835eec87282ac9484.zip |
Add set buffer sizes code to Phy<>
Diffstat (limited to 'osdep')
-rw-r--r-- | osdep/Phy.hpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/osdep/Phy.hpp b/osdep/Phy.hpp index 94130faf..8dde279c 100644 --- a/osdep/Phy.hpp +++ b/osdep/Phy.hpp @@ -656,6 +656,36 @@ public: } /** + * 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) * * If -1 is returned, the socket should no longer be used as it is now |