|
|
@ -113,15 +113,22 @@ int grpc_pick_unused_port(void) { |
|
|
|
|
|
|
|
|
|
|
|
/* Type of port to first pick in next iteration */ |
|
|
|
/* Type of port to first pick in next iteration */ |
|
|
|
int is_tcp = 1; |
|
|
|
int is_tcp = 1; |
|
|
|
int try |
|
|
|
int try = 0; |
|
|
|
= 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (;;) { |
|
|
|
for (;;) { |
|
|
|
int port = try |
|
|
|
int port; |
|
|
|
< NUM_RANDOM_PORTS_TO_PICK ? rand() % (65536 - 30000) + 30000 : 0; |
|
|
|
if (try == 0) { |
|
|
|
|
|
|
|
port = getpid() % (65536 - 30000) + 30000; |
|
|
|
|
|
|
|
} else if (try < NUM_RANDOM_PORTS_TO_PICK) { |
|
|
|
|
|
|
|
port = rand() % (65536 - 30000) + 30000; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
port = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!is_port_available(&port, is_tcp)) { |
|
|
|
if (!is_port_available(&port, is_tcp)) { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
GPR_ASSERT(port > 0); |
|
|
|
GPR_ASSERT(port > 0); |
|
|
|
/* Check that the port # is free for the other type of socket also */ |
|
|
|
/* Check that the port # is free for the other type of socket also */ |
|
|
|
if (!is_port_available(&port, !is_tcp)) { |
|
|
|
if (!is_port_available(&port, !is_tcp)) { |
|
|
|