1+ use crate :: handle:: Handle ;
2+ use crate :: submission_handler:: SubmissionHandler ;
3+ use futures:: io:: { AsyncRead , AsyncWrite } ;
4+ use std:: fs:: File ;
5+ use std:: io:: Read ;
6+ use std:: mem:: ManuallyDrop ;
7+ use std:: net:: TcpStream ;
8+ use std:: time:: Duration ;
9+ use std:: { io, task} ;
10+ use std:: { pin:: Pin , task:: Context , task:: Poll } ;
11+
112pub struct SysProactor { }
213
314impl SysProactor {
@@ -7,8 +18,8 @@ impl SysProactor {
718 }
819
920 /// Wakes the thread waiting on proactor.
10- pub fn wake ( & self ) {
11- todo ! ( ) ;
21+ pub fn wake ( & self ) -> io :: Result < ( ) > {
22+ Ok ( ( ) )
1223 }
1324
1425 /// Wait for completion of IO object
@@ -21,3 +32,127 @@ impl SysProactor {
2132 todo ! ( ) ;
2233 }
2334}
35+
36+ ///////////////////////////////////
37+ ///// File
38+ ///////////////////////////////////
39+
40+ #[ cfg( windows) ]
41+ impl AsyncRead for & Handle < File > {
42+ fn poll_read (
43+ self : Pin < & mut Self > ,
44+ cx : & mut task:: Context < ' _ > ,
45+ buf : & mut [ u8 ] ,
46+ ) -> Poll < io:: Result < usize > > {
47+ todo ! ( ) ;
48+ // let raw_fd = self.as_raw_fd();
49+ // let buf_len = buf.len();
50+ // let buf = buf.as_mut_ptr();
51+
52+ // let completion_dispatcher = async move {
53+ // let file = unsafe { File::from_raw_fd(raw_fd) };
54+
55+ // let buf = unsafe { std::slice::from_raw_parts_mut(buf, buf_len) };
56+ // let size = Processor::processor_read_file(&file, buf).await?;
57+
58+ // let _ = ManuallyDrop::new(file);
59+ // Ok(size)
60+ // };
61+
62+ // SubmissionHandler::<Self>::handle_read(self, cx, completion_dispatcher)
63+ }
64+ }
65+
66+ #[ cfg( windows) ]
67+ impl AsyncWrite for & Handle < File > {
68+ fn poll_write (
69+ self : Pin < & mut Self > ,
70+ cx : & mut Context < ' _ > ,
71+ buf : & [ u8 ] ,
72+ ) -> Poll < io:: Result < usize > > {
73+ todo ! ( ) ;
74+ // let raw_fd = self.as_raw_fd();
75+ // let buf_len = buf.len();
76+ // let buf = buf.as_ptr();
77+
78+ // let completion_dispatcher = async move {
79+ // let file = unsafe { File::from_raw_fd(raw_fd) };
80+
81+ // let buf = unsafe { std::slice::from_raw_parts(buf, buf_len) };
82+ // let size = Processor::processor_write_file(&file, buf).await?;
83+
84+ // let _ = ManuallyDrop::new(file);
85+ // Ok(size)
86+ // };
87+
88+ // SubmissionHandler::<Self>::handle_write(self, cx, completion_dispatcher)
89+ }
90+
91+ fn poll_flush ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < io:: Result < ( ) > > {
92+ Poll :: Ready ( Ok ( ( ) ) )
93+ }
94+
95+ fn poll_close ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < io:: Result < ( ) > > {
96+ Poll :: Ready ( Ok ( ( ) ) )
97+ }
98+ }
99+
100+ ///////////////////////////////////
101+ ///// TcpStream
102+ ///////////////////////////////////
103+
104+ #[ cfg( windows) ]
105+ impl AsyncRead for & Handle < TcpStream > {
106+ fn poll_read (
107+ self : Pin < & mut Self > ,
108+ cx : & mut task:: Context < ' _ > ,
109+ buf : & mut [ u8 ] ,
110+ ) -> Poll < io:: Result < usize > > {
111+ todo ! ( ) ;
112+ // let raw_fd = self.as_raw_fd();
113+ // let buf_len = buf.len();
114+ // let buf = buf.as_mut_ptr();
115+
116+ // let completion_dispatcher = async move {
117+ // let sock = unsafe { TcpStream::from_raw_fd(raw_fd) };
118+
119+ // let buf = unsafe { std::slice::from_raw_parts_mut(buf, buf_len) };
120+ // let size = Processor::processor_recv(&sock, buf).await?;
121+
122+ // let _ = ManuallyDrop::new(sock);
123+ // Ok(size)
124+ // };
125+
126+ // SubmissionHandler::<Self>::handle_read(self, cx, completion_dispatcher)
127+ }
128+ }
129+
130+ #[ cfg( windows) ]
131+ impl AsyncWrite for & Handle < TcpStream > {
132+ fn poll_write ( self : Pin < & mut Self > , cx : & mut Context , buf : & [ u8 ] ) -> Poll < io:: Result < usize > > {
133+ todo ! ( ) ;
134+ // let raw_fd = self.as_raw_fd();
135+ // let buf_len = buf.len();
136+ // let buf = buf.as_ptr();
137+
138+ // let completion_dispatcher = async move {
139+ // let sock = unsafe { TcpStream::from_raw_fd(raw_fd) };
140+
141+ // let buf = unsafe { std::slice::from_raw_parts(buf, buf_len) };
142+ // let size = Processor::processor_send(&sock, buf).await?;
143+
144+ // let _ = ManuallyDrop::new(sock);
145+ // Ok(size)
146+ // };
147+
148+ // SubmissionHandler::<Self>::handle_write(self, cx, completion_dispatcher)
149+ }
150+
151+ fn poll_flush ( self : Pin < & mut Self > , _cx : & mut Context ) -> Poll < io:: Result < ( ) > > {
152+ Poll :: Ready ( Ok ( ( ) ) )
153+ }
154+
155+ fn poll_close ( self : Pin < & mut Self > , _cx : & mut Context ) -> Poll < io:: Result < ( ) > > {
156+ Poll :: Ready ( Ok ( ( ) ) )
157+ }
158+ }
0 commit comments