Skip to content

Commit

Permalink
Use getOutStream replace sock->outStream
Browse files Browse the repository at this point in the history
  • Loading branch information
KangLin committed Sep 5, 2024
1 parent 2d5636e commit 4bafa23
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions common/rfb/VNCSConnectionST.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,15 @@ void VNCSConnectionST::close(const char* reason)
vlog.debug("second close: %s (%s)", peerEndpoint.c_str(), reason);

try {
if (sock->outStream().hasBufferedData()) {
sock->outStream().cork(false);
sock->outStream().flush();
if (sock->outStream().hasBufferedData())
vlog.error("Failed to flush remaining socket data on close");
auto out = getOutStream();
if (out.hasBufferedData()) {
out.cork(false);
out.flush();
if (out.hasBufferedData())
vlog.error("Failed to flush remaining data of out stream on close");
}
} catch (rdr::Exception& e) {
vlog.error("Failed to flush remaining socket data on close: %s", e.str());
vlog.error("Failed to flush remaining data of out stream on close: %s", e.str());
}

// Just shutdown the socket and mark our state as closing. Eventually the
Expand Down Expand Up @@ -201,10 +202,11 @@ void VNCSConnectionST::flushSocket()
{
if (state() == RFBSTATE_CLOSING) return;
try {
sock->outStream().flush();
auto out = getOutStream();
out.flush();
// Flushing the socket might release an update that was previously
// delayed because of congestion.
if (!sock->outStream().hasBufferedData())
if (!out.hasBufferedData())
writeFramebufferUpdate();
} catch (rdr::Exception &e) {
close(e.str());
Expand Down Expand Up @@ -837,7 +839,7 @@ void VNCSConnectionST::writeRTTPing()
if (!client.supportsFence())
return;

congestion.updatePosition(sock->outStream().length());
congestion.updatePosition(getOutStream().length());

// We need to make sure any old update are already processed by the
// time we get the response back. This allows us to reliably throttle
Expand All @@ -856,15 +858,16 @@ bool VNCSConnectionST::isCongested()
congestionTimer.stop();

// Stuff still waiting in the send buffer?
sock->outStream().flush();
auto out = getOutStream();
out.flush();
congestion.debugTrace("congestion-trace.csv", sock->getFd());
if (sock->outStream().hasBufferedData())
if (out.hasBufferedData())
return true;

if (!client.supportsFence())
return false;

congestion.updatePosition(sock->outStream().length());
congestion.updatePosition(out.length());
if (!congestion.isCongested())
return false;

Expand All @@ -878,7 +881,7 @@ bool VNCSConnectionST::isCongested()

void VNCSConnectionST::writeFramebufferUpdate()
{
congestion.updatePosition(sock->outStream().length());
congestion.updatePosition(getOutStream().length());

// We're in the middle of processing a command that's supposed to be
// synchronised. Allowing an update to slip out right now might violate
Expand Down Expand Up @@ -917,7 +920,7 @@ void VNCSConnectionST::writeFramebufferUpdate()

getOutStream()->cork(false);

congestion.updatePosition(sock->outStream().length());
congestion.updatePosition(getOutStream().length());
}

void VNCSConnectionST::writeNoDataUpdate()
Expand Down

0 comments on commit 4bafa23

Please sign in to comment.