22
33use bytes:: BytesMut ;
44use std:: {
5- fmt:: Debug , io, marker:: PhantomData , mem:: size_of, pin:: Pin , task:: { Context , Poll }
5+ fmt:: Debug ,
6+ io,
7+ marker:: PhantomData ,
8+ mem:: size_of,
9+ pin:: Pin ,
10+ task:: { Context , Poll } ,
611} ;
712
813use futures:: { Sink , Stream } ;
@@ -13,8 +18,8 @@ use crate::{
1318 sys:: { AsyncSocket , SocketAddr } ,
1419} ;
1520use netlink_packet_core:: {
16- NetlinkDeserializable , NetlinkMessage , NetlinkSerializable , NetlinkHeader ,
17- NLMSG_OVERRUN , NetlinkPayload ,
21+ NetlinkDeserializable , NetlinkHeader , NetlinkMessage , NetlinkPayload ,
22+ NetlinkSerializable , NLMSG_OVERRUN ,
1823} ;
1924
2025/// Buffer overrun condition
@@ -68,24 +73,28 @@ where
6873
6974 * in_addr = match ready ! ( socket. poll_recv_from( cx, reader) ) {
7075 Ok ( addr) => addr,
71- // When receiving messages in multicast mode (i.e. we subscribed to
72- // notifications), the kernel will not wait for us to read datagrams before
73- // sending more. The receive buffer has a finite size, so once it is full (no
74- // more message can fit in), new messages will be dropped and recv calls will
75- // return `ENOBUFS`.
76- // This needs to be handled for applications to resynchronize with the contents
77- // of the kernel if necessary.
76+ // When receiving messages in multicast mode (i.e. we subscribed
77+ // to notifications), the kernel will not wait
78+ // for us to read datagrams before sending more.
79+ // The receive buffer has a finite size, so once it is full (no
80+ // more message can fit in), new messages will be dropped and
81+ // recv calls will return `ENOBUFS`.
82+ // This needs to be handled for applications to resynchronize
83+ // with the contents of the kernel if necessary.
7884 // We don't need to do anything special:
79- // - contents of the reader is still valid because we won't have partial messages
80- // in there anyways (large enough buffer)
81- // - contents of the socket's internal buffer is still valid because the kernel
82- // won't put partial data in it
85+ // - contents of the reader is still valid because we won't have
86+ // partial messages in there anyways (large enough buffer)
87+ // - contents of the socket's internal buffer is still valid
88+ // because the kernel won't put partial data in it
8389 Err ( e) if e. raw_os_error ( ) == Some ( ENOBUFS ) => {
8490 warn ! ( "netlink socket buffer full" ) ;
8591 let mut hdr = NetlinkHeader :: default ( ) ;
8692 hdr. length = size_of :: < NetlinkHeader > ( ) as u32 ;
8793 hdr. message_type = NLMSG_OVERRUN ;
88- let msg = NetlinkMessage :: new ( hdr, NetlinkPayload :: Overrun ( Vec :: new ( ) ) ) ;
94+ let msg = NetlinkMessage :: new (
95+ hdr,
96+ NetlinkPayload :: Overrun ( Vec :: new ( ) ) ,
97+ ) ;
8998 return Poll :: Ready ( Some ( ( msg, SocketAddr :: new ( 0 , 0 ) ) ) ) ;
9099 }
91100 Err ( e) => {
0 commit comments