Back out "Clear handlers on disconnect"

Summary:
^

Revert as to validate this is not causing regressions: T143523262

Reviewed By: passy

Differential Revision: D42800560

fbshipit-source-id: 8db61454eabfdb259637bb97c2bb4754984ecf6f
This commit is contained in:
Lorenzo Blasa
2023-01-27 04:07:37 -08:00
committed by Facebook GitHub Bot
parent 2cc273ce96
commit 2ba167f899
3 changed files with 33 additions and 33 deletions

View File

@@ -144,10 +144,6 @@ static constexpr int connectionKeepaliveSeconds = 10;
return;
}
_socket = [[SRWebSocket alloc] initWithURL:self->_url
securityPolicy:self->_policy];
_socket.delegate = self;
__weak auto weakSelf = self;
[_dispatchQueue addOperationWithBlock:^{
__strong auto strongSelf = weakSelf;
@@ -162,32 +158,33 @@ static constexpr int connectionKeepaliveSeconds = 10;
return;
}
strongSelf->_socket = [[SRWebSocket alloc] initWithURL:self->_url
securityPolicy:self->_policy];
strongSelf->_socket.delegate = self;
[strongSelf->_socket open];
}];
}
- (void)disconnect {
_socket.delegate = nil;
// Manually trigger a 'close' event as SocketRocket close method will
// not notify the delegate. SocketRocket only triggers the close event
// when the connection is closed from the server. Furthermore,
// we are clearing the delegate above.
_eventHandler(facebook::flipper::SocketEvent::CLOSE);
_eventHandler = [](facebook::flipper::SocketEvent) {};
_messageHandler = ^(const std::string&) {
};
_policy.certificateProvider = [](char* _Nonnull, size_t) { return ""; };
[_dispatchQueue cancelAllOperations];
[_dispatchQueue waitUntilAllOperationsAreFinished];
if ([_keepAlive isValid]) {
[_keepAlive invalidate];
}
_keepAlive = nil;
_socket = nil;
// Manually trigger a 'close' event as SocketRocket close method will
// not notify the delegate. SocketRocket only triggers the close event
// when the connection is closed from the server.
_eventHandler(facebook::flipper::SocketEvent::CLOSE);
if (_socket) {
// Clear the socket delegate before close. Ensures that we won't get
// any messages after the disconnect takes place.
_socket.delegate = nil;
[_socket close];
_socket = nil;
};
}
- (void)send:(NSString*)message
@@ -205,6 +202,7 @@ static constexpr int connectionKeepaliveSeconds = 10;
- (void)setCertificateProvider:
(facebook::flipper::SocketCertificateProvider)certificateProvider {
_certificateProvider = certificateProvider;
_policy.certificateProvider = certificateProvider;
}
@@ -243,6 +241,7 @@ static constexpr int connectionKeepaliveSeconds = 10;
} else {
_eventHandler(facebook::flipper::SocketEvent::ERROR);
}
_socket = nil;
}
- (void)_webSocketDidClose {
@@ -252,6 +251,7 @@ static constexpr int connectionKeepaliveSeconds = 10;
_keepAlive = nil;
_eventHandler(facebook::flipper::SocketEvent::CLOSE);
_socket = nil;
}
- (void)_webSocketDidReceiveMessage:(id)message {