mirror of
https://github.com/ohwgiles/laminar.git
synced 2024-10-27 20:34:20 +00:00
better socket closing
This commit is contained in:
parent
f923762c7e
commit
3ee5b4f8f6
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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<void>();
|
||||
if(payload.empty()) {
|
||||
stream->shutdownWrite();
|
||||
return kj::Promise<void>(kj::READY_NOW);
|
||||
} else {
|
||||
return stream->write(payload.data(), payload.size()).then([this](){
|
||||
return closeOnComplete ? kj::Promise<void>(kj::READY_NOW) : writeTask();
|
||||
return closeOnComplete ? stream->shutdownWrite(), kj::Promise<void>(kj::READY_NOW) : writeTask();
|
||||
}).attach(kj::mv(payload));
|
||||
}
|
||||
});
|
||||
@ -316,11 +317,13 @@ 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;
|
||||
if(now) {
|
||||
outputBuffer.clear();
|
||||
writePaf.fulfiller->fulfill();
|
||||
}
|
||||
}
|
||||
|
||||
std::streamsize xsputn(const char* s, std::streamsize sz) override {
|
||||
outputBuffer.append(std::string(s, sz));
|
||||
|
Loading…
Reference in New Issue
Block a user