Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged fixing of closure event behaviour from tinywebsockets #15

Merged
merged 1 commit into from
Jun 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/websockets_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ namespace websockets {
} else if(msg.isPong()) {
_handlePong(std::move(msg));
} else if(msg.isClose()) {
this->_connectionOpen = false;
_handleClose(std::move(msg));
}
}
Expand Down Expand Up @@ -440,11 +441,19 @@ namespace websockets {
}

bool WebsocketsClient::available(const bool activeTest) {
this->_connectionOpen &= this->_client && this->_client->available();
if(this->_connectionOpen && activeTest) {
if(activeTest) {
_endpoint.ping("");
}
return _connectionOpen;

bool updatedConnectionOpen = this->_connectionOpen && this->_client && this->_client->available();

if(updatedConnectionOpen != this->_connectionOpen) {
_endpoint.close(CloseReason_AbnormalClosure);
this->_eventsCallback(*this, WebsocketsEvent::ConnectionClosed, "");
}

this->_connectionOpen = updatedConnectionOpen;
return this->_connectionOpen;
}

bool WebsocketsClient::ping(const WSInterfaceString data) {
Expand All @@ -463,8 +472,8 @@ namespace websockets {

void WebsocketsClient::close(const CloseReason reason) {
if(available()) {
_endpoint.close(reason);
this->_connectionOpen = false;
_endpoint.close(reason);
_handleClose({});
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/websockets_endpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,10 @@ namespace internals {
}

void WebsocketsEndpoint::close(CloseReason reason) {
this->_closeReason = reason;

if(!this->_client->available()) return;

this->_closeReason = reason;
if(reason == CloseReason_None) {
send(nullptr, 0, internals::ContentType::Close, true, this->_useMasking);
} else {
Expand Down