@@ -2,6 +2,7 @@ use std::{
22 future:: Future ,
33 io,
44 net:: SocketAddr ,
5+ num:: NonZeroUsize ,
56 pin:: Pin ,
67 sync:: { Arc , RwLock , RwLockReadGuard , TryLockError , atomic:: AtomicBool } ,
78 task:: { Context , Poll } ,
@@ -463,7 +464,7 @@ impl UdpSocket {
463464 ///
464465 /// This is 1 if the platform doesn't support GSO. Subject to change if errors are detected
465466 /// while using GSO.
466- pub fn max_gso_segments ( & self ) -> usize {
467+ pub fn max_gso_segments ( & self ) -> NonZeroUsize {
467468 let guard = self . socket . read ( ) . unwrap ( ) ;
468469 guard. max_gso_segments ( )
469470 }
@@ -472,7 +473,7 @@ impl UdpSocket {
472473 /// compute the receive buffer size.
473474 ///
474475 /// Returns 1 if the platform doesn't support GRO.
475- pub fn gro_segments ( & self ) -> usize {
476+ pub fn gro_segments ( & self ) -> NonZeroUsize {
476477 let guard = self . socket . read ( ) . unwrap ( ) ;
477478 guard. gro_segments ( )
478479 }
@@ -687,8 +688,8 @@ enum SocketState {
687688 addr : SocketAddr ,
688689 } ,
689690 Closed {
690- last_max_gso_segments : usize ,
691- last_gro_segments : usize ,
691+ last_max_gso_segments : NonZeroUsize ,
692+ last_gro_segments : NonZeroUsize ,
692693 last_may_fragment : bool ,
693694 } ,
694695}
@@ -818,7 +819,7 @@ impl SocketState {
818819 }
819820 }
820821
821- fn max_gso_segments ( & self ) -> usize {
822+ fn max_gso_segments ( & self ) -> NonZeroUsize {
822823 match self {
823824 Self :: Connected { state, .. } => state. max_gso_segments ( ) ,
824825 Self :: Closed {
@@ -828,7 +829,7 @@ impl SocketState {
828829 }
829830 }
830831
831- fn gro_segments ( & self ) -> usize {
832+ fn gro_segments ( & self ) -> NonZeroUsize {
832833 match self {
833834 Self :: Connected { state, .. } => state. gro_segments ( ) ,
834835 Self :: Closed {
@@ -840,7 +841,6 @@ impl SocketState {
840841
841842impl Drop for UdpSocket {
842843 fn drop ( & mut self ) {
843- trace ! ( "dropping UdpSocket" ) ;
844844 if let Some ( ( socket, _) ) = self . socket . write ( ) . unwrap ( ) . close ( ) {
845845 if let Ok ( handle) = tokio:: runtime:: Handle :: try_current ( ) {
846846 // No wakeup after dropping write lock here, since we're getting dropped.
0 commit comments