diff --git a/src/interface.h b/src/interface.h index 057603b..317993c 100644 --- a/src/interface.h +++ b/src/interface.h @@ -69,7 +69,7 @@ struct MonitorScope { // registerClient and deregisterClient struct LaminarClient { virtual void sendMessage(std::string payload) = 0; - virtual void close() = 0; + virtual void close(bool now = true) = 0; MonitorScope scope; }; diff --git a/src/server.cpp b/src/server.cpp index dafe911..bc57022 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -189,7 +189,7 @@ public: // 404 c->set_status(websocketpp::http::status_code::not_found); } - c->lc->close(); + c->lc->close(false); }); // Handle new websocket connection. Parse the URL to determine @@ -303,10 +303,11 @@ struct Server::WebsocketConnection : public LaminarClient, public std::streambuf payload.swap(outputBuffer); writePaf = kj::newPromiseAndFulfiller(); if(payload.empty()) { + stream->shutdownWrite(); return kj::Promise(kj::READY_NOW); } else { return stream->write(payload.data(), payload.size()).then([this](){ - return closeOnComplete ? kj::Promise(kj::READY_NOW) : writeTask(); + return closeOnComplete ? stream->shutdownWrite(), kj::Promise(kj::READY_NOW) : writeTask(); }).attach(kj::mv(payload)); } }); @@ -316,10 +317,12 @@ struct Server::WebsocketConnection : public LaminarClient, public std::streambuf cn->send(payload, websocketpp::frame::opcode::text); } - void close() override { + void close(bool now) override { closeOnComplete = true; - outputBuffer.clear(); - writePaf.fulfiller->fulfill(); + if(now) { + outputBuffer.clear(); + writePaf.fulfiller->fulfill(); + } } std::streamsize xsputn(const char* s, std::streamsize sz) override {