@@ -58,18 +58,8 @@ struct ListenTask {
5858 listener : Arc < TcpListener > ,
5959 family : SocketAddressFamily ,
6060 tx : StreamWriter < Option < Resource < TcpSocket > > > ,
61-
62- // The socket options below are not automatically inherited from the listener
63- // on all platforms. So we keep track of which options have been explicitly
64- // set and manually apply those values to newly accepted clients.
65- #[ cfg( target_os = "macos" ) ]
66- receive_buffer_size : Arc < core:: sync:: atomic:: AtomicUsize > ,
67- #[ cfg( target_os = "macos" ) ]
68- send_buffer_size : Arc < core:: sync:: atomic:: AtomicUsize > ,
6961 #[ cfg( target_os = "macos" ) ]
70- hop_limit : Arc < core:: sync:: atomic:: AtomicU8 > ,
71- #[ cfg( target_os = "macos" ) ]
72- keep_alive_idle_time : Arc < core:: sync:: atomic:: AtomicU64 > , // nanoseconds
62+ options : Arc < crate :: p3:: sockets:: tcp:: NonInheritedOptions > ,
7363}
7464
7565impl < T > AccessorTask < T , WasiSockets , wasmtime:: Result < ( ) > > for ListenTask {
@@ -95,6 +85,7 @@ impl<T> AccessorTask<T, WasiSockets, wasmtime::Result<()>> for ListenTask {
9585 // and only if a specific value was explicitly set on the listener.
9686
9787 let receive_buffer_size = self
88+ . options
9889 . receive_buffer_size
9990 . load ( core:: sync:: atomic:: Ordering :: Relaxed ) ;
10091 if receive_buffer_size > 0 {
@@ -106,6 +97,7 @@ impl<T> AccessorTask<T, WasiSockets, wasmtime::Result<()>> for ListenTask {
10697 }
10798
10899 let send_buffer_size = self
100+ . options
109101 . send_buffer_size
110102 . load ( core:: sync:: atomic:: Ordering :: Relaxed ) ;
111103 if send_buffer_size > 0 {
@@ -118,8 +110,10 @@ impl<T> AccessorTask<T, WasiSockets, wasmtime::Result<()>> for ListenTask {
118110
119111 // For some reason, IP_TTL is inherited, but IPV6_UNICAST_HOPS isn't.
120112 if self . family == SocketAddressFamily :: Ipv6 {
121- let hop_limit =
122- self . hop_limit . load ( core:: sync:: atomic:: Ordering :: Relaxed ) ;
113+ let hop_limit = self
114+ . options
115+ . hop_limit
116+ . load ( core:: sync:: atomic:: Ordering :: Relaxed ) ;
123117 if hop_limit > 0 {
124118 // Ignore potential error.
125119 _ = rustix:: net:: sockopt:: set_ipv6_unicast_hops (
@@ -130,6 +124,7 @@ impl<T> AccessorTask<T, WasiSockets, wasmtime::Result<()>> for ListenTask {
130124 }
131125
132126 let keep_alive_idle_time = self
127+ . options
133128 . keep_alive_idle_time
134129 . load ( core:: sync:: atomic:: Ordering :: Relaxed ) ;
135130 if keep_alive_idle_time > 0 {
@@ -331,13 +326,7 @@ impl HostTcpSocketConcurrent for WasiSockets {
331326 listen_backlog_size,
332327 family,
333328 #[ cfg( target_os = "macos" ) ]
334- receive_buffer_size,
335- #[ cfg ( target_os = "macos" ) ]
336- send_buffer_size,
337- #[ cfg ( target_os = "macos" ) ]
338- hop_limit,
339- #[ cfg ( target_os = "macos" ) ]
340- keep_alive_idle_time,
329+ options,
341330 } = get_socket_mut ( view. get ( ) . table , & socket) ?;
342331 let sock = match mem:: replace ( tcp_state, TcpState :: Closed ) {
343332 TcpState :: Default ( sock) | TcpState :: Bound ( sock) => sock,
@@ -373,13 +362,7 @@ impl HostTcpSocketConcurrent for WasiSockets {
373362 family : * family,
374363 tx,
375364 #[ cfg( target_os = "macos" ) ]
376- receive_buffer_size : Arc :: clone ( & receive_buffer_size) ,
377- #[ cfg( target_os = "macos" ) ]
378- send_buffer_size : Arc :: clone ( & send_buffer_size) ,
379- #[ cfg( target_os = "macos" ) ]
380- hop_limit : Arc :: clone ( & hop_limit) ,
381- #[ cfg( target_os = "macos" ) ]
382- keep_alive_idle_time : Arc :: clone ( & keep_alive_idle_time) ,
365+ options : Arc :: clone ( & options) ,
383366 } ;
384367 view. spawn ( task) ;
385368 Ok ( Ok ( rx. into ( ) ) )
0 commit comments