diff options
author | Craig Tiller <craig.tiller@gmail.com> | 2015-04-08 16:13:58 -0700 |
---|---|---|
committer | Craig Tiller <craig.tiller@gmail.com> | 2015-04-08 16:13:58 -0700 |
commit | f7262057e6fff03544311cd95ea584218062e2ab (patch) | |
tree | 37088b46d1e53da95747d48c5245592b4c1843fc /test | |
parent | b8fce7f628948d0a3f26b0b779f270600392aa27 (diff) |
Port port_posix to port_windows.
Diffstat (limited to 'test')
-rw-r--r-- | test/core/util/port_windows.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/test/core/util/port_windows.c b/test/core/util/port_windows.c index 279aa2d21b..17058c3353 100644 --- a/test/core/util/port_windows.c +++ b/test/core/util/port_windows.c @@ -35,14 +35,13 @@ #include "test/core/util/test_config.h" #if defined(GPR_WINSOCK_SOCKET) && defined(GRPC_TEST_PICK_PORT) +#include "src/core/iomgr/sockaddr_utils.h" #include "test/core/util/port.h" -#include <netinet/in.h> -#include <sys/socket.h> +#include <process.h> #include <stdio.h> #include <errno.h> #include <string.h> -#include <unistd.h> #include <grpc/support/log.h> @@ -50,7 +49,7 @@ static int is_port_available(int *port, int is_tcp) { const int proto = is_tcp ? IPPROTO_TCP : 0; - const int fd = socket(AF_INET, is_tcp ? SOCK_STREAM : SOCK_DGRAM, proto); + const SOCKET fd = socket(AF_INET, is_tcp ? SOCK_STREAM : SOCK_DGRAM, proto); int one = 1; struct sockaddr_in addr; socklen_t alen = sizeof(addr); @@ -64,9 +63,9 @@ static int is_port_available(int *port, int is_tcp) { } /* Reuseaddr lets us start up a server immediately after it exits */ - if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) < 0) { + if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&one, sizeof(one)) < 0) { gpr_log(GPR_ERROR, "setsockopt() failed: %s", strerror(errno)); - close(fd); + closesocket(fd); return 0; } @@ -76,14 +75,14 @@ static int is_port_available(int *port, int is_tcp) { addr.sin_port = htons(*port); if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) { gpr_log(GPR_DEBUG, "bind(port=%d) failed: %s", *port, strerror(errno)); - close(fd); + closesocket(fd); return 0; } /* Get the bound port number */ if (getsockname(fd, (struct sockaddr *)&addr, &alen) < 0) { gpr_log(GPR_ERROR, "getsockname() failed: %s", strerror(errno)); - close(fd); + closesocket(fd); return 0; } GPR_ASSERT(alen <= sizeof(addr)); @@ -95,7 +94,7 @@ static int is_port_available(int *port, int is_tcp) { GPR_ASSERT(*port == actual_port); } - close(fd); + closesocket(fd); return 1; } @@ -120,7 +119,7 @@ int grpc_pick_unused_port(void) { int port; try++; if (try == 1) { - port = getpid() % (65536 - 30000) + 30000; + port = _getpid() % (65536 - 30000) + 30000; } else if (try <= NUM_RANDOM_PORTS_TO_PICK) { port = rand() % (65536 - 30000) + 30000; } else { |