[Libreoffice-commits] online.git: net/Socket.cpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Tue Apr 4 04:29:51 UTC 2017


 net/Socket.cpp |   28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

New commits:
commit b734284b599bb612cd8eee13e761ce42c8eb8a6a
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Mon Apr 3 23:57:59 2017 -0400

    wsd: cleanup deflating HTTP responses
    
    Change-Id: Id21bdfcb5d3e04f27b681ee9581a0ed06283d163
    Reviewed-on: https://gerrit.libreoffice.org/36058
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/net/Socket.cpp b/net/Socket.cpp
index bac3a741..1f6d64d0 100644
--- a/net/Socket.cpp
+++ b/net/Socket.cpp
@@ -205,15 +205,17 @@ namespace HttpHelper
             response.set("ETag", "\"" LOOLWSD_VERSION_HASH "\"");
         }
 
-        if(!deflate)
+        int bufferSize = std::min(st.st_size, (off_t)Socket::MaximumSendBufferSize);
+        if (st.st_size >= socket->getSendBufferSize())
         {
-            int bufferSize = std::min(st.st_size, (off_t)Socket::MaximumSendBufferSize);
-            if (st.st_size >= socket->getSendBufferSize())
-            {
-                socket->setSocketBufferSize(bufferSize);
-                bufferSize = socket->getSendBufferSize();
-            }
+            socket->setSocketBufferSize(bufferSize);
+            bufferSize = socket->getSendBufferSize();
+        }
 
+        // Deflate is done over the full file, which can be too large.
+        // Skip deflating (ironically) if the file is too large.
+        if (!deflate || st.st_size > Socket::MaximumSendBufferSize * 10)
+        {
             response.setContentLength(st.st_size);
             std::ostringstream oss;
             response.write(oss);
@@ -246,18 +248,16 @@ namespace HttpHelper
             socket->send(header);
 
             std::ifstream file(path, std::ios::binary);
-            uLong bufferSize;
-            bufferSize = st.st_size;
-            char buf[bufferSize];
             bool flush = true;
             do
             {
-                unsigned int a = 9;
-                file.read(buf, sizeof(buf));
-                long unsigned int size = file.gcount();
+                static const unsigned int level = 9;
+                char buf[st.st_size]; // FIXME: Should compress in chunks.
+                file.read(buf, st.st_size);
+                const long unsigned int size = file.gcount();
                 long unsigned int compSize = compressBound(size);
                 char cbuf[compSize];
-                compress2((Bytef *)&cbuf, &compSize, (Bytef *)&buf, size, a) ;
+                compress2((Bytef *)&cbuf, &compSize, (Bytef *)&buf, size, level);
                 if (size > 0)
                     socket->send(cbuf, compSize, flush);
                 else


More information about the Libreoffice-commits mailing list