Skip to content

Commit

Permalink
Merge pull request #4 from bligeti/master
Browse files Browse the repository at this point in the history
Merge fhessel#89 from fhessel/esp32_https_server
  • Loading branch information
KaloNK authored Nov 29, 2021
2 parents 14ab041 + 2bf7522 commit 64dd18e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
19 changes: 12 additions & 7 deletions src/HTTPConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ void HTTPConnection::closeConnection() {

if (_wsHandler != nullptr) {
HTTPS_LOGD("Free WS Handler");
_wsHandler->onClose();
delete _wsHandler;
_wsHandler = NULL;
}
Expand Down Expand Up @@ -206,7 +207,7 @@ int HTTPConnection::updateBuffer() {
} else {
// An error occured
_connectionState = STATE_ERROR;
HTTPS_LOGE("An receive error occured, FID=%d", _socket);
HTTPS_LOGE("An receive error occurred, FID=%d, code=%d", _socket, readReturnCode);
closeConnection();
return -1;
}
Expand Down Expand Up @@ -254,7 +255,7 @@ size_t HTTPConnection::readBuffer(byte* buffer, size_t length) {

size_t HTTPConnection::pendingBufferSize() {
updateBuffer();

if (isClosed()) return 0;
return _bufferUnusedIdx - _bufferProcessed + pendingByteCount();
}

Expand Down Expand Up @@ -586,11 +587,15 @@ void HTTPConnection::loop() {
}

// If the handler has terminated the connection, clean up and close the socket too
if (_wsHandler->closed() || _clientState == CSTATE_CLOSED) {
HTTPS_LOGI("WS closed, freeing Handler, FID=%d", _socket);
delete _wsHandler;
_wsHandler = nullptr;
_connectionState = STATE_CLOSING;
if (_wsHandler != nullptr){
if (_wsHandler->closed() || _clientState == CSTATE_CLOSED) {
HTTPS_LOGI("WS closed, freeing Handler, FID=%d", _socket);
delete _wsHandler;
_wsHandler = nullptr;
_connectionState = STATE_CLOSING;
}
} else {
HTTPS_LOGI("WS closed due to SSL level issue and cleanded up");
}
break;
default:;
Expand Down
6 changes: 5 additions & 1 deletion src/HTTPSConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ size_t HTTPSConnection::writeBuffer(byte* buffer, size_t length) {
}

size_t HTTPSConnection::readBytesToBuffer(byte* buffer, size_t length) {
return SSL_read(_ssl, buffer, length);
int ret = SSL_read(_ssl, buffer, length);
if (ret < 0) {
HTTPS_LOGD("SSL_read error: %d", SSL_get_error(_ssl, ret));
}
return ret;
}

size_t HTTPSConnection::pendingByteCount() {
Expand Down

0 comments on commit 64dd18e

Please sign in to comment.