[Libreoffice-commits] online.git: Branch 'private/Ashod/nonblocking' - net/socket.hpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Sat Feb 18 21:17:17 UTC 2017
net/socket.hpp | 28 +++++++++++++++++++++-------
1 file changed, 21 insertions(+), 7 deletions(-)
New commits:
commit ddb0ea6a9d641488fd5a939fb4e0d2f69ae54da2
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Sat Feb 18 13:48:44 2017 -0500
nb: drain the read buffer before dispatching
Draining the buffer is the correct appraoch
to avoid accumulating data in the kernel
unnecessarily. But it also reduces the overhead
of reparsing the incoming data for message
boundaries.
The client that is to parse the data should
parse as many messages as possible and remove
them from the socket buffer.
Finally, we probably need to cap the maximum
buffer size to avoid bloating. However this
heavily depends on the application's max
message size, assuming there is no separate
buffer beyond that of the socket to accumulate
the messages in.
Change-Id: I49c4eccebd474cd07ca84f3f4eae33bc717ed1f2
Reviewed-on: https://gerrit.libreoffice.org/34411
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/net/socket.hpp b/net/socket.hpp
index 0eec7f0..780c390 100644
--- a/net/socket.hpp
+++ b/net/socket.hpp
@@ -345,16 +345,30 @@ public:
{
ssize_t len;
char buf[4096];
- do {
- len = ::read(getFD(), buf, sizeof(buf));
- } while (len < 0 && errno == EINTR);
- if (len > 0)
+ bool gotNewData = false;
+ do
+ {
+ // Drain the read buffer.
+ // TODO: Cap the buffer size, lest we grow beyond control.
+ do
+ {
+ len = ::read(getFD(), buf, sizeof(buf));
+ }
+ while (len < 0 && errno == EINTR);
+ if (len > 0)
+ {
+ assert (len < ssize_t(sizeof(buf)));
+ _inBuffer.insert(_inBuffer.end(), &buf[0], &buf[len]);
+ gotNewData = true;
+ }
+ // else poll will handle errors.
+ }
+ while (len > 0);
+
+ if (gotNewData)
{
- assert (len < ssize_t(sizeof(buf)));
- _inBuffer.insert(_inBuffer.end(), &buf[0], &buf[len]);
handleIncomingMessage();
}
- // else poll will handle errors.
return len != 0; // zero is eof / clean socket close.
}
More information about the Libreoffice-commits
mailing list