Skip to content

Commit 3e97446

Browse files
authored
Update HTTPConnection.cpp for changes issue fhessel#89
May help in crash fix for websockets.
1 parent 402894e commit 3e97446

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/HTTPConnection.cpp

+12-7
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ void HTTPConnection::closeConnection() {
139139

140140
if (_wsHandler != nullptr) {
141141
HTTPS_LOGD("Free WS Handler");
142+
_wsHandler->onClose();
142143
delete _wsHandler;
143144
_wsHandler = NULL;
144145
}
@@ -206,7 +207,7 @@ int HTTPConnection::updateBuffer() {
206207
} else {
207208
// An error occured
208209
_connectionState = STATE_ERROR;
209-
HTTPS_LOGE("An receive error occured, FID=%d", _socket);
210+
HTTPS_LOGE("An receive error occurred, FID=%d, code=%d", _socket, readReturnCode);
210211
closeConnection();
211212
return -1;
212213
}
@@ -254,7 +255,7 @@ size_t HTTPConnection::readBuffer(byte* buffer, size_t length) {
254255

255256
size_t HTTPConnection::pendingBufferSize() {
256257
updateBuffer();
257-
258+
if (isClosed()) return 0;
258259
return _bufferUnusedIdx - _bufferProcessed + pendingByteCount();
259260
}
260261

@@ -588,11 +589,15 @@ void HTTPConnection::loop() {
588589
}
589590

590591
// If the handler has terminated the connection, clean up and close the socket too
591-
if (_wsHandler->closed() || _clientState == CSTATE_CLOSED) {
592-
HTTPS_LOGI("WS closed, freeing Handler, FID=%d", _socket);
593-
delete _wsHandler;
594-
_wsHandler = nullptr;
595-
_connectionState = STATE_CLOSING;
592+
if (_wsHandler != nullptr){
593+
if (_wsHandler->closed() || _clientState == CSTATE_CLOSED) {
594+
HTTPS_LOGI("WS closed, freeing Handler, FID=%d", _socket);
595+
delete _wsHandler;
596+
_wsHandler = nullptr;
597+
_connectionState = STATE_CLOSING;
598+
}
599+
} else {
600+
HTTPS_LOGI("WS closed due to SSL level issue and cleanded up");
596601
}
597602
break;
598603
default:;

0 commit comments

Comments
 (0)