From 28d46052b0495879fe67130f05efeb4c1da20063 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 3 Apr 2019 09:50:52 +0200 Subject: [PATCH] HttpServerConnection#StartStreaming(): auto-detect disconnection --- lib/remote/httpserverconnection.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/remote/httpserverconnection.cpp b/lib/remote/httpserverconnection.cpp index 5c40e2e83..7d08d8ae4 100644 --- a/lib/remote/httpserverconnection.cpp +++ b/lib/remote/httpserverconnection.cpp @@ -93,7 +93,25 @@ void HttpServerConnection::Disconnect() void HttpServerConnection::StartStreaming() { + namespace asio = boost::asio; + m_HasStartedStreaming = true; + + HttpServerConnection::Ptr keepAlive (this); + + asio::spawn(m_IoStrand, [this, keepAlive](asio::yield_context yc) { + if (!m_ShuttingDown) { + char buf[128]; + asio::mutable_buffer readBuf (buf, 128); + boost::system::error_code ec; + + do { + m_Stream->async_read_some(readBuf, yc[ec]); + } while (!ec); + + Disconnect(); + } + }); } static inline