@@ -15,7 +15,6 @@ use idl2json::{idl2json, Idl2JsonOptions};
15
15
use num_traits:: FromPrimitive ;
16
16
use reqwest:: { Client , StatusCode , Url } ;
17
17
use rust_decimal:: Decimal ;
18
- use socket2:: { Domain , Socket } ;
19
18
use std:: collections:: BTreeMap ;
20
19
use std:: io:: { stderr, stdin, stdout, IsTerminal , Read } ;
21
20
use std:: net:: { IpAddr , SocketAddr , TcpListener } ;
@@ -35,22 +34,8 @@ const DECIMAL_POINT: char = '.';
35
34
// thus, we need to recreate SocketAddr with the kernel-provided dynamically allocated port here.
36
35
#[ context( "Failed to find available socket address" ) ]
37
36
pub fn get_reusable_socket_addr ( ip : IpAddr , port : u16 ) -> DfxResult < SocketAddr > {
38
- let socket = if ip. is_ipv4 ( ) {
39
- Socket :: new ( Domain :: IPV4 , socket2:: Type :: STREAM , None )
40
- . context ( "Failed to create IPv4 socket." ) ?
41
- } else {
42
- Socket :: new ( Domain :: IPV6 , socket2:: Type :: STREAM , None )
43
- . context ( "Failed to create IPv6 socket." ) ?
44
- } ;
45
- socket
46
- . set_linger ( Some ( Duration :: from_secs ( 10 ) ) )
47
- . context ( "Failed to set linger duration of tcp listener." ) ?;
48
- socket
49
- . bind ( & SocketAddr :: new ( ip, port) . into ( ) )
37
+ let listener = TcpListener :: bind ( SocketAddr :: new ( ip, port) )
50
38
. with_context ( || format ! ( "Failed to bind socket to {}:{}." , ip, port) ) ?;
51
- socket. listen ( 128 ) . context ( "Failed to listen on socket." ) ?;
52
-
53
- let listener: TcpListener = socket. into ( ) ;
54
39
listener
55
40
. local_addr ( )
56
41
. context ( "Failed to fetch local address." )
0 commit comments