File tree Expand file tree Collapse file tree 1 file changed +4
-7
lines changed Expand file tree Collapse file tree 1 file changed +4
-7
lines changed Original file line number Diff line number Diff line change @@ -79,18 +79,17 @@ impl UdpSocket {
79
79
/// Rebind the underlying socket.
80
80
pub fn rebind ( & self ) -> Result < ( ) > {
81
81
// Remove old socket
82
+ let mut guard = self . socket . write ( ) . unwrap ( ) ;
82
83
{
83
- let mut guard = self . socket . write ( ) . unwrap ( ) ;
84
84
let socket = guard. take ( ) . expect ( "not yet dropped" ) ;
85
-
86
85
drop ( socket) ;
87
86
}
88
87
89
88
// Prepare new socket
90
89
let new_socket = inner_bind ( self . addr ) ?;
91
90
92
91
// Insert new socket
93
- self . socket . write ( ) . unwrap ( ) . replace ( new_socket) ;
92
+ guard . replace ( new_socket) ;
94
93
95
94
// Clear errors
96
95
self . is_broken
@@ -102,10 +101,8 @@ impl UdpSocket {
102
101
fn bind_raw ( addr : impl Into < SocketAddr > ) -> Result < Self > {
103
102
let mut addr = addr. into ( ) ;
104
103
let socket = inner_bind ( addr) ?;
105
- if addr. port ( ) == 0 {
106
- // update to use selected port
107
- addr. set_port ( socket. local_addr ( ) ?. port ( ) ) ;
108
- }
104
+ // update to use selected port
105
+ addr. set_port ( socket. local_addr ( ) ?. port ( ) ) ;
109
106
110
107
Ok ( UdpSocket {
111
108
socket : Arc :: new ( RwLock :: new ( Some ( socket) ) ) ,
You can’t perform that action at this time.
0 commit comments