return offset + ptr - sentUpTo;
}
-size_t BufferedOutStream::bufferUsage()
-{
- return ptr - sentUpTo;
-}
-
void BufferedOutStream::flush()
{
struct timeval now;
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?
}
}
+bool BufferedOutStream::hasBufferedData()
+{
+ return sentUpTo != ptr;
+}
+
void BufferedOutStream::overrun(size_t needed)
{
size_t totalNeeded, newSize;
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) {
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());
// 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())
delete (*i);
} else {
FD_SET((*i)->getFd(), &rfds);
- if ((*i)->outStream().bufferUsage() > 0)
+ if ((*i)->outStream().hasBufferedData())
FD_SET((*i)->getFd(), &wfds);
clients_connected++;
}
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());
}
}