11use std:: ops:: DerefMut ;
22use std:: pin:: Pin ;
3+ #[ cfg( unix) ]
4+ use std:: sync:: Arc ;
35use std:: task:: { Context , Poll } ;
46
57use futures:: { Sink , SinkExt , Stream , StreamExt , ready} ;
3032 let ( new_stream_sender, new_stream_receiver) = mpsc:: unbounded_channel ( ) ;
3133 let ( new_sink_sender, new_sink_receiver) = mpsc:: unbounded_channel ( ) ;
3234
35+ #[ cfg_attr(
36+ not( unix) ,
37+ expect( unused_variables, reason = "dir is only used on non-Unix" )
38+ ) ]
3339 let dir = match * bound_server {
3440 #[ cfg( unix) ]
3541 BoundServer :: UnixSocket ( listener, dir) => {
@@ -76,18 +82,32 @@ impl<
7682 }
7783 } ) ;
7884
79- None
85+ #[ cfg( unix) ]
86+ {
87+ None
88+ }
89+
90+ #[ cfg( not( unix) ) ]
91+ {
92+ None :: < ( ) >
93+ }
8094 }
8195 _ => panic ! ( "SingleConnection only supports UnixSocket and TcpPort" ) ,
8296 } ;
8397
98+ #[ cfg( unix) ]
99+ let dir_holder_arc = dir. map ( Arc :: new) ;
100+
84101 let source = SingleConnectionSource {
85102 new_stream_receiver,
86- _dir_holder : dir,
103+ #[ cfg( unix) ]
104+ _dir_holder : dir_holder_arc. clone ( ) ,
87105 active_stream : None ,
88106 } ;
89107
90108 let sink = SingleConnectionSink :: < O , C > {
109+ #[ cfg( unix) ]
110+ _dir_holder : dir_holder_arc,
91111 connection_sink : None ,
92112 new_sink_receiver,
93113 } ;
@@ -106,12 +126,14 @@ type DynEncodedSink<O, C> = Pin<Box<dyn Sink<O, Error = <C as Encoder<O>>::Error
106126pub struct SingleConnectionSource < I , C : Decoder < Item = I > > {
107127 new_stream_receiver : mpsc:: UnboundedReceiver < DynDecodedStream < I , C > > ,
108128 #[ cfg( unix) ]
109- _dir_holder : Option < TempDir > , // keeps the folder containing the socket alive
129+ _dir_holder : Option < Arc < TempDir > > , // keeps the folder containing the socket alive
110130 /// The active stream for the single connection, if taken
111131 active_stream : Option < DynDecodedStream < I , C > > ,
112132}
113133
114134pub struct SingleConnectionSink < O , C : Encoder < O > > {
135+ #[ cfg( unix) ]
136+ _dir_holder : Option < Arc < TempDir > > , // keeps the folder containing the socket alive
115137 connection_sink : Option < DynEncodedSink < O , C > > ,
116138 new_sink_receiver : mpsc:: UnboundedReceiver < DynEncodedSink < O , C > > ,
117139}
0 commit comments