aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Nicolas Noble <nnoble@google.com>2015-03-18 16:27:43 -0700
committerGravatar Nicolas "Pixel" Noble <pixel@nobis-crew.org>2015-03-19 04:21:22 +0100
commitcfd6073a66fda3db150998ef40dbbc76c198c02e (patch)
tree219bdb26ca59d84996c4fd29e2be2d467057f080 /src/core
parent6cf02edae146694e6e9378e0b6fb635439b9c140 (diff)
Various Windows fixes.
-) using dupenv_s instead of getenv_s and calling strdup ourselves. -) few impossible-to-obtain if checks. -) various signed/unsigned casting. -) using time_t instead of time32_t -) checking output of FormatMessage for failures. -) don't redefine _WIN32_WINNT without undefining it first. -) fixed msvc's interlocked casting. -) renamed AddPort to AddListeningPort. -) added protobuf's third_party includes to search path. -) added a missing definition for inet_ntop in mingw32. -) removed useless declarations.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/iomgr/sockaddr_win32.h5
-rw-r--r--src/core/iomgr/tcp_server_windows.c3
-rw-r--r--src/core/iomgr/tcp_windows.c4
-rw-r--r--src/core/support/env_win32.c15
-rw-r--r--src/core/support/file_win32.c2
-rw-r--r--src/core/support/log_win32.c8
-rw-r--r--src/core/support/string_win32.c6
-rw-r--r--src/core/support/sync_win32.c1
-rw-r--r--src/core/support/time_win32.c4
9 files changed, 29 insertions, 19 deletions
diff --git a/src/core/iomgr/sockaddr_win32.h b/src/core/iomgr/sockaddr_win32.h
index 3a5f27bb34..c0385ea614 100644
--- a/src/core/iomgr/sockaddr_win32.h
+++ b/src/core/iomgr/sockaddr_win32.h
@@ -38,4 +38,9 @@
#include <winsock2.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 59319da26d..0c3ab1dc91 100644
--- a/src/core/iomgr/tcp_server_windows.c
+++ b/src/core/iomgr/tcp_server_windows.c
@@ -53,9 +53,6 @@
#define INIT_PORT_CAP 2
#define MIN_SAFE_ACCEPT_QUEUE_SIZE 100
-static gpr_once s_init_max_accept_queue_size;
-static int s_max_accept_queue_size;
-
/* one listening port */
typedef struct server_port {
gpr_uint8 addresses[sizeof(struct sockaddr_in6) * 2 + 32];
diff --git a/src/core/iomgr/tcp_windows.c b/src/core/iomgr/tcp_windows.c
index 3efd69a71b..ec5496e7ee 100644
--- a/src/core/iomgr/tcp_windows.c
+++ b/src/core/iomgr/tcp_windows.c
@@ -172,7 +172,7 @@ static void win_notify_on_read(grpc_endpoint *ep,
tcp->read_slice = gpr_slice_malloc(8192);
buffer.len = GPR_SLICE_LENGTH(tcp->read_slice);
- buffer.buf = GPR_SLICE_START_PTR(tcp->read_slice);
+ buffer.buf = (char *)GPR_SLICE_START_PTR(tcp->read_slice);
gpr_log(GPR_DEBUG, "win_notify_on_read: calling WSARecv without overlap");
status = WSARecv(tcp->socket->socket, &buffer, 1, &bytes_read, &flags,
@@ -284,7 +284,7 @@ static grpc_endpoint_write_status win_write(grpc_endpoint *ep,
for (i = 0; i < tcp->write_slices.count; i++) {
buffers[i].len = GPR_SLICE_LENGTH(tcp->write_slices.slices[i]);
- buffers[i].buf = GPR_SLICE_START_PTR(tcp->write_slices.slices[i]);
+ buffers[i].buf = (char *)GPR_SLICE_START_PTR(tcp->write_slices.slices[i]);
}
gpr_log(GPR_DEBUG, "win_write: calling WSASend without overlap");
diff --git a/src/core/support/env_win32.c b/src/core/support/env_win32.c
index 177cc36a30..9b4cd698ad 100644
--- a/src/core/support/env_win32.c
+++ b/src/core/support/env_win32.c
@@ -36,6 +36,7 @@
#ifdef GPR_WIN32
#include "src/core/support/env.h"
+#include "src/core/support/string.h"
#include <stdlib.h>
@@ -43,14 +44,16 @@
#include <grpc/support/log.h>
char *gpr_getenv(const char *name) {
- size_t required_size;
+ size_t size;
char *result = NULL;
+ char *duplicated;
+ errno_t err;
- getenv_s(&required_size, NULL, 0, name);
- if (required_size == 0) return NULL;
- result = gpr_malloc(required_size);
- getenv_s(&required_size, result, required_size, name);
- return result;
+ err = _dupenv_s(&result, &size, name);
+ if (err) return NULL;
+ duplicated = gpr_strdup(result);
+ free(result);
+ return duplicated;
}
void gpr_setenv(const char *name, const char *value) {
diff --git a/src/core/support/file_win32.c b/src/core/support/file_win32.c
index fe209af9b2..f59d3af397 100644
--- a/src/core/support/file_win32.c
+++ b/src/core/support/file_win32.c
@@ -72,7 +72,7 @@ FILE *gpr_tmpfile(const char *prefix, char **tmp_filename_out) {
if (_tfopen_s(&result, tmp_filename, TEXT("wb+")) != 0) goto end;
end:
- if (result && tmp_filename) {
+ if (result && tmp_filename_out) {
*tmp_filename_out = gpr_tchar_to_char(tmp_filename);
}
diff --git a/src/core/support/log_win32.c b/src/core/support/log_win32.c
index 720dc141f5..159c7e052c 100644
--- a/src/core/support/log_win32.c
+++ b/src/core/support/log_win32.c
@@ -43,6 +43,7 @@
#include <grpc/support/log.h>
#include <grpc/support/time.h>
+#include "src/core/support/string.h"
#include "src/core/support/string_win32.h"
void gpr_log(const char *file, int line, gpr_log_severity severity,
@@ -55,7 +56,7 @@ void gpr_log(const char *file, int line, gpr_log_severity severity,
va_start(args, format);
ret = _vscprintf(format, args);
va_end(args);
- if (!(0 <= ret && ret < ~(size_t)0)) {
+ if (ret < 0) {
message = NULL;
} else {
/* Allocate a new buffer, with space for the NUL terminator. */
@@ -66,7 +67,7 @@ void gpr_log(const char *file, int line, gpr_log_severity severity,
va_start(args, format);
ret = vsnprintf_s(message, strp_buflen, _TRUNCATE, format, args);
va_end(args);
- if (ret != strp_buflen - 1) {
+ if ((size_t)ret != strp_buflen - 1) {
/* This should never happen. */
gpr_free(message);
message = NULL;
@@ -90,7 +91,7 @@ void gpr_default_log(gpr_log_func_args *args) {
strcpy(time_buffer, "error:strftime");
}
- fprintf(stderr, "%s%s.%09u %5u %s:%d] %s\n",
+ fprintf(stderr, "%s%s.%09u %5lu %s:%d] %s\n",
gpr_log_severity_string(args->severity), time_buffer,
(int)(now.tv_nsec), GetCurrentThreadId(),
args->file, args->line, args->message);
@@ -105,6 +106,7 @@ char *gpr_format_message(DWORD messageid) {
NULL, messageid,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)(&tmessage), 0, NULL);
+ if (status == 0) return gpr_strdup("Unable to retreive error string");
message = gpr_tchar_to_char(tmessage);
LocalFree(tmessage);
return message;
diff --git a/src/core/support/string_win32.c b/src/core/support/string_win32.c
index 583abd27d8..6d1d6337a9 100644
--- a/src/core/support/string_win32.c
+++ b/src/core/support/string_win32.c
@@ -44,6 +44,8 @@
#include <grpc/support/alloc.h>
+#include "src/core/support/string.h"
+
int gpr_asprintf(char **strp, const char *format, ...) {
va_list args;
int ret;
@@ -53,7 +55,7 @@ int gpr_asprintf(char **strp, const char *format, ...) {
va_start(args, format);
ret = _vscprintf(format, args);
va_end(args);
- if (!(0 <= ret && ret < ~(size_t)0)) {
+ if (ret < 0) {
*strp = NULL;
return -1;
}
@@ -69,7 +71,7 @@ int gpr_asprintf(char **strp, const char *format, ...) {
va_start(args, format);
ret = vsnprintf_s(*strp, strp_buflen, _TRUNCATE, format, args);
va_end(args);
- if (ret == strp_buflen - 1) {
+ if ((size_t)ret == strp_buflen - 1) {
return ret;
}
diff --git a/src/core/support/sync_win32.c b/src/core/support/sync_win32.c
index c9a977cc80..cc31d9b052 100644
--- a/src/core/support/sync_win32.c
+++ b/src/core/support/sync_win32.c
@@ -37,6 +37,7 @@
#ifdef GPR_WIN32
+#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0600
#include <windows.h>
#include <grpc/support/log.h>
diff --git a/src/core/support/time_win32.c b/src/core/support/time_win32.c
index 8256849655..f221cb5790 100644
--- a/src/core/support/time_win32.c
+++ b/src/core/support/time_win32.c
@@ -42,8 +42,8 @@
gpr_timespec gpr_now(void) {
gpr_timespec now_tv;
- struct __timeb32 now_tb;
- _ftime32_s(&now_tb);
+ struct _timeb now_tb;
+ _ftime_s(&now_tb);
now_tv.tv_sec = now_tb.time;
now_tv.tv_nsec = now_tb.millitm * 1000000;
return now_tv;