Adding support for msys.

pull/6183/head
Nicolas "Pixel" Noble 9 years ago
parent bcd49994e2
commit c4b18a50de
  1. 4
      BUILD
  2. 2
      Makefile
  3. 2
      binding.gyp
  4. 2
      build.yaml
  5. 2
      config.m4
  6. 2
      gRPC.podspec
  7. 2
      grpc.gemspec
  8. 44
      include/grpc/impl/codegen/port_platform.h
  9. 2
      package.xml
  10. 27
      src/core/lib/iomgr/tcp_server_windows.c
  11. 14
      src/core/lib/iomgr/tcp_windows.c
  12. 44
      src/core/lib/support/env_win32.c
  13. 4
      src/core/lib/support/log_linux.c
  14. 18
      src/core/lib/support/log_win32.c
  15. 91
      src/core/lib/support/string_util_win32.c
  16. 41
      src/core/lib/support/string_win32.c
  17. 4
      src/core/lib/support/time_win32.c
  18. 75
      src/core/lib/support/tmpfile_msys.c
  19. 4
      src/core/lib/support/tmpfile_posix.c
  20. 4
      src/core/lib/support/tmpfile_win32.c
  21. 2
      src/python/grpcio/grpc_core_dependencies.py
  22. 9
      test/core/util/port_windows.c
  23. 2
      test/core/util/test_config.c
  24. 2
      tools/doxygen/Doxyfile.core.internal
  25. 2
      tools/run_tests/sources_and_headers.json
  26. 4
      vsprojects/vcxproj/gpr/gpr.vcxproj
  27. 6
      vsprojects/vcxproj/gpr/gpr.vcxproj.filters

@ -84,6 +84,7 @@ cc_library(
"src/core/lib/support/stack_lockfree.c",
"src/core/lib/support/string.c",
"src/core/lib/support/string_posix.c",
"src/core/lib/support/string_util_win32.c",
"src/core/lib/support/string_win32.c",
"src/core/lib/support/subprocess_posix.c",
"src/core/lib/support/subprocess_windows.c",
@ -98,6 +99,7 @@ cc_library(
"src/core/lib/support/time_precise.c",
"src/core/lib/support/time_win32.c",
"src/core/lib/support/tls_pthread.c",
"src/core/lib/support/tmpfile_msys.c",
"src/core/lib/support/tmpfile_posix.c",
"src/core/lib/support/tmpfile_win32.c",
"src/core/lib/support/wrap_memcpy.c",
@ -1211,6 +1213,7 @@ objc_library(
"src/core/lib/support/stack_lockfree.c",
"src/core/lib/support/string.c",
"src/core/lib/support/string_posix.c",
"src/core/lib/support/string_util_win32.c",
"src/core/lib/support/string_win32.c",
"src/core/lib/support/subprocess_posix.c",
"src/core/lib/support/subprocess_windows.c",
@ -1225,6 +1228,7 @@ objc_library(
"src/core/lib/support/time_precise.c",
"src/core/lib/support/time_win32.c",
"src/core/lib/support/tls_pthread.c",
"src/core/lib/support/tmpfile_msys.c",
"src/core/lib/support/tmpfile_posix.c",
"src/core/lib/support/tmpfile_win32.c",
"src/core/lib/support/wrap_memcpy.c",

@ -2322,6 +2322,7 @@ LIBGPR_SRC = \
src/core/lib/support/stack_lockfree.c \
src/core/lib/support/string.c \
src/core/lib/support/string_posix.c \
src/core/lib/support/string_util_win32.c \
src/core/lib/support/string_win32.c \
src/core/lib/support/subprocess_posix.c \
src/core/lib/support/subprocess_windows.c \
@ -2336,6 +2337,7 @@ LIBGPR_SRC = \
src/core/lib/support/time_precise.c \
src/core/lib/support/time_win32.c \
src/core/lib/support/tls_pthread.c \
src/core/lib/support/tmpfile_msys.c \
src/core/lib/support/tmpfile_posix.c \
src/core/lib/support/tmpfile_win32.c \
src/core/lib/support/wrap_memcpy.c \

@ -519,6 +519,7 @@
'src/core/lib/support/stack_lockfree.c',
'src/core/lib/support/string.c',
'src/core/lib/support/string_posix.c',
'src/core/lib/support/string_util_win32.c',
'src/core/lib/support/string_win32.c',
'src/core/lib/support/subprocess_posix.c',
'src/core/lib/support/subprocess_windows.c',
@ -533,6 +534,7 @@
'src/core/lib/support/time_precise.c',
'src/core/lib/support/time_win32.c',
'src/core/lib/support/tls_pthread.c',
'src/core/lib/support/tmpfile_msys.c',
'src/core/lib/support/tmpfile_posix.c',
'src/core/lib/support/tmpfile_win32.c',
'src/core/lib/support/wrap_memcpy.c',

@ -103,6 +103,7 @@ filegroups:
- src/core/lib/support/stack_lockfree.c
- src/core/lib/support/string.c
- src/core/lib/support/string_posix.c
- src/core/lib/support/string_util_win32.c
- src/core/lib/support/string_win32.c
- src/core/lib/support/subprocess_posix.c
- src/core/lib/support/subprocess_windows.c
@ -117,6 +118,7 @@ filegroups:
- src/core/lib/support/time_precise.c
- src/core/lib/support/time_win32.c
- src/core/lib/support/tls_pthread.c
- src/core/lib/support/tmpfile_msys.c
- src/core/lib/support/tmpfile_posix.c
- src/core/lib/support/tmpfile_win32.c
- src/core/lib/support/wrap_memcpy.c

@ -63,6 +63,7 @@ if test "$PHP_GRPC" != "no"; then
src/core/lib/support/stack_lockfree.c \
src/core/lib/support/string.c \
src/core/lib/support/string_posix.c \
src/core/lib/support/string_util_win32.c \
src/core/lib/support/string_win32.c \
src/core/lib/support/subprocess_posix.c \
src/core/lib/support/subprocess_windows.c \
@ -77,6 +78,7 @@ if test "$PHP_GRPC" != "no"; then
src/core/lib/support/time_precise.c \
src/core/lib/support/time_win32.c \
src/core/lib/support/tls_pthread.c \
src/core/lib/support/tmpfile_msys.c \
src/core/lib/support/tmpfile_posix.c \
src/core/lib/support/tmpfile_win32.c \
src/core/lib/support/wrap_memcpy.c \

@ -144,6 +144,7 @@ Pod::Spec.new do |s|
'src/core/lib/support/stack_lockfree.c',
'src/core/lib/support/string.c',
'src/core/lib/support/string_posix.c',
'src/core/lib/support/string_util_win32.c',
'src/core/lib/support/string_win32.c',
'src/core/lib/support/subprocess_posix.c',
'src/core/lib/support/subprocess_windows.c',
@ -158,6 +159,7 @@ Pod::Spec.new do |s|
'src/core/lib/support/time_precise.c',
'src/core/lib/support/time_win32.c',
'src/core/lib/support/tls_pthread.c',
'src/core/lib/support/tmpfile_msys.c',
'src/core/lib/support/tmpfile_posix.c',
'src/core/lib/support/tmpfile_win32.c',
'src/core/lib/support/wrap_memcpy.c',

@ -128,6 +128,7 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/support/stack_lockfree.c )
s.files += %w( src/core/lib/support/string.c )
s.files += %w( src/core/lib/support/string_posix.c )
s.files += %w( src/core/lib/support/string_util_win32.c )
s.files += %w( src/core/lib/support/string_win32.c )
s.files += %w( src/core/lib/support/subprocess_posix.c )
s.files += %w( src/core/lib/support/subprocess_windows.c )
@ -142,6 +143,7 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/support/time_precise.c )
s.files += %w( src/core/lib/support/time_win32.c )
s.files += %w( src/core/lib/support/tls_pthread.c )
s.files += %w( src/core/lib/support/tmpfile_msys.c )
s.files += %w( src/core/lib/support/tmpfile_posix.c )
s.files += %w( src/core/lib/support/tmpfile_win32.c )
s.files += %w( src/core/lib/support/wrap_memcpy.c )

@ -82,28 +82,31 @@
things. */
#if !defined(GPR_NO_AUTODETECT_PLATFORM)
#if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32)
#if defined(_WIN64) || defined(WIN64)
#define GPR_PLATFORM_STRING "windows"
#define GPR_WIN32 1
#define GPR_ARCH_64 1
#define GPR_GETPID_IN_PROCESS_H 1
#define GPR_WINSOCK_SOCKET 1
#define GPR_WINDOWS_SUBPROCESS 1
#ifdef __GNUC__
#define GPR_GCC_ATOMIC 1
#define GPR_GCC_TLS 1
#else
#define GPR_WIN32_ATOMIC 1
#define GPR_MSVC_TLS 1
#define GPR_ARCH_32 1
#endif
#define GPR_WINDOWS_CRASH_HANDLER 1
#elif defined(_WIN32) || defined(WIN32)
#define GPR_PLATFORM_STRING "windows"
#define GPR_ARCH_32 1
#define GPR_WIN32 1
#define GPR_GETPID_IN_PROCESS_H 1
#define GPR_WINSOCK_SOCKET 1
#define GPR_WINDOWS_SUBPROCESS 1
#define GPR_WIN32_ENV
#ifdef __MSYS__
#define GPR_GETPID_IN_UNISTD_H 1
#define GPR_MSYS_TMPFILE
#define GPR_POSIX_LOG
#define GPR_POSIX_STRING
#define GPR_POSIX_TIME
#else
#define GPR_GETPID_IN_PROCESS_H 1
#define GPR_WIN32_TMPFILE
#define GPR_WIN32_LOG
#define GPR_WINDOWS_CRASH_HANDLER 1
#define GPR_WIN32_STRING
#define GPR_WIN32_TIME
#endif
#ifdef __GNUC__
#define GPR_GCC_ATOMIC 1
#define GPR_GCC_TLS 1
@ -111,7 +114,6 @@
#define GPR_WIN32_ATOMIC 1
#define GPR_MSVC_TLS 1
#endif
#define GPR_WINDOWS_CRASH_HANDLER 1
#elif defined(ANDROID) || defined(__ANDROID__)
#define GPR_PLATFORM_STRING "android"
#define GPR_ANDROID 1
@ -126,7 +128,8 @@
#define GPR_POSIX_SOCKETADDR 1
#define GPR_POSIX_SOCKETUTILS 1
#define GPR_POSIX_ENV 1
#define GPR_POSIX_FILE 1
#define GPR_POSIX_TMPFILE 1
#define GPR_POSIX_LOG
#define GPR_POSIX_STRING 1
#define GPR_POSIX_SUBPROCESS 1
#define GPR_POSIX_SYNC 1
@ -153,6 +156,7 @@
#define GPR_GCC_ATOMIC 1
#define GPR_GCC_TLS 1
#define GPR_LINUX 1
#define GPR_LINUX_LOG
#define GPR_LINUX_MULTIPOLL_WITH_EPOLL 1
#define GPR_POSIX_WAKEUP_FD 1
#define GPR_POSIX_SOCKET 1
@ -175,7 +179,7 @@
#ifndef GPR_LINUX_SOCKETUTILS
#define GPR_POSIX_SOCKETUTILS
#endif
#define GPR_POSIX_FILE 1
#define GPR_POSIX_TMPFILE 1
#define GPR_POSIX_STRING 1
#define GPR_POSIX_SUBPROCESS 1
#define GPR_POSIX_SYNC 1
@ -213,7 +217,7 @@
#define GPR_POSIX_SOCKETADDR 1
#define GPR_POSIX_SOCKETUTILS 1
#define GPR_POSIX_ENV 1
#define GPR_POSIX_FILE 1
#define GPR_POSIX_TMPFILE 1
#define GPR_POSIX_STRING 1
#define GPR_POSIX_SUBPROCESS 1
#define GPR_POSIX_SYNC 1
@ -243,7 +247,7 @@
#define GPR_POSIX_SOCKETADDR 1
#define GPR_POSIX_SOCKETUTILS 1
#define GPR_POSIX_ENV 1
#define GPR_POSIX_FILE 1
#define GPR_POSIX_TMPFILE 1
#define GPR_POSIX_STRING 1
#define GPR_POSIX_SUBPROCESS 1
#define GPR_POSIX_SYNC 1
@ -280,7 +284,7 @@
#define GPR_POSIX_SOCKETADDR 1
#define GPR_POSIX_SOCKETUTILS 1
#define GPR_POSIX_ENV 1
#define GPR_POSIX_FILE 1
#define GPR_POSIX_TMPFILE 1
#define GPR_POSIX_STRING 1
#define GPR_POSIX_SUBPROCESS 1
#define GPR_POSIX_SYNC 1

@ -131,6 +131,7 @@
<file baseinstalldir="/" name="src/core/lib/support/stack_lockfree.c" role="src" />
<file baseinstalldir="/" name="src/core/lib/support/string.c" role="src" />
<file baseinstalldir="/" name="src/core/lib/support/string_posix.c" role="src" />
<file baseinstalldir="/" name="src/core/lib/support/string_util_win32.c" role="src" />
<file baseinstalldir="/" name="src/core/lib/support/string_win32.c" role="src" />
<file baseinstalldir="/" name="src/core/lib/support/subprocess_posix.c" role="src" />
<file baseinstalldir="/" name="src/core/lib/support/subprocess_windows.c" role="src" />
@ -145,6 +146,7 @@
<file baseinstalldir="/" name="src/core/lib/support/time_precise.c" role="src" />
<file baseinstalldir="/" name="src/core/lib/support/time_win32.c" role="src" />
<file baseinstalldir="/" name="src/core/lib/support/tls_pthread.c" role="src" />
<file baseinstalldir="/" name="src/core/lib/support/tmpfile_msys.c" role="src" />
<file baseinstalldir="/" name="src/core/lib/support/tmpfile_posix.c" role="src" />
<file baseinstalldir="/" name="src/core/lib/support/tmpfile_win32.c" role="src" />
<file baseinstalldir="/" name="src/core/lib/support/wrap_memcpy.c" role="src" />

@ -510,30 +510,17 @@ int grpc_tcp_server_add_port(grpc_tcp_server *s, const void *addr,
unsigned grpc_tcp_server_port_fd_count(grpc_tcp_server *s,
unsigned port_index) {
grpc_tcp_listener *sp;
for (sp = s->head; sp && port_index != 0; sp = sp->next, --port_index)
;
if (sp) {
return 1;
} else {
return 0;
}
(void)s;
(void)port_index;
abort();
}
int grpc_tcp_server_port_fd(grpc_tcp_server *s, unsigned port_index,
unsigned fd_index) {
grpc_tcp_listener *sp;
if (fd_index != 0) {
/* Windows implementation has only one fd per port_index. */
return -1;
}
for (sp = s->head; sp && port_index != 0; sp = sp->next, --port_index)
;
if (sp) {
return _open_osfhandle((intptr_t)sp->socket->socket, 0);
} else {
return -1;
}
(void)s;
(void)port_index;
(void)fd_index;
abort();
}
void grpc_tcp_server_start(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s,

@ -35,6 +35,8 @@
#ifdef GPR_WINSOCK_SOCKET
#include <limits.h>
#include "src/core/lib/iomgr/sockaddr_win32.h"
#include <grpc/support/alloc.h>
@ -51,12 +53,20 @@
#include "src/core/lib/iomgr/tcp_client.h"
#include "src/core/lib/iomgr/timer.h"
#if defined(__MSYS__) && defined(GPR_ARCH_64)
/* Nasty workaround for nasty bug when using the 64 bits msys compiler
in conjunction with Microsoft Windows headers. */
#define GRPC_FIONBIO _IOW('f', 126, uint32_t)
#else
#define GRPC_FIONBIO FIONBIO
#endif
static int set_non_block(SOCKET sock) {
int status;
unsigned long param = 1;
uint32_t param = 1;
DWORD ret;
status =
WSAIoctl(sock, FIONBIO, &param, sizeof(param), NULL, 0, &ret, NULL, NULL);
WSAIoctl(sock, GRPC_FIONBIO, &param, sizeof(param), NULL, 0, &ret, NULL, NULL);
return status == 0;
}

@ -33,41 +33,47 @@
#include <grpc/support/port_platform.h>
#ifdef GPR_WIN32
#ifdef GPR_WIN32_ENV
#include <windows.h>
#include "src/core/lib/support/env.h"
#include "src/core/lib/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 "src/core/lib/support/string_win32.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
char *gpr_getenv(const char *name) {
size_t size;
char *result = NULL;
errno_t err;
DWORD size;
LPTSTR tresult = NULL;
LPTSTR tname = gpr_char_to_tchar(name);
DWORD ret;
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);
ret = GetEnvironmentVariable(tname, NULL, 0);
if (ret == 0) return NULL;
size = ret * (DWORD)sizeof(TCHAR);
tresult = gpr_malloc(size);
ret = GetEnvironmentVariable(tname, tresult, size);
gpr_free(tname);
if (ret == 0) {
gpr_free(tresult);
return NULL;
}
result = gpr_tchar_to_char(tresult);
gpr_free(tresult);
return result;
}
void gpr_setenv(const char *name, const char *value) {
errno_t res = _putenv_s(name, value);
GPR_ASSERT(res == 0);
LPTSTR tname = gpr_char_to_tchar(name);
LPTSTR tvalue = gpr_char_to_tchar(value);
BOOL res = SetEnvironmentVariable(tname, tvalue);
gpr_free(tname);
gpr_free(tvalue);
GPR_ASSERT(res);
}
#endif /* GPR_WIN32 */
#endif /* GPR_WIN32_ENV */

@ -41,7 +41,7 @@
#include <grpc/support/port_platform.h>
#ifdef GPR_LINUX
#ifdef GPR_LINUX_LOG
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
@ -103,4 +103,4 @@ void gpr_default_log(gpr_log_func_args *args) {
gpr_free(prefix);
}
#endif
#endif /* GPR_LINUX_LOG */

@ -33,7 +33,7 @@
#include <grpc/support/port_platform.h>
#ifdef GPR_WIN32
#ifdef GPR_WIN32_LOG
#include <stdarg.h>
#include <stdio.h>
@ -109,18 +109,4 @@ void gpr_default_log(gpr_log_func_args *args) {
fflush(stderr);
}
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, (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);
LocalFree(tmessage);
return message;
}
#endif /* GPR_WIN32 */
#endif /* GPR_WIN32_LOG */

@ -0,0 +1,91 @@
/*
*
* Copyright 2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* Posix code for gpr snprintf support. */
#include <grpc/support/port_platform.h>
#ifdef GPR_WIN32
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <wchar.h>
#include <strsafe.h>
#include <grpc/support/alloc.h>
#include <grpc/support/string_util.h>
#include "src/core/lib/support/string.h"
#if defined UNICODE || defined _UNICODE
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((unsigned)needed * sizeof(TCHAR));
MultiByteToWideChar(CP_UTF8, 0, input, -1, ret, needed);
return ret;
}
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((unsigned)needed);
WideCharToMultiByte(CP_UTF8, 0, input, -1, ret, needed, NULL, NULL);
return ret;
}
#else
char *gpr_tchar_to_char(LPTSTR input) { return gpr_strdup(input); }
char *gpr_char_to_tchar(LPTSTR input) { return gpr_strdup(input); }
#endif
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, (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);
LocalFree(tmessage);
return message;
}
#endif /* GPR_WIN32 */

@ -31,23 +31,28 @@
*
*/
/* Posix code for gpr snprintf support. */
/* Windows code for gpr snprintf support. */
#include <grpc/support/port_platform.h>
#ifdef GPR_WIN32
#ifdef GPR_WIN32_STRING
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <wchar.h>
#include <strsafe.h>
#include <grpc/support/alloc.h>
#include <grpc/support/string_util.h>
#include "src/core/lib/support/string.h"
int gpr_asprintf(char **strp, const char *format, ...) {
va_list args;
int ret;
HRESULT success;
size_t strp_buflen;
/* Determine the length. */
@ -68,9 +73,9 @@ int gpr_asprintf(char **strp, const char *format, ...) {
/* Print to the buffer. */
va_start(args, format);
ret = vsnprintf_s(*strp, strp_buflen, _TRUNCATE, format, args);
success = StringCbVPrintfA(*strp, strp_buflen, format, args);
va_end(args);
if ((size_t)ret == strp_buflen - 1) {
if (success == S_OK) {
return ret;
}
@ -80,30 +85,4 @@ int gpr_asprintf(char **strp, const char *format, ...) {
return -1;
}
#if defined UNICODE || defined _UNICODE
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((unsigned)needed * sizeof(TCHAR));
MultiByteToWideChar(CP_UTF8, 0, input, -1, ret, needed);
return ret;
}
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((unsigned)needed);
WideCharToMultiByte(CP_UTF8, 0, input, -1, ret, needed, NULL, NULL);
return ret;
}
#else
char *gpr_tchar_to_char(LPTSTR input) { return gpr_strdup(input); }
char *gpr_char_to_tchar(LPTSTR input) { return gpr_strdup(input); }
#endif
#endif /* GPR_WIN32 */
#endif /* GPR_WIN32_STRING */

@ -35,7 +35,7 @@
#include <grpc/support/port_platform.h>
#ifdef GPR_WIN32
#ifdef GPR_WIN32_TIME
#include <grpc/support/log.h>
#include <grpc/support/time.h>
@ -107,4 +107,4 @@ void gpr_sleep_until(gpr_timespec until) {
}
}
#endif /* GPR_WIN32 */
#endif /* GPR_WIN32_TIME */

@ -0,0 +1,75 @@
/*
*
* Copyright 2015, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <grpc/support/port_platform.h>
#ifdef GPR_MSYS_TMPFILE
#include <io.h>
#include <stdio.h>
#include <string.h>
#include <tchar.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include "src/core/lib/support/string_win32.h"
#include "src/core/lib/support/tmpfile.h"
FILE *gpr_tmpfile(const char *prefix, char **tmp_filename_out) {
FILE *result = NULL;
char tmp_filename[MAX_PATH];
UINT success;
if (tmp_filename_out != NULL) *tmp_filename_out = NULL;
/* Generate a unique filename with our template + temporary path. */
success = GetTempFileNameA(".", prefix, 0, tmp_filename);
fprintf(stderr, "success = %d\n", success);
if (!success) goto end;
/* Open a file there. */
result = fopen(tmp_filename, "wb+");
fprintf(stderr, "result = %p\n", result);
if (result == NULL) goto end;
end:
if (result && tmp_filename_out) {
*tmp_filename_out = gpr_strdup(tmp_filename);
}
return result;
}
#endif /* GPR_MSYS_TMPFILE */

@ -33,7 +33,7 @@
#include <grpc/support/port_platform.h>
#ifdef GPR_POSIX_FILE
#ifdef GPR_POSIX_TMPFILE
#include "src/core/lib/support/tmpfile.h"
@ -82,4 +82,4 @@ end:
return result;
}
#endif /* GPR_POSIX_FILE */
#endif /* GPR_POSIX_TMPFILE */

@ -33,7 +33,7 @@
#include <grpc/support/port_platform.h>
#ifdef GPR_WIN32
#ifdef GPR_WIN32_TMPFILE
#include <io.h>
#include <stdio.h>
@ -81,4 +81,4 @@ end:
return result;
}
#endif /* GPR_WIN32 */
#endif /* GPR_WIN32_TMPFILE */

@ -57,6 +57,7 @@ CORE_SOURCE_FILES = [
'src/core/lib/support/stack_lockfree.c',
'src/core/lib/support/string.c',
'src/core/lib/support/string_posix.c',
'src/core/lib/support/string_util_win32.c',
'src/core/lib/support/string_win32.c',
'src/core/lib/support/subprocess_posix.c',
'src/core/lib/support/subprocess_windows.c',
@ -71,6 +72,7 @@ CORE_SOURCE_FILES = [
'src/core/lib/support/time_precise.c',
'src/core/lib/support/time_win32.c',
'src/core/lib/support/tls_pthread.c',
'src/core/lib/support/tmpfile_msys.c',
'src/core/lib/support/tmpfile_posix.c',
'src/core/lib/support/tmpfile_win32.c',
'src/core/lib/support/wrap_memcpy.c',

@ -51,6 +51,11 @@
#include "src/core/lib/support/env.h"
#include "test/core/util/port_server_client.h"
#if GPR_GETPID_IN_UNISTD_H
#include <sys/unistd.h>
static int _getpid() { return getpid(); }
#endif
#define NUM_RANDOM_PORTS_TO_PICK 100
static int *chosen_ports = NULL;
@ -114,7 +119,7 @@ static int is_port_available(int *port, int is_tcp) {
/* Try binding to port */
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = INADDR_ANY;
addr.sin_port = htons(*port);
addr.sin_port = htons((u_short)*port);
if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
gpr_log(GPR_DEBUG, "bind(port=%d) failed: %s", *port, strerror(errno));
closesocket(fd);
@ -127,7 +132,7 @@ static int is_port_available(int *port, int is_tcp) {
closesocket(fd);
return 0;
}
GPR_ASSERT(alen <= sizeof(addr));
GPR_ASSERT(alen <= (socklen_t)sizeof(addr));
actual_port = ntohs(addr.sin_port);
GPR_ASSERT(actual_port > 0);
if (*port == 0) {

@ -50,7 +50,7 @@ static unsigned seed(void) { return (unsigned)getpid(); }
#if GPR_GETPID_IN_PROCESS_H
#include <process.h>
static unsigned seed(void) { return _getpid(); }
static unsigned seed(void) { return (unsigned)_getpid(); }
#endif
#if GPR_WINDOWS_CRASH_HANDLER

@ -1167,6 +1167,7 @@ src/core/lib/support/slice_buffer.c \
src/core/lib/support/stack_lockfree.c \
src/core/lib/support/string.c \
src/core/lib/support/string_posix.c \
src/core/lib/support/string_util_win32.c \
src/core/lib/support/string_win32.c \
src/core/lib/support/subprocess_posix.c \
src/core/lib/support/subprocess_windows.c \
@ -1181,6 +1182,7 @@ src/core/lib/support/time_posix.c \
src/core/lib/support/time_precise.c \
src/core/lib/support/time_win32.c \
src/core/lib/support/tls_pthread.c \
src/core/lib/support/tmpfile_msys.c \
src/core/lib/support/tmpfile_posix.c \
src/core/lib/support/tmpfile_win32.c \
src/core/lib/support/wrap_memcpy.c

@ -5429,6 +5429,7 @@
"src/core/lib/support/string.c",
"src/core/lib/support/string.h",
"src/core/lib/support/string_posix.c",
"src/core/lib/support/string_util_win32.c",
"src/core/lib/support/string_win32.c",
"src/core/lib/support/string_win32.h",
"src/core/lib/support/subprocess_posix.c",
@ -5447,6 +5448,7 @@
"src/core/lib/support/time_win32.c",
"src/core/lib/support/tls_pthread.c",
"src/core/lib/support/tmpfile.h",
"src/core/lib/support/tmpfile_msys.c",
"src/core/lib/support/tmpfile_posix.c",
"src/core/lib/support/tmpfile_win32.c",
"src/core/lib/support/wrap_memcpy.c"

@ -259,6 +259,8 @@
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\core\lib\support\string_posix.c">
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\core\lib\support\string_util_win32.c">
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\core\lib\support\string_win32.c">
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\core\lib\support\subprocess_posix.c">
@ -287,6 +289,8 @@
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\core\lib\support\tls_pthread.c">
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\core\lib\support\tmpfile_msys.c">
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\core\lib\support\tmpfile_posix.c">
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\core\lib\support\tmpfile_win32.c">

@ -82,6 +82,9 @@
<ClCompile Include="$(SolutionDir)\..\src\core\lib\support\string_posix.c">
<Filter>src\core\lib\support</Filter>
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\core\lib\support\string_util_win32.c">
<Filter>src\core\lib\support</Filter>
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\core\lib\support\string_win32.c">
<Filter>src\core\lib\support</Filter>
</ClCompile>
@ -124,6 +127,9 @@
<ClCompile Include="$(SolutionDir)\..\src\core\lib\support\tls_pthread.c">
<Filter>src\core\lib\support</Filter>
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\core\lib\support\tmpfile_msys.c">
<Filter>src\core\lib\support</Filter>
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\core\lib\support\tmpfile_posix.c">
<Filter>src\core\lib\support</Filter>
</ClCompile>

Loading…
Cancel
Save