From a2e7158792f88d8b2734ecfb3424cb873ff43083 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 10 Sep 2019 10:04:51 +0200 Subject: record: Windows compatibility Update #3665. --- trace/record/record-client-base.cc | 19 +++++++++++++++---- trace/wscript | 9 +++++++-- 2 files changed, 22 insertions(+), 6 deletions(-) (limited to 'trace') diff --git a/trace/record/record-client-base.cc b/trace/record/record-client-base.cc index 01ed803..ac88eab 100644 --- a/trace/record/record-client-base.cc +++ b/trace/record/record-client-base.cc @@ -27,12 +27,18 @@ #include "client.h" +#ifdef _WIN32 +#include +#include +#else #include -#include #include #include -#include #include +#endif + +#include +#include #include #include @@ -42,13 +48,18 @@ static ssize_t ReadFile(int fd, void* buf, size_t n) { } static ssize_t ReadSocket(int fd, void* buf, size_t n) { - return ::recv(fd, buf, n, 0); + // This cast is necessary for Windows + return ::recv(fd, static_cast(buf), n, 0); } void FileDescriptor::Open(const char* file) { assert(fd_ == -1); - fd_ = ::open(file, O_RDONLY); + int oflag = O_RDONLY; +#ifdef _WIN32 + oflag |= O_BINARY; +#endif + fd_ = ::open(file, oflag); if (fd_ < 0) { throw ErrnoException(std::string("cannot open file '") + file + "'"); } diff --git a/trace/wscript b/trace/wscript index 9bac9b9..a2124ad 100644 --- a/trace/wscript +++ b/trace/wscript @@ -33,6 +33,7 @@ def options(opt): def configure(conf): conf.load('compiler_c') conf.load('compiler_cxx') + conf.check_cxx(lib = 'ws2_32', mandatory=False) def build(bld): # @@ -46,7 +47,10 @@ def build(bld): conf['warningflags'] = ['-Wall', '-Wextra', '-pedantic'] conf['optflags'] = bld.env.C_OPTS conf['cflags'] = ['-pipe', '-g'] + conf['optflags'] - conf['linkflags'] = ['-g'] + conf['cxxflags'] = ['-std=c++11'] + conf['cflags'] + conf['lib'] = [] + if bld.env.LIB_WS2_32: + conf['lib'].extend(bld.env.LIB_WS2_32) # # The list of defines @@ -65,7 +69,8 @@ def build(bld): includes = ['record'], defines = defines, cflags = conf['cflags'] + conf['warningflags'], - linkflags = conf['linkflags']) + cxxflags = conf['cxxflags'] + conf['warningflags'], + lib = conf['lib']) def tags(ctx): ctx.exec_command('etags $(find . -name \*.[sSch])', shell = True) -- cgit v1.2.3