Skip to content

Handling of errors - like unstable network - coming via SSL #89

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

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
19 changes: 12 additions & 7 deletions src/HTTPConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ void HTTPConnection::closeConnection() {

if (_httpHeaders != NULL) {
HTTPS_LOGD("Free headers");
_wsHandler->onClose();
delete _httpHeaders;
_httpHeaders = 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 occured, FID=%d, SSL_error=%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 @@ -588,11 +589,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