aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/support
diff options
context:
space:
mode:
authorGravatar Nicolas "Pixel" Noble <pixel@nobis-crew.org>2015-02-04 01:31:14 +0100
committerGravatar Nicolas "Pixel" Noble <pixel@nobis-crew.org>2015-02-04 02:13:04 +0100
commit21f627ad0adeb41e49112ff071c40e5609f93736 (patch)
tree5c75e521d4943e556c9a45814e352ae2515fe6c0 /src/core/support
parent8c0596edcaf00680eea55455471cba84ccf8061e (diff)
First draft of the win32 implementation of iomgr.
Caveats: -) The win32 pollset isn't threadsafe (yet). -) Only client code is implemented. -) Only very simple code has been tested with it yet.
Diffstat (limited to 'src/core/support')
-rw-r--r--src/core/support/log_win32.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/core/support/log_win32.c b/src/core/support/log_win32.c
index dc8c1d0785..e1cf6fb10a 100644
--- a/src/core/support/log_win32.c
+++ b/src/core/support/log_win32.c
@@ -35,6 +35,7 @@
#ifdef GPR_WIN32
+#include <grpc/support/log_win32.h>
#include <grpc/support/log.h>
#include <grpc/support/alloc.h>
#include <stdio.h>
@@ -74,8 +75,42 @@ void gpr_log(const char *file, int line, gpr_log_severity severity,
/* Simple starter implementation */
void gpr_default_log(gpr_log_func_args *args) {
- fprintf(stderr, "%s %s:%d: %s\n", gpr_log_severity_string(args->severity),
+ fprintf(stderr, "%s.%u %s:%d: %s\n",
+ gpr_log_severity_string(args->severity), GetCurrentThreadId(),
args->file, args->line, args->message);
}
+/* Arguable, this could become a public function. But hardly
+ * anything beside the Windows implementation should use
+ * it, so, never mind...*/
+#if defined UNICODE || defined _UNICODE
+static char *tchar_to_char(LPWSTR input) {
+ char *ret;
+ int needed = WideCharToMultiByte(CP_UTF8, 0, input, -1, NULL, 0, NULL, NULL);
+ if (needed == 0) return NULL;
+ ret = gpr_malloc(needed + 1);
+ WideCharToMultiByte(CP_UTF8, 0, input, -1, ret, needed, NULL, NULL);
+ ret[needed] = 0;
+ return ret;
+}
+#else
+static char *tchar_to_char(LPSTR input) {
+ return gpr_strdup(input);
+}
#endif
+
+char *gpr_format_message(DWORD 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),
+ (LPTSTR)(&tmessage), 0, NULL);
+ message = tchar_to_char(tmessage);
+ LocalFree(tmessage);
+ return message;
+}
+
+#endif /* GPR_WIN32 */