@@ -24,6 +24,42 @@ pub struct Socket {
2424
2525impl Socket {
2626 pub fn from_socket2 ( socket : Socket2 ) -> io:: Result < Self > {
27+ #[ cfg( unix) ]
28+ {
29+ #[ cfg( not( any(
30+ target_os = "android" ,
31+ target_os = "dragonfly" ,
32+ target_os = "freebsd" ,
33+ target_os = "fuchsia" ,
34+ target_os = "hurd" ,
35+ target_os = "illumos" ,
36+ target_os = "linux" ,
37+ target_os = "netbsd" ,
38+ target_os = "openbsd" ,
39+ target_os = "espidf" ,
40+ target_os = "vita" ,
41+ ) ) ) ]
42+ socket. set_cloexec ( true ) ?;
43+ #[ cfg( any(
44+ target_os = "ios" ,
45+ target_os = "macos" ,
46+ target_os = "tvos" ,
47+ target_os = "watchos" ,
48+ ) ) ]
49+ socket. set_nosigpipe ( true ) ?;
50+ // On Linux we use blocking socket
51+ // Newer kernels have the patch that allows to arm io_uring poll mechanism for
52+ // non blocking socket when there is no connections in listen queue
53+ //
54+ // https://patchwork.kernel.org/project/linux-block/patch/[email protected] /#22949861 55+ if cfg ! ( all(
56+ unix,
57+ not( all( target_os = "linux" , feature = "io-uring" ) )
58+ ) ) {
59+ socket. set_nonblocking ( true ) ?;
60+ }
61+ }
62+
2763 Ok ( Self {
2864 socket : Attacher :: new ( socket) ?,
2965 } )
@@ -83,38 +119,7 @@ impl Socket {
83119 ) ;
84120 let BufResult ( res, _) = compio_runtime:: submit ( op) . await ;
85121 let socket = unsafe { Socket2 :: from_raw_fd ( res? as _ ) } ;
86- #[ cfg( not( any(
87- target_os = "android" ,
88- target_os = "dragonfly" ,
89- target_os = "freebsd" ,
90- target_os = "fuchsia" ,
91- target_os = "hurd" ,
92- target_os = "illumos" ,
93- target_os = "linux" ,
94- target_os = "netbsd" ,
95- target_os = "openbsd" ,
96- target_os = "espidf" ,
97- target_os = "vita" ,
98- ) ) ) ]
99- socket. set_cloexec ( true ) ?;
100- #[ cfg( any(
101- target_os = "ios" ,
102- target_os = "macos" ,
103- target_os = "tvos" ,
104- target_os = "watchos" ,
105- ) ) ]
106- socket. set_nosigpipe ( true ) ?;
107- // On Linux we use blocking socket
108- // Newer kernels have the patch that allows to arm io_uring poll mechanism for
109- // non blocking socket when there is no connections in listen queue
110- //
111- // https://patchwork.kernel.org/project/linux-block/patch/[email protected] /#22949861 112- if cfg ! ( all(
113- unix,
114- not( all( target_os = "linux" , feature = "io-uring" ) )
115- ) ) {
116- socket. set_nonblocking ( true ) ?;
117- }
122+
118123 Self :: from_socket2 ( socket)
119124 }
120125
0 commit comments