Merge pull request #4902 from nicolasnoble/win32-cleanup

Cleaning up Windows compilation.
pull/4940/head
Michael Lumish 9 years ago
commit a570b73a48
  1. 4
      include/grpc/support/log_win32.h
  2. 4
      include/grpc/support/thd.h
  3. 6
      src/core/iomgr/iocp_windows.c
  4. 11
      src/core/iomgr/pollset_windows.c
  5. 7
      src/core/iomgr/sockaddr_win32.h
  6. 2
      src/core/iomgr/tcp_server_windows.c
  7. 6
      src/core/iomgr/tcp_windows.c
  8. 22
      src/core/support/env_win32.c
  9. 6
      src/core/support/log_win32.c
  10. 10
      src/core/support/string_win32.c
  11. 8
      src/core/support/sync_win32.c
  12. 21
      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
@ -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
}

@ -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 {

@ -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
@ -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 {

@ -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) {

@ -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 */

@ -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;
}

@ -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
@ -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;

@ -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) {

@ -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);

@ -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;
}

@ -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);
}

@ -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(&timestamp);
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;
}
}

Loading…
Cancel
Save