@@ -139,6 +139,7 @@ void HTTPConnection::closeConnection() {
139
139
140
140
if (_wsHandler != nullptr ) {
141
141
HTTPS_LOGD (" Free WS Handler" );
142
+ _wsHandler->onClose ();
142
143
delete _wsHandler;
143
144
_wsHandler = NULL ;
144
145
}
@@ -206,7 +207,7 @@ int HTTPConnection::updateBuffer() {
206
207
} else {
207
208
// An error occured
208
209
_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);
210
211
closeConnection ();
211
212
return -1 ;
212
213
}
@@ -254,7 +255,7 @@ size_t HTTPConnection::readBuffer(byte* buffer, size_t length) {
254
255
255
256
size_t HTTPConnection::pendingBufferSize () {
256
257
updateBuffer ();
257
-
258
+ if ( isClosed ()) return 0 ;
258
259
return _bufferUnusedIdx - _bufferProcessed + pendingByteCount ();
259
260
}
260
261
@@ -586,11 +587,15 @@ void HTTPConnection::loop() {
586
587
}
587
588
588
589
// If the handler has terminated the connection, clean up and close the socket too
589
- if (_wsHandler->closed () || _clientState == CSTATE_CLOSED) {
590
- HTTPS_LOGI (" WS closed, freeing Handler, FID=%d" , _socket);
591
- delete _wsHandler;
592
- _wsHandler = nullptr ;
593
- _connectionState = STATE_CLOSING;
590
+ if (_wsHandler != nullptr ){
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;
596
+ }
597
+ } else {
598
+ HTTPS_LOGI (" WS closed due to SSL level issue and cleanded up" );
594
599
}
595
600
break ;
596
601
default :;
0 commit comments