Pass socket-handles for read/write.
@@ -11,8 +11,16 @@ pub trait TcpStack: Actor {
type SocketHandle: Copy;
fn connect(self, dst: IpAddress) -> Response<Self, TcpSocket<Self>>;
- fn write(self, buf: &[u8]) -> Response<Self, Result<usize, TcpError>>;
- fn read(self, buf: &mut [u8]) -> Response<Self, Result<usize, TcpError>>;
+ fn write(
+ self,
+ handle: Self::SocketHandle,
+ buf: &[u8],
+ ) -> Response<Self, Result<usize, TcpError>>;
+ fn read(
+ self,
+ handle: Self::SocketHandle,
+ buf: &mut [u8],
+ ) -> Response<Self, Result<usize, TcpError>>;
fn close(self, handle: Self::SocketHandle) -> Completion<Self>;
}
@@ -29,11 +37,11 @@ where
S: TcpStack + 'static,
{
async fn write(&mut self, buf: &[u8]) -> Result<usize, TcpError> {
- self.stack.request_panicking(Write(buf)).await
+ self.stack.request_panicking(Write(self.handle, buf)).await
}
async fn read(&mut self, buf: &mut [u8]) -> Result<usize, TcpError> {
- self.stack.request_panicking(Read(buf)).await
+ self.stack.request_panicking(Read(self.handle, buf)).await
}
fn close(self) {
@@ -54,29 +62,33 @@ where
}
}
-pub struct Write<'b>(&'b [u8]);
+pub struct Write<'b, S>(S::SocketHandle, &'b [u8])
+where
+ S: TcpStack;
-impl<'b, S> RequestHandler<Write<'b>> for S
+impl<'b, S> RequestHandler<Write<'b, S>> for S
where
S: TcpStack,
{
type Response = Result<usize, TcpError>;
- fn on_request(self, message: Write<'b>) -> Response<Self, Self::Response> {
- self.write(message.0)
+ fn on_request(self, message: Write<'b, S>) -> Response<Self, Self::Response> {
+ self.write(message.0, message.1)
}
}
-pub struct Read<'b>(&'b mut [u8]);
+pub struct Read<'b, S>(S::SocketHandle, &'b mut [u8])
+where
+ S: TcpStack;
-impl<'b, S> RequestHandler<Read<'b>> for S
+impl<'b, S> RequestHandler<Read<'b, S>> for S
where
S: TcpStack,
{
type Response = Result<usize, TcpError>;
- fn on_request(self, message: Read<'b>) -> Response<Self, Self::Response> {
- self.read(message.0)
+ fn on_request(self, message: Read<'b, S>) -> Response<Self, Self::Response> {
+ self.read(message.0, message.1)
}
}
