//TODO: Factor out the `i32` raw sockets in these types below into a seperate `RawPipe` struct, which has the Drop impl and has functions for transfering ownership of the raw socket (it should hide the raw fd when not explicitly needed ideally.)
// This will prevent us from having to ensure we `forget()` the outer type each time we want to move the inner one around without closing it.
/// A writer for a bi-directinoal unix pipe
/// A writer for a bi-directinoal unix pipe
///
///
/// Created by splitting `Pipe`, data written to this is available to be read from its `ReadHalf` counterpart.
/// Created by splitting `Pipe`, data written to this is available to be read from its `ReadHalf` counterpart.
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq)]
pubstructWriteHalf(i32);
pubstructWriteHalf(RawPipe);
/// A reader for a bi-directional unix pipe.
/// A reader for a bi-directional unix pipe.
///
///
/// Created by splitting `Pipe`, data read from this is data that was sent to its `WriteHalf` counterpart.
/// Created by splitting `Pipe`, data read from this is data that was sent to its `WriteHalf` counterpart.
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq)]
pubstructReadHalf(i32);
pubstructReadHalf(RawPipe);
/// A bi-drectional unix pipe
/// A bi-drectional unix pipe
///
///
@ -55,11 +129,10 @@ pub struct ReadHalf(i32);
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq)]
pubstructPipe
pubstructPipe
{
{
tx: i32,
tx: RawPipe,
rx: i32,
rx: RawPipe,
}
}
// Make sure when operating on consumers of Pipe of Read/WriteHalf, the pipe structures are `mem::forget`ed before returning, since the Drop impl of those types closes the raw socket.
implPipe
implPipe
{
{
/// Split this pipe into a read and write half.
/// Split this pipe into a read and write half.
@ -67,9 +140,7 @@ impl Pipe
/// Data written to the `WriteHalf` is sent to the `ReadHalf` (unless the pipe is mismatched.)
/// Data written to the `WriteHalf` is sent to the `ReadHalf` (unless the pipe is mismatched.)
#[inline]pubfnsplit(self)-> (WriteHalf,ReadHalf)
#[inline]pubfnsplit(self)-> (WriteHalf,ReadHalf)
{
{
letrv=(WriteHalf(self.tx),ReadHalf(self.rx));
(WriteHalf(self.tx),ReadHalf(self.rx))
std::mem::forget(self);
rv
}
}
/// Create a `Pipe` from two halves.
/// Create a `Pipe` from two halves.
@ -79,16 +150,14 @@ impl Pipe
/// If they are not, then writing to the `Pipe` will send the data to its original receiver, and reading from it will take the data from its original sender.
/// If they are not, then writing to the `Pipe` will send the data to its original receiver, and reading from it will take the data from its original sender.