Support for half-open connections
- Dominant language
- Dart
- Stars
- 1.1k
- Forks
- 419
- Avg merge
- 4d 14h
- Merged PRs (30d)
- 8
Description
A tcp-socket can be closed in one direction (the client can close one direction after it is done sending the request, and still listen for more response).
We should support this in package:http2.
Currently this program:
```dart
import 'dart:io';
import 'dart:async';
import 'dart:isolate';
import 'package:http2/http2.dart';
client(port) async {
Socket s = await Socket.connect('localhost', port);
final ctc = ClientTransportConnection.viaSocket(s);
final cts = ctc.makeRequest([Header.ascii("a", "b")]);
cts.incomingMessages.listen(print);
await Future.delayed(Duration(seconds: 2));
print("closing client socket outgoing");
s.close();
}
spawnClient(port) async {
await Isolate.spawn(client, port);
}
main() async {
ServerSocket ss = await ServerSocket.bind('localhost', 0);
spawnClient(ss.port);
Socket s = await ss.first;
ServerTransportStream ts;
print("Listening");
new ServerTransportConnection.viaSocket(s).incomingStreams.listen((stream) {
print("got stream");
ts = stream;
}, onDone: () {
print("done");
ts.sendHeaders([Header.ascii("foo", "bar")]);
});
}
```
prints:
```
Listening
got stream
closing client socket
Unhandled exception:
Bad state: StreamSink is bound to a stream
#0 _StreamSinkImpl.close (dart:io/io_sink.dart:218:7)
dart-lang/http#1342 _Socket.close (dart:io/runtime/binsocket_patch.dart:1627:27)
dart-lang/http#1343 client (file:///usr/local/google/home/sigurdm/projects/blah/bin/http2sample.dart:14:5)
dart-lang/http#1344 _startIsolate. (dart:isolate/runtime/libisolate_patch.dart:292:17)
dart-lang/http#1345 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)
done
Unhandled exception:
Bad state: Cannot add event after closing
#0 _StreamController.add (dart:async/stream_controller.dart:585:24)
dart-lang/http#1342 _StreamSinkWrapper.add (dart:async/stream_controller.dart:858:13)
dart-lang/http#1343 TransportStream.sendHeaders (package:http2/transport.dart:145:10)
dart-lang/http#1344 main. (file:///usr/local/google/home/sigurdm/projects/blah/bin/http2sample.dart:32:8)
dart-lang/http#1345 _RootZone.runGuarded (dart:async/zone.dart:1302:10)
dart-lang/http#1346 _BufferingStreamSubscription._sendDone.sendDone (dart:async/stream_impl.dart:389:13)
dart-lang/http#1347 _BufferingStreamSubscription._sendDone (dart:async/stream_impl.dart:399:15)
```
Contributor guide
Assessment
This issue has not been assessed yet.