Skip to content

Commit

Permalink
Added a check to work-around a bug in ESP32's libs (connect returns t…
Browse files Browse the repository at this point in the history
…rue even when connection actually failed - no endpoint)
  • Loading branch information
gilmaimon committed Aug 1, 2019
1 parent aad6457 commit ca5ab95
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/websockets_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ namespace websockets {
auto handshake = generateHandshake(internals::fromInterfaceString(host), internals::fromInterfaceString(path), _customHeaders);
this->_client->send(handshake.requestStr);

// This check is needed because of an ESP32 lib bug that wont signal that the connection had
// failed in `->connect` (called above), sometimes the disconnect will only be noticed here (after a `send`)
if(!available()) {
return false;
}

auto head = this->_client->readLine();
if(!doestStartsWith(head, "HTTP/1.1 101")) {
close(CloseReason_ProtocolError);
Expand Down

0 comments on commit ca5ab95

Please sign in to comment.