@@ -6,14 +6,14 @@ use std::{
66
77use compio_buf:: { BufResult , IntoInner , IoBuf , IoBufMut , IoVectoredBuf , IoVectoredBufMut , buf_try} ;
88#[ cfg( unix) ]
9- use compio_driver:: op:: CreateSocket ;
9+ use compio_driver:: op:: { CreateSocket , ShutdownSocket } ;
1010use compio_driver:: {
1111 AsRawFd , OpCode , ToSharedFd , impl_raw_fd,
1212 op:: {
1313 Accept , BufResultExt , CloseSocket , Connect , Recv , RecvFrom , RecvFromManaged ,
1414 RecvFromVectored , RecvManaged , RecvMsg , RecvResultExt , RecvVectored , ResultTakeBuffer ,
1515 Send , SendMsg , SendMsgZc , SendTo , SendToVectored , SendToVectoredZc , SendToZc , SendVectored ,
16- SendVectoredZc , SendZc , ShutdownSocket , VecBufResultExt ,
16+ SendVectoredZc , SendZc , VecBufResultExt ,
1717 } ,
1818 syscall,
1919} ;
@@ -68,12 +68,7 @@ impl Socket {
6868
6969 #[ cfg( windows) ]
7070 pub async fn new ( domain : Domain , ty : Type , protocol : Option < Protocol > ) -> io:: Result < Self > {
71- use std:: panic:: resume_unwind;
72-
73- let socket = compio_runtime:: spawn_blocking ( move || Socket2 :: new ( domain, ty, protocol) )
74- . await
75- . unwrap_or_else ( |e| resume_unwind ( e) ) ?;
76- Self :: from_socket2 ( socket)
71+ Self :: from_socket2 ( Socket2 :: new ( domain, ty, protocol) ?)
7772 }
7873
7974 #[ cfg( unix) ]
@@ -121,16 +116,10 @@ impl Socket {
121116
122117 #[ cfg( windows) ]
123118 pub async fn accept ( & self ) -> io:: Result < ( Self , SockAddr ) > {
124- use std:: panic:: resume_unwind;
125-
126119 let domain = self . local_addr ( ) ?. domain ( ) ;
127- // We should allow users sending this accepted socket to a new thread.
128120 let ty = self . socket . r#type ( ) ?;
129121 let protocol = self . socket . protocol ( ) ?;
130- let accept_sock =
131- compio_runtime:: spawn_blocking ( move || Socket2 :: new ( domain, ty, protocol) )
132- . await
133- . unwrap_or_else ( |e| resume_unwind ( e) ) ?;
122+ let accept_sock = Socket2 :: new ( domain, ty, protocol) ?;
134123 let op = Accept :: new ( self . to_shared_fd ( ) , accept_sock) ;
135124 let ( _, op) = buf_try ! ( @try compio_runtime:: submit( op) . await ) ;
136125 op. update_context ( ) ?;
@@ -161,12 +150,19 @@ impl Socket {
161150 }
162151 }
163152
153+ #[ cfg( unix) ]
164154 pub async fn shutdown ( & self ) -> io:: Result < ( ) > {
165155 let op = ShutdownSocket :: new ( self . to_shared_fd ( ) , std:: net:: Shutdown :: Write ) ;
166156 compio_runtime:: submit ( op) . await . 0 ?;
167157 Ok ( ( ) )
168158 }
169159
160+ #[ cfg( windows) ]
161+ pub async fn shutdown ( & self ) -> io:: Result < ( ) > {
162+ self . socket . shutdown ( std:: net:: Shutdown :: Write ) ?;
163+ Ok ( ( ) )
164+ }
165+
170166 pub async fn recv < B : IoBufMut > ( & self , buffer : B , flags : i32 ) -> BufResult < usize , B > {
171167 let fd = self . to_shared_fd ( ) ;
172168 let op = Recv :: new ( fd, buffer, flags) ;
0 commit comments