@@ -12,7 +12,7 @@ use compio_io::{
1212 AsyncRead , AsyncReadAt , AsyncReadManaged , AsyncReadManagedAt , AsyncWrite , AsyncWriteAt ,
1313 util:: Splittable ,
1414} ;
15- use compio_runtime:: { BorrowedBuffer , BufferPool , fd :: AsyncFd } ;
15+ use compio_runtime:: { BorrowedBuffer , BufferPool } ;
1616use widestring:: U16CString ;
1717use windows_sys:: Win32 :: {
1818 Storage :: FileSystem :: {
@@ -91,7 +91,7 @@ use crate::{File, OpenOptions};
9191/// [Windows named pipe]: https://docs.microsoft.com/en-us/windows/win32/ipc/named-pipes
9292#[ derive( Debug , Clone ) ]
9393pub struct NamedPipeServer {
94- handle : AsyncFd < std :: fs :: File > ,
94+ handle : File ,
9595}
9696
9797impl NamedPipeServer {
@@ -180,6 +180,14 @@ impl NamedPipeServer {
180180 syscall ! ( BOOL , DisconnectNamedPipe ( self . as_raw_fd( ) as _) ) ?;
181181 Ok ( ( ) )
182182 }
183+
184+ /// Close the server. If the returned future is dropped before polling, the
185+ /// server won't be closed.
186+ ///
187+ /// See [`File::close`] for more details.
188+ pub fn close ( self ) -> impl Future < Output = io:: Result < ( ) > > {
189+ self . handle . close ( )
190+ }
183191}
184192
185193impl AsyncRead for NamedPipeServer {
@@ -192,7 +200,7 @@ impl AsyncRead for NamedPipeServer {
192200impl AsyncRead for & NamedPipeServer {
193201 #[ inline]
194202 async fn read < B : IoBufMut > ( & mut self , buffer : B ) -> BufResult < usize , B > {
195- ( & self . handle ) . read ( buffer) . await
203+ self . handle . read_at ( buffer, 0 ) . await
196204 }
197205}
198206
@@ -219,7 +227,7 @@ impl AsyncReadManaged for &NamedPipeServer {
219227 len : usize ,
220228 ) -> io:: Result < Self :: Buffer < ' a > > {
221229 // The position is ignored.
222- ( & self . handle ) . read_managed ( buffer_pool, len) . await
230+ self . handle . read_managed_at ( buffer_pool, len, 0 ) . await
223231 }
224232}
225233
@@ -243,7 +251,7 @@ impl AsyncWrite for NamedPipeServer {
243251impl AsyncWrite for & NamedPipeServer {
244252 #[ inline]
245253 async fn write < T : IoBuf > ( & mut self , buffer : T ) -> BufResult < usize , T > {
246- ( & self . handle ) . write ( buffer) . await
254+ ( & self . handle ) . write_at ( buffer, 0 ) . await
247255 }
248256
249257 #[ inline]
@@ -344,6 +352,14 @@ impl NamedPipeClient {
344352 // SAFETY: we're ensuring the lifetime of the named pipe.
345353 unsafe { named_pipe_info ( self . as_raw_fd ( ) ) }
346354 }
355+
356+ /// Close the client. If the returned future is dropped before polling, the
357+ /// client won't be closed.
358+ ///
359+ /// See [`File::close`] for more details.
360+ pub fn close ( self ) -> impl Future < Output = io:: Result < ( ) > > {
361+ self . handle . close ( )
362+ }
347363}
348364
349365impl AsyncRead for NamedPipeClient {
@@ -1065,7 +1081,7 @@ impl ServerOptions {
10651081 ) ?;
10661082
10671083 Ok ( NamedPipeServer {
1068- handle : AsyncFd :: new ( unsafe { std:: fs:: File :: from_raw_handle ( h as _ ) } ) ?,
1084+ handle : File :: from_std ( unsafe { std:: fs:: File :: from_raw_handle ( h as _ ) } ) ?,
10691085 } )
10701086 }
10711087}
0 commit comments