Skip to content

Commit

Permalink
Merge pull request #23 from atsign-foundation/fix-socket-closed-while…
Browse files Browse the repository at this point in the history
…-other-side-still-writing

fix: socket closed while other side still writing
  • Loading branch information
gkc authored Nov 12, 2024
2 parents 4128bcf + 2204d47 commit afa33e0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/src/socket_connector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,18 @@ class SocketConnector {
StreamController<Uint8List> sc = StreamController<Uint8List>();
side.farSide!.sink = sc;
Stream<List<int>> transformed = side.transformer!(sc.stream);
transformed.listen((event) {
transformed.listen((event) async {
try {
side.farSide!.socket.add(event);
await side.farSide!.socket.flush();
} catch (e) {
_log('Failed to write to side ${side.farSide!.name} - closing',
force: true);
_destroySide(side.farSide!);
}
});
}
side.stream.listen((Uint8List data) {
side.stream.listen((Uint8List data) async {
if (logTraffic) {
final message = String.fromCharCodes(data);
if (side.isSideA) {
Expand All @@ -164,6 +165,7 @@ class SocketConnector {
}
try {
side.farSide!.sink.add(data);
await side.farSide!.socket.flush();
} catch (e) {
_log('Failed to write to side ${side.farSide!.name} - closing',
force: true);
Expand Down

0 comments on commit afa33e0

Please sign in to comment.