Fix declarations in port.h to not be ambiguous in C due to K&R.

Also actually add the port parameter to grpc_recycle_unused_port.

Also remove the downsizing gpr_realloc in the recycle codepath, which is
unnecessary and can free the pointer.
pull/6589/head
David Klempner 9 years ago
parent 2ecb08f5a7
commit c7614cf277
  1. 6
      test/core/util/port.h
  2. 25
      test/core/util/port_posix.c
  3. 1
      test/core/util/port_windows.c

@ -40,16 +40,16 @@ extern "C" {
/* pick a port number that is currently unused by either tcp or udp. return /* pick a port number that is currently unused by either tcp or udp. return
0 on failure. */ 0 on failure. */
int grpc_pick_unused_port(); int grpc_pick_unused_port(void);
/* pick a port number that is currently unused by either tcp or udp. abort /* pick a port number that is currently unused by either tcp or udp. abort
on failure. */ on failure. */
int grpc_pick_unused_port_or_die(); int grpc_pick_unused_port_or_die(void);
/* Return a port which was previously returned by grpc_pick_unused_port(). /* Return a port which was previously returned by grpc_pick_unused_port().
* Implementations of grpc_pick_unused_port() backed by a portserver may limit * Implementations of grpc_pick_unused_port() backed by a portserver may limit
* the total number of ports available; this lets a binary return its allocated * the total number of ports available; this lets a binary return its allocated
* ports back to the server if it is going to allocate a large number. */ * ports back to the server if it is going to allocate a large number. */
void grpc_recycle_unused_port(); void grpc_recycle_unused_port(int port);
#ifdef __cplusplus #ifdef __cplusplus
} }

@ -73,21 +73,20 @@ static int free_chosen_port(int port) {
int found = 0; int found = 0;
size_t found_at = 0; size_t found_at = 0;
char *env = gpr_getenv("GRPC_TEST_PORT_SERVER"); char *env = gpr_getenv("GRPC_TEST_PORT_SERVER");
if (env != NULL) { /* Find the port and erase it from the list, then tell the server it can be
/* Find the port and erase it from the list, then tell the server it can be freed. */
freed. */ for (i = 0; i < num_chosen_ports; i++) {
for (i = 0; i < num_chosen_ports; i++) { if (chosen_ports[i] == port) {
if (chosen_ports[i] == port) { GPR_ASSERT(found == 0);
GPR_ASSERT(found == 0); found = 1;
found = 1; found_at = i;
found_at = i;
}
} }
if (found) { }
chosen_ports[found_at] = chosen_ports[num_chosen_ports - 1]; if (found) {
chosen_ports[found_at] = chosen_ports[num_chosen_ports - 1];
num_chosen_ports--;
if (env) {
grpc_free_port_using_server(env, port); grpc_free_port_using_server(env, port);
num_chosen_ports--;
chosen_ports = gpr_realloc(chosen_ports, sizeof(int) * num_chosen_ports);
} }
} }
return found; return found;

@ -90,7 +90,6 @@ static int free_chosen_port(int port) {
chosen_ports[found_at] = chosen_ports[num_chosen_ports - 1]; chosen_ports[found_at] = chosen_ports[num_chosen_ports - 1];
grpc_free_port_using_server(env, port); grpc_free_port_using_server(env, port);
num_chosen_ports--; num_chosen_ports--;
chosen_ports = gpr_realloc(chosen_ports, sizeof(int) * num_chosen_ports);
} }
} }
return found; return found;

Loading…
Cancel
Save