New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dart should support anonymous pipes #49917
Comments
How does this look as an API? /// An `AnonymousPipe` holds two [RandomAccessFile]s that each allow unidirectional data flow
/// i.e. data written to [writePipe] can be read from [readPipe]. Creating an [AnonymousPipe] is
/// possible on Windows but, since there is no way to transmit it to another process, probably not
/// useful.
///
/// Either the [readPipe] or [writePipe] can be transmitted to a another process and used for interprocess
/// communication.
///
/// For example:
///
/// ```dart
/// import 'dart:async';
/// import 'dart:io';
///
/// void main() async {
/// final address =
/// InternetAddress('sock', type: InternetAddressType.unix);
/// final socket = await RawSocket.connect(address, 0);
///. final pipe = await AnonymousPipe.create();
///
/// await socket.sendMessage(<SocketControlMessage>[
/// SocketControlMessage.fromHandles(
/// <ResourceHandle>[ResourceHandle.fromFile(pipe.readPipe)])
/// ], 'Hi'.codeUnits);
/// await pipe.write.writeString("Message");
/// }
/// ```
abstract class AnonymousPipe {
RandomAccessFile get readPipe;
RandomAccessFile get writePipe;
static Future<AnonymousPipe> create();
static AnonymousPipe createSync();
} I'd actual prefer to not create a new class for this. Does anyone have an alternative API suggestion? |
Wait for records and use For naming, why is it Consider: abstract class Pipe {
RandomAccessFile get read; // Would use "in" and "out", but "in" is a reserved word.
RandomAccessFile get write;
external factory Pipe.createSync();
externals static Pipe create();
} Is Even more alternatively, could it be a single Also consider a |
In the example above socket.sendMessage is used to communicate one end of the pipe to another process, but this does not work on Windows, what would be the option on Windows ? Also @rmacnak-google points out that anonymous pipes created on Windows do not support non blocking IO (this maybe an issue for dart:io) |
Thanks for the feedback!
I was thinking about it 😆
I'm not sure what will happen on Windows but on Unix, it should return the number of bytes left to be read.
You get f = await File('something').open(); // read is the default mode
await f.writeString('Hi'); // Same exception as above.
You mean for the
I'd rather not introduce a new |
Yeah, I don't think that being able to create pipes would be useful on Windows.
Isn't |
@aam, @rmacnak-google seem to also prefer the abstract class ReadPipe implements Stream<Uint8List> {
Future<int> unreadBytes(); // The number of unread bytes.
}
abstract class WritePipe implements Sink<Uint8List> {
}
abstract class Pipe {
ReadPipe get read; // Can't just be a Stream<Uint8List> because that won't work with ResourceHandle
WritePipe get write; // Can't just be a Sink<Uint8List> because that won't work with ResourceHandle
factory Pipe.createSync();
static Future<Pipe> create();
}
// ResourceHandle needs two new methods to extract file descriptors from read/write pipes:
ResourceHandle.fromReadPipe(ReadPipe pipe);
ResourceHandle.fromWritePipe(WritePipe pipe); IMO: This seems pretty heavy - we need two need classes and two new methods in But I'm happy to go with that if it is more idiomatic. |
Some of the proposed API is using the term 'pipe' for the pipe ends - this will be confusing. I suggest something like: abstract class Pipe {
RandomAccessFile reaEnd;
RandomAccessFile writeEnd;
} or abstract class Pipe {
PipeInput input;
PipeOutput output;
} |
@robert-ancell Ack. We won't do that. @aam @rmacnak-google @lrhn : I implemented the proposal where the read end of the pipe is a UPDATE: I think that I can fix this behavior without changing the interface (which is described below) The exact interface looked like: abstract class ReadPipe implements Stream<List<int>> {
// Future<int> unreadBytes(); // The number of unread bytes.
}
abstract class WritePipe implements IOSink {
}
abstract class Pipe {
ReadPipe get read;
WritePipe get write;
static Future<Pipe> create() {
return _Pipe._create();
}
} My test code was: void main() async {
final pipe = await Pipe.create();
pipe.read.listen((event) {
print(event);
}) // onDone is triggered immediately because no data was written to the pipe.
}
Options:
|
Fixed in 2ead86a |
Dart should support anonymous pipes (e.g. as returned by the
pipe
system call).Requested by @robert-ancell in #47310.
The text was updated successfully, but these errors were encountered: