@@ -78,11 +78,13 @@ impl TcpListenerRunner {
7878 Runner :: new ( async move {
7979 let notify = Arc :: new ( Notify :: new ( ) ) ;
8080 let ( socket_tx, socket_rx) = unbounded_channel :: < TcpSocketCreation > ( ) ;
81- tokio:: select! {
82- _ = Self :: handle_packet( notify. clone( ) , iface_ingress_tx, iface_ingress_tx_avail. clone( ) , tcp_rx, stream_tx, socket_tx) => { }
83- _ = Self :: handle_socket( notify, device, iface, iface_ingress_tx_avail, sockets, socket_rx) => { }
84- }
81+ let res = tokio:: select! {
82+ v = Self :: handle_packet( notify. clone( ) , iface_ingress_tx, iface_ingress_tx_avail. clone( ) , tcp_rx, stream_tx, socket_tx) => v,
83+ v = Self :: handle_socket( notify, device, iface, iface_ingress_tx_avail, sockets, socket_rx) => v,
84+ } ;
85+ res?;
8586 trace ! ( "VirtDevice::poll thread exited" ) ;
87+ Ok ( ( ) )
8688 } )
8789 }
8890
@@ -93,7 +95,7 @@ impl TcpListenerRunner {
9395 mut tcp_rx : Receiver < AnyIpPktFrame > ,
9496 stream_tx : UnboundedSender < TcpStream > ,
9597 socket_tx : UnboundedSender < TcpSocketCreation > ,
96- ) {
98+ ) -> std :: io :: Result < ( ) > {
9799 while let Some ( frame) = tcp_rx. recv ( ) . await {
98100 let packet = match IpPacket :: new_checked ( frame. as_slice ( ) ) {
99101 Ok ( p) => p,
@@ -107,7 +109,7 @@ impl TcpListenerRunner {
107109 if matches ! ( packet. protocol( ) , IpProtocol :: Icmp | IpProtocol :: Icmpv6 ) {
108110 iface_ingress_tx
109111 . send ( frame)
110- . expect ( "channel already closed" ) ;
112+ . map_err ( |e| std :: io :: Error :: new ( std :: io :: ErrorKind :: BrokenPipe , e ) ) ? ;
111113 iface_ingress_tx_avail. store ( true , Ordering :: Release ) ;
112114 notify. notify_one ( ) ;
113115 continue ;
@@ -165,19 +167,20 @@ impl TcpListenerRunner {
165167 notify : notify. clone ( ) ,
166168 control : control. clone ( ) ,
167169 } )
168- . expect ( "channel already closed" ) ;
170+ . map_err ( |e| std :: io :: Error :: new ( std :: io :: ErrorKind :: BrokenPipe , e ) ) ? ;
169171 socket_tx
170172 . send ( TcpSocketCreation { control, socket } )
171- . expect ( "channel already closed" ) ;
173+ . map_err ( |e| std :: io :: Error :: new ( std :: io :: ErrorKind :: BrokenPipe , e ) ) ? ;
172174 }
173175
174176 // Pipeline tcp stream packet
175177 iface_ingress_tx
176178 . send ( frame)
177- . expect ( "channel already closed" ) ;
179+ . map_err ( |e| std :: io :: Error :: new ( std :: io :: ErrorKind :: BrokenPipe , e ) ) ? ;
178180 iface_ingress_tx_avail. store ( true , Ordering :: Release ) ;
179181 notify. notify_one ( ) ;
180182 }
183+ Ok ( ( ) )
181184 }
182185
183186 async fn handle_socket (
@@ -187,7 +190,7 @@ impl TcpListenerRunner {
187190 iface_ingress_tx_avail : Arc < AtomicBool > ,
188191 mut sockets : HashMap < SocketHandle , SharedControl > ,
189192 mut socket_rx : UnboundedReceiver < TcpSocketCreation > ,
190- ) {
193+ ) -> std :: io :: Result < ( ) > {
191194 let mut socket_set = SocketSet :: new ( vec ! [ ] ) ;
192195 loop {
193196 while let Ok ( TcpSocketCreation { control, socket } ) = socket_rx. try_recv ( ) {
@@ -354,9 +357,9 @@ impl TcpListener {
354357 pub ( super ) fn new (
355358 tcp_rx : Receiver < AnyIpPktFrame > ,
356359 stack_tx : Sender < AnyIpPktFrame > ,
357- ) -> ( Runner , Self ) {
360+ ) -> std :: io :: Result < ( Runner , Self ) > {
358361 let ( mut device, iface_ingress_tx, iface_ingress_tx_avail) = VirtualDevice :: new ( stack_tx) ;
359- let iface = Self :: create_interface ( & mut device) ;
362+ let iface = Self :: create_interface ( & mut device) ? ;
360363
361364 let ( stream_tx, stream_rx) = unbounded_channel ( ) ;
362365
@@ -370,10 +373,10 @@ impl TcpListener {
370373 HashMap :: new ( ) ,
371374 ) ;
372375
373- ( runner, Self { stream_rx } )
376+ Ok ( ( runner, Self { stream_rx } ) )
374377 }
375378
376- fn create_interface < D > ( device : & mut D ) -> Interface
379+ fn create_interface < D > ( device : & mut D ) -> std :: io :: Result < Interface >
377380 where
378381 D : Device + ?Sized ,
379382 {
@@ -391,13 +394,13 @@ impl TcpListener {
391394 iface
392395 . routes_mut ( )
393396 . add_default_ipv4_route ( Ipv4Address :: new ( 0 , 0 , 0 , 1 ) )
394- . expect ( "IPv4 default route" ) ;
397+ . map_err ( |e| std :: io :: Error :: new ( std :: io :: ErrorKind :: AddrNotAvailable , e ) ) ? ;
395398 iface
396399 . routes_mut ( )
397400 . add_default_ipv6_route ( Ipv6Address :: new ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ) )
398- . expect ( "IPv6 default route" ) ;
401+ . map_err ( |e| std :: io :: Error :: new ( std :: io :: ErrorKind :: AddrNotAvailable , e ) ) ? ;
399402 iface. set_any_ip ( true ) ;
400- iface
403+ Ok ( iface)
401404 }
402405}
403406
0 commit comments