]> source.dussan.org Git - tigervnc.git/commitdiff
Check buffer usage with a simply boolean
authorPierre Ossman <ossman@cendio.se>
Sat, 16 May 2020 10:26:08 +0000 (12:26 +0200)
committerPierre Ossman <ossman@cendio.se>
Thu, 21 May 2020 09:34:22 +0000 (11:34 +0200)
External callers don't need to know the exact details, only if there is
data that needs to be flushed or not.

common/rdr/BufferedOutStream.cxx
common/rdr/BufferedOutStream.h
common/rfb/VNCSConnectionST.cxx
unix/x0vncserver/x0vncserver.cxx
unix/xserver/hw/vnc/XserverDesktop.cc

index cb2a0b0bb99da1628d88d3db23af61fc189571fa..930b80b99349e2c73ca06d7db793171da41a49cb 100644 (file)
@@ -51,11 +51,6 @@ size_t BufferedOutStream::length()
   return offset + ptr - sentUpTo;
 }
 
-size_t BufferedOutStream::bufferUsage()
-{
-  return ptr - sentUpTo;
-}
-
 void BufferedOutStream::flush()
 {
   struct timeval now;
@@ -63,12 +58,12 @@ void BufferedOutStream::flush()
   while (sentUpTo < ptr) {
     size_t len;
 
-    len = bufferUsage();
+    len = (ptr - sentUpTo);
 
     if (!flushBuffer(false))
       break;
 
-    offset += len - bufferUsage();
+    offset += len - (ptr - sentUpTo);
   }
 
   // Managed to flush everything?
@@ -99,6 +94,11 @@ void BufferedOutStream::flush()
   }
 }
 
+bool BufferedOutStream::hasBufferedData()
+{
+  return sentUpTo != ptr;
+}
+
 void BufferedOutStream::overrun(size_t needed)
 {
   size_t totalNeeded, newSize;
index 05727f6e32371f5dd59bce8fd2ce9ddc5263cc82..dd64a1364d4139fb0a08e858b29eb8f7937f9acb 100644 (file)
@@ -38,7 +38,9 @@ namespace rdr {
     virtual size_t length();
     virtual void flush();
 
-    size_t bufferUsage();
+    // hasBufferedData() checks if there is any data yet to be flushed
+
+    bool hasBufferedData();
 
   private:
     // flushBuffer() requests that the stream be flushed. Returns true if it is
index e23e9b875c8c985f8cc657623c78871c063f350b..6ac9edbea97e4be5d393842b36ac43e9ae4b166e 100644 (file)
@@ -115,10 +115,10 @@ void VNCSConnectionST::close(const char* reason)
     vlog.debug("second close: %s (%s)", peerEndpoint.buf, reason);
 
   try {
-    if (sock->outStream().bufferUsage() > 0) {
+    if (sock->outStream().hasBufferedData()) {
       sock->outStream().cork(false);
       sock->outStream().flush();
-      if (sock->outStream().bufferUsage() > 0)
+      if (sock->outStream().hasBufferedData())
         vlog.error("Failed to flush remaining socket data on close");
     }
   } catch (rdr::Exception& e) {
@@ -199,7 +199,7 @@ void VNCSConnectionST::flushSocket()
     sock->outStream().flush();
     // Flushing the socket might release an update that was previously
     // delayed because of congestion.
-    if (sock->outStream().bufferUsage() == 0)
+    if (!sock->outStream().hasBufferedData())
       writeFramebufferUpdate();
   } catch (rdr::Exception &e) {
     close(e.str());
@@ -832,7 +832,7 @@ bool VNCSConnectionST::isCongested()
   // Stuff still waiting in the send buffer?
   sock->outStream().flush();
   congestion.debugTrace("congestion-trace.csv", sock->getFd());
-  if (sock->outStream().bufferUsage() > 0)
+  if (sock->outStream().hasBufferedData())
     return true;
 
   if (!client.supportsFence())
index c406e3c9e778101e3a937017101ed4222aeeb3ff..a9782ada77634760f24a94973c916f4f25e9f0bb 100644 (file)
@@ -307,7 +307,7 @@ int main(int argc, char** argv)
           delete (*i);
         } else {
           FD_SET((*i)->getFd(), &rfds);
-          if ((*i)->outStream().bufferUsage() > 0)
+          if ((*i)->outStream().hasBufferedData())
             FD_SET((*i)->getFd(), &wfds);
           clients_connected++;
         }
index 5c8b4cef829a1221982a44679e8f9b9dc361f3e4..8215c936c8133208206ed7aa63e8f58781e78b5e 100644 (file)
@@ -366,7 +366,7 @@ void XserverDesktop::blockHandler(int* timeout)
         delete (*i);
       } else {
         /* Update existing NotifyFD to listen for write (or not) */
-        vncSetNotifyFd(fd, screenIndex, true, (*i)->outStream().bufferUsage() > 0);
+        vncSetNotifyFd(fd, screenIndex, true, (*i)->outStream().hasBufferedData());
       }
     }