diff options
author | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2016-01-28 09:35:27 +0100 |
---|---|---|
committer | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2016-01-28 09:35:27 +0100 |
commit | 9bcab61d2780e719b5551322ddc7d08c6cf7725f (patch) | |
tree | dc4bb9a3dfcd244fba77dd5a3726b80c9a4c5909 | |
parent | 545c6c133de700785876959efbeb7a2987dcf2c7 (diff) | |
parent | bd76a63a6f3683930a83a4770d06bb29e4e8820a (diff) |
Merge branch 'win32-cleanup' into make-ruby-installable
-rw-r--r-- | include/grpc/support/log_win32.h | 4 | ||||
-rw-r--r-- | include/grpc/support/thd.h | 4 | ||||
-rw-r--r-- | src/core/iomgr/iocp_windows.c | 4 | ||||
-rw-r--r-- | src/core/iomgr/pollset_windows.c | 11 | ||||
-rw-r--r-- | src/core/iomgr/sockaddr_win32.h | 7 | ||||
-rw-r--r-- | src/core/iomgr/tcp_server_windows.c | 2 | ||||
-rw-r--r-- | src/core/iomgr/tcp_windows.c | 4 | ||||
-rw-r--r-- | src/core/support/env_win32.c | 22 | ||||
-rw-r--r-- | src/core/support/log_win32.c | 6 | ||||
-rw-r--r-- | src/core/support/string_win32.c | 10 | ||||
-rw-r--r-- | src/core/support/sync_win32.c | 8 | ||||
-rw-r--r-- | src/core/support/time_win32.c | 21 |
12 files changed, 52 insertions, 51 deletions
diff --git a/include/grpc/support/log_win32.h b/include/grpc/support/log_win32.h index ea6b16dd77..3546266976 100644 --- a/include/grpc/support/log_win32.h +++ b/include/grpc/support/log_win32.h @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -42,7 +42,7 @@ extern "C" { * formatted error message, corresponding to the error messageid. * Use in conjunction with GetLastError() et al. */ -char *gpr_format_message(DWORD messageid); +char *gpr_format_message(int messageid); #ifdef __cplusplus } diff --git a/include/grpc/support/thd.h b/include/grpc/support/thd.h index 58b8a8340e..56185cc8ea 100644 --- a/include/grpc/support/thd.h +++ b/include/grpc/support/thd.h @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -48,7 +48,7 @@ extern "C" { #endif -typedef uint64_t gpr_thd_id; +typedef uintptr_t gpr_thd_id; /* Thread creation options. */ typedef struct { diff --git a/src/core/iomgr/iocp_windows.c b/src/core/iomgr/iocp_windows.c index d3868ce62c..65e371842f 100644 --- a/src/core/iomgr/iocp_windows.c +++ b/src/core/iomgr/iocp_windows.c @@ -67,7 +67,7 @@ static DWORD deadline_to_millis_timeout(gpr_timespec deadline, return 0; } timeout = gpr_time_sub(deadline, now); - return gpr_time_to_millis(gpr_time_add( + return (DWORD)gpr_time_to_millis(gpr_time_add( timeout, gpr_time_from_nanos(GPR_NS_PER_MS - 1, GPR_TIMESPAN))); } @@ -179,11 +179,9 @@ void grpc_iocp_add_socket(grpc_winsocket *socket) { static void socket_notify_on_iocp(grpc_exec_ctx *exec_ctx, grpc_winsocket *socket, grpc_closure *closure, grpc_winsocket_callback_info *info) { - int run_now = 0; GPR_ASSERT(info->closure == NULL); gpr_mu_lock(&socket->state_mu); if (info->has_pending_iocp) { - run_now = 1; info->has_pending_iocp = 0; grpc_exec_ctx_enqueue(exec_ctx, closure, 1); } else { diff --git a/src/core/iomgr/pollset_windows.c b/src/core/iomgr/pollset_windows.c index deb661548d..bfd9e69a16 100644 --- a/src/core/iomgr/pollset_windows.c +++ b/src/core/iomgr/pollset_windows.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -81,15 +81,6 @@ static grpc_pollset_worker *pop_front_worker( } } -static void push_back_worker(grpc_pollset_worker *root, - grpc_pollset_worker_link_type type, - grpc_pollset_worker *worker) { - worker->links[type].next = root; - worker->links[type].prev = worker->links[type].next->links[type].prev; - worker->links[type].prev->links[type].next = - worker->links[type].next->links[type].prev = worker; -} - static void push_front_worker(grpc_pollset_worker *root, grpc_pollset_worker_link_type type, grpc_pollset_worker *worker) { diff --git a/src/core/iomgr/sockaddr_win32.h b/src/core/iomgr/sockaddr_win32.h index fe2be99145..8e3946a7d8 100644 --- a/src/core/iomgr/sockaddr_win32.h +++ b/src/core/iomgr/sockaddr_win32.h @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -38,9 +38,4 @@ #include <ws2tcpip.h> #include <mswsock.h> -#ifdef __MINGW32__ -/* mingw seems to be missing that definition. */ -const char *inet_ntop(int af, const void *src, char *dst, socklen_t size); -#endif - #endif /* GRPC_INTERNAL_CORE_IOMGR_SOCKADDR_WIN32_H */ diff --git a/src/core/iomgr/tcp_server_windows.c b/src/core/iomgr/tcp_server_windows.c index 8ee8149f25..00d381f264 100644 --- a/src/core/iomgr/tcp_server_windows.c +++ b/src/core/iomgr/tcp_server_windows.c @@ -531,7 +531,7 @@ int grpc_tcp_server_port_fd(grpc_tcp_server *s, unsigned port_index, for (sp = s->head; sp && port_index != 0; sp = sp->next, --port_index) ; if (sp) { - return _open_osfhandle(sp->socket->socket, 0); + return _open_osfhandle((intptr_t)sp->socket->socket, 0); } else { return -1; } diff --git a/src/core/iomgr/tcp_windows.c b/src/core/iomgr/tcp_windows.c index cc7f7ff8d2..f09588cc21 100644 --- a/src/core/iomgr/tcp_windows.c +++ b/src/core/iomgr/tcp_windows.c @@ -143,10 +143,7 @@ static void on_read(grpc_exec_ctx *exec_ctx, void *tcpp, int success) { grpc_closure *cb = tcp->read_cb; grpc_winsocket *socket = tcp->socket; gpr_slice sub; - gpr_slice *slice = NULL; - size_t nslices = 0; grpc_winsocket_callback_info *info = &socket->read_info; - int do_abort = 0; if (success) { if (socket->read_info.wsa_error != 0 && !tcp->shutting_down) { @@ -238,7 +235,6 @@ static void on_write(grpc_exec_ctx *exec_ctx, void *tcpp, int success) { grpc_winsocket *handle = tcp->socket; grpc_winsocket_callback_info *info = &handle->write_info; grpc_closure *cb; - int do_abort = 0; gpr_mu_lock(&tcp->mu); cb = tcp->write_cb; diff --git a/src/core/support/env_win32.c b/src/core/support/env_win32.c index 6b1ff102b0..10258283ba 100644 --- a/src/core/support/env_win32.c +++ b/src/core/support/env_win32.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -38,7 +38,12 @@ #include "src/core/support/env.h" #include "src/core/support/string.h" +#ifdef __MINGW32__ +errno_t getenv_s(size_t *size_needed, char *buffer, size_t size, + const char *varname); +#else #include <stdlib.h> +#endif #include <grpc/support/alloc.h> #include <grpc/support/log.h> @@ -47,14 +52,17 @@ char *gpr_getenv(const char *name) { size_t size; char *result = NULL; - char *duplicated; errno_t err; - err = _dupenv_s(&result, &size, name); - if (err) return NULL; - duplicated = gpr_strdup(result); - free(result); - return duplicated; + err = getenv_s(&size, NULL, 0, name); + if (err || (size == 0)) return NULL; + result = gpr_malloc(size); + err = getenv_s(&size, result, size, name); + if (err) { + gpr_free(result); + return NULL; + } + return result; } void gpr_setenv(const char *name, const char *value) { diff --git a/src/core/support/log_win32.c b/src/core/support/log_win32.c index 40adcd1b50..e18e667fe5 100644 --- a/src/core/support/log_win32.c +++ b/src/core/support/log_win32.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -109,13 +109,13 @@ void gpr_default_log(gpr_log_func_args *args) { fflush(stderr); } -char *gpr_format_message(DWORD messageid) { +char *gpr_format_message(int messageid) { LPTSTR tmessage; char *message; DWORD status = FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, messageid, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + NULL, (DWORD)messageid, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)(&tmessage), 0, NULL); if (status == 0) return gpr_strdup("Unable to retrieve error string"); message = gpr_tchar_to_char(tmessage); diff --git a/src/core/support/string_win32.c b/src/core/support/string_win32.c index 914ba8771c..3b1f702cf1 100644 --- a/src/core/support/string_win32.c +++ b/src/core/support/string_win32.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -85,8 +85,8 @@ LPTSTR gpr_char_to_tchar(LPCSTR input) { LPTSTR ret; int needed = MultiByteToWideChar(CP_UTF8, 0, input, -1, NULL, 0); - if (needed == 0) return NULL; - ret = gpr_malloc(needed * sizeof(TCHAR)); + if (needed <= 0) return NULL; + ret = gpr_malloc((unsigned)needed * sizeof(TCHAR)); MultiByteToWideChar(CP_UTF8, 0, input, -1, ret, needed); return ret; } @@ -95,8 +95,8 @@ LPSTR gpr_tchar_to_char(LPCTSTR input) { LPSTR ret; int needed = WideCharToMultiByte(CP_UTF8, 0, input, -1, NULL, 0, NULL, NULL); - if (needed == 0) return NULL; - ret = gpr_malloc(needed); + if (needed <= 0) return NULL; + ret = gpr_malloc((unsigned)needed); WideCharToMultiByte(CP_UTF8, 0, input, -1, ret, needed, NULL, NULL); return ret; } diff --git a/src/core/support/sync_win32.c b/src/core/support/sync_win32.c index 51a082b29e..84d412a75f 100644 --- a/src/core/support/sync_win32.c +++ b/src/core/support/sync_win32.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -94,7 +94,11 @@ int gpr_cv_wait(gpr_cv *cv, gpr_mu *mu, gpr_timespec abs_deadline) { if (now_ms >= deadline_ms) { timeout = 1; } else { - timeout_max_ms = (DWORD)min(deadline_ms - now_ms, INFINITE - 1); + if ((deadline_ms - now_ms) >= INFINITE) { + timeout_max_ms = INFINITE - 1; + } else { + timeout_max_ms = (DWORD)(deadline_ms - now_ms); + } timeout = (SleepConditionVariableCS(cv, &mu->cs, timeout_max_ms) == 0 && GetLastError() == ERROR_TIMEOUT); } diff --git a/src/core/support/time_win32.c b/src/core/support/time_win32.c index 2bed0f6a9c..8af957e6f4 100644 --- a/src/core/support/time_win32.c +++ b/src/core/support/time_win32.c @@ -1,6 +1,6 @@ /* * - * Copyright 2015, Google Inc. + * Copyright 2015-2016, Google Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -37,9 +37,12 @@ #ifdef GPR_WIN32 +#include <grpc/support/log.h> #include <grpc/support/time.h> #include <src/core/support/time_precise.h> #include <sys/timeb.h> +#include <process.h> +#include <limits.h> #include "src/core/support/block_annotate.h" @@ -50,11 +53,12 @@ void gpr_time_init(void) { LARGE_INTEGER frequency; QueryPerformanceFrequency(&frequency); QueryPerformanceCounter(&g_start_time); - g_time_scale = 1.0 / frequency.QuadPart; + g_time_scale = 1.0 / (double)frequency.QuadPart; } gpr_timespec gpr_now(gpr_clock_type clock) { gpr_timespec now_tv; + LONGLONG diff; struct _timeb now_tb; LARGE_INTEGER timestamp; double now_dbl; @@ -68,10 +72,14 @@ gpr_timespec gpr_now(gpr_clock_type clock) { case GPR_CLOCK_MONOTONIC: case GPR_CLOCK_PRECISE: QueryPerformanceCounter(×tamp); - now_dbl = (timestamp.QuadPart - g_start_time.QuadPart) * g_time_scale; + diff = timestamp.QuadPart - g_start_time.QuadPart; + now_dbl = (double)diff * g_time_scale; now_tv.tv_sec = (int64_t)now_dbl; now_tv.tv_nsec = (int32_t)((now_dbl - (double)now_tv.tv_sec) * 1e9); break; + case GPR_TIMESPAN: + abort(); + break; } return now_tv; } @@ -79,7 +87,7 @@ gpr_timespec gpr_now(gpr_clock_type clock) { void gpr_sleep_until(gpr_timespec until) { gpr_timespec now; gpr_timespec delta; - DWORD sleep_millis; + int64_t sleep_millis; for (;;) { /* We could simplify by using clock_nanosleep instead, but it might be @@ -91,9 +99,10 @@ void gpr_sleep_until(gpr_timespec until) { delta = gpr_time_sub(until, now); sleep_millis = - (DWORD)delta.tv_sec * GPR_MS_PER_SEC + delta.tv_nsec / GPR_NS_PER_MS; + delta.tv_sec * GPR_MS_PER_SEC + delta.tv_nsec / GPR_NS_PER_MS; + GPR_ASSERT((sleep_millis >= 0) && (sleep_millis <= INT_MAX)); GRPC_SCHEDULING_START_BLOCKING_REGION; - Sleep(sleep_millis); + Sleep((DWORD)sleep_millis); GRPC_SCHEDULING_END_BLOCKING_REGION; } } |