Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions lib/src/database/db.dart
Original file line number Diff line number Diff line change
Expand Up @@ -471,14 +471,16 @@ class Db {
bool tlsAllowInvalidCertificates = false,
String? tlsCAFile,
String? tlsCertificateKeyFile,
String? tlsCertificateKeyFilePassword}) async {
String? tlsCertificateKeyFilePassword,
Function? onConnectionClosed}) async {
if (state == State.opening) {
throw MongoDartError('Attempt to open db in state $state');
}

state = State.opening;
_writeConcern = writeConcern;
_connectionManager = ConnectionManager(this);
_connectionManager =
ConnectionManager(this, onConnectionClosed: onConnectionClosed);

for (var uri in _uriList) {
_connectionManager!.addConnection(await _parseUri(uri,
Expand Down
2 changes: 2 additions & 0 deletions lib/src/network/connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ class Connection {
if (!_closed) {
await _closeSocketOnError(socketError: e);
}
_manager.onConnectionClosed?.call();
},
cancelOnError: true,
// onDone is not called in any case after onData or OnError,
Expand All @@ -223,6 +224,7 @@ class Connection {
if (!_closed) {
await _closeSocketOnError(socketError: noSecureRequestError);
}
_manager.onConnectionClosed?.call();
});
connected = true;
return true;
Expand Down
3 changes: 2 additions & 1 deletion lib/src/network/connection_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ class ConnectionManager {
final replyCompleters = <int, Completer<MongoResponseMessage>>{};
final sendQueue = Queue<MongoMessage>();
Connection? _masterConnection;
final Function? onConnectionClosed;

ConnectionManager(this.db);
ConnectionManager(this.db, {this.onConnectionClosed});

Connection? get masterConnection => _masterConnection;

Expand Down