diff options
author | Attila Molnar <attilamolnar@hush.com> | 2015-06-08 12:30:56 +0200 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2015-06-08 12:30:56 +0200 |
commit | 68c06dd45fa32466ef924c8d6db9ef6649bf3ff7 (patch) | |
tree | e753f3992e0238a3d086449e86b7fb567ae6f3cd /include/modules | |
parent | 9b9326ff08565c6cf4acdc865884cc7c1f426822 (diff) | |
parent | f8bd10737457e9775038bda4448ae6bbb75cce74 (diff) |
Merge branch 'master+sendq'
Diffstat (limited to 'include/modules')
-rw-r--r-- | include/modules/ssl.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/include/modules/ssl.h b/include/modules/ssl.h index 0f58e0b7b..67bfc7b2e 100644 --- a/include/modules/ssl.h +++ b/include/modules/ssl.h @@ -138,6 +138,31 @@ class SSLIOHook : public IOHook */ reference<ssl_cert> certificate; + /** Reduce elements in a send queue by appending later elements to the first element until there are no more + * elements to append or a desired length is reached + * @param sendq SendQ to work on + * @param targetsize Target size of the front element + */ + static void FlattenSendQueue(StreamSocket::SendQueue& sendq, size_t targetsize) + { + if ((sendq.size() <= 1) || (sendq.front().length() >= targetsize)) + return; + + // Avoid multiple repeated SSL encryption invocations + // This adds a single copy of the queue, but avoids + // much more overhead in terms of system calls invoked + // by an IOHook. + std::string tmp; + tmp.reserve(std::min(targetsize, sendq.bytes())+1); + do + { + tmp.append(sendq.front()); + sendq.pop_front(); + } + while (!sendq.empty() && tmp.length() < targetsize); + sendq.push_front(tmp); + } + public: SSLIOHook(IOHookProvider* hookprov) : IOHook(hookprov) |