From 3a91332a70abfc777a352c46727f54426c982371 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Fri, 20 Dec 2013 01:34:09 -0800 Subject: A few more Win32 / VisualStudio fixes. --- src/BRegex.cc | 6 ++++++ src/HttpServer.cc | 6 ++++++ src/Selectable.cc | 3 +++ src/Socket.cc | 22 +++++++++++++++++----- src/Task.cc | 39 +++++++++++++++++++++++++++++++++++++-- src/Threads.cc | 9 ++------- 6 files changed, 71 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/BRegex.cc b/src/BRegex.cc index d755e04..00b9d0b 100644 --- a/src/BRegex.cc +++ b/src/BRegex.cc @@ -44,3 +44,9 @@ Balau::String Balau::Regex::getError(int err) const { Balau::Regex const Balau::Regexes::any(".*"); Balau::Regex const Balau::Regexes::empty("^$"); + +#ifdef _MSC_VER +extern "C" { +void printchar(int) { } +}; +#endif diff --git a/src/HttpServer.cc b/src/HttpServer.cc index 53e3da0..3abf776 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -5,6 +5,12 @@ #include "SimpleMustache.h" #include "Main.h" +#ifdef _MSC_VER +// FU, MICROSOFT! +#undef DELETE +#undef ERROR +#endif + class OutputCheck : public Balau::Handle { public: OutputCheck(Balau::IO h) : m_h(h), m_wrote(false) { IAssert(m_h->canWrite(), "We haven't been passed a writable Handle to our HttpWorker... ?"); m_name.set("OutputCheck(%s)", m_h->getName()); } diff --git a/src/Selectable.cc b/src/Selectable.cc index 6bef2bc..40e85bc 100644 --- a/src/Selectable.cc +++ b/src/Selectable.cc @@ -1,5 +1,8 @@ +#include #include +#ifndef _MSC_VER #include +#endif #include #include #include diff --git a/src/Socket.cc b/src/Socket.cc index 2247d77..62fa8bc 100644 --- a/src/Socket.cc +++ b/src/Socket.cc @@ -3,7 +3,10 @@ #include #endif #include +#ifdef _MSC_VER +#else #include +#endif #include #include #include @@ -190,7 +193,7 @@ class AsyncOpResolv : public Balau::AsyncOperation { static Balau::DNSRequest * resolveName(const char * name, const char * service = NULL, struct addrinfo * hints = NULL) { Balau::DNSRequest * req = new Balau::DNSRequest(); - createAsyncOp(new AsyncOpResolv(name, service, hints, req)); + Balau::createAsyncOp(new AsyncOpResolv(name, service, hints, req)); return req; } @@ -242,7 +245,6 @@ void Balau::Socket::close() throw (GeneralException) { return; #ifdef _WIN32 closesocket(getFD()); - WSACleanup(); #else ::close(getFD()); #endif @@ -415,7 +417,11 @@ bool Balau::Socket::connect(const char * hostname, int port) { } #ifdef _WIN32 +#ifdef _MSC_VER + if (err != WSAEWOULDBLOCK) { +#else if (err != WSAWOULDBLOCK) { +#endif #else if (err != EINPROGRESS) { #endif @@ -483,7 +489,13 @@ Balau::IO Balau::Socket::accept() throw (GeneralException) { int s = ::accept(getFD(), (sockaddr *) &remoteAddr, &len); if (s < 0) { - if ((errno == EAGAIN) || (errno == EINTR) || (errno == EWOULDBLOCK)) { + int err = errno; +#ifdef _WIN32 + err = WSAGetLastError(); + if (err == WSAEWOULDBLOCK) + err = EAGAIN; +#endif + if ((err == EAGAIN) || (err == EINTR) || (err == EWOULDBLOCK)) { Task::operationYield(m_evtR, Task::INTERRUPTIBLE); } else { String msg = getErrorMessage(); @@ -508,11 +520,11 @@ ssize_t Balau::Socket::write(const void * buf, size_t count) throw (GeneralExcep } ssize_t Balau::Socket::recv(int sockfd, void *buf, size_t len, int flags) { - return ::recv(sockfd, buf, len, flags); + return ::recv(sockfd, (char *) buf, len, flags); } ssize_t Balau::Socket::send(int sockfd, const void *buf, size_t len, int flags) { - return ::send(sockfd, buf, len, flags); + return ::send(sockfd, (const char *) buf, len, flags); } Balau::ListenerBase::ListenerBase(int port, const char * local, void * opaque) : m_listener(new Socket()), m_stop(false), m_local(local), m_port(port), m_opaque(opaque) { diff --git a/src/Task.cc b/src/Task.cc index 9bf7c5b..c97077b 100644 --- a/src/Task.cc +++ b/src/Task.cc @@ -1,8 +1,43 @@ +#ifdef _MSC_VER +#include // for CALLBACK +#endif +#ifndef _WIN32 +#define CALLBACK +#endif + #include "Task.h" #include "TaskMan.h" #include "Exceptions.h" #include "Printer.h" #include "Local.h" +#include "Main.h" + +typedef void (*trampoline_t)(void *); + +static trampoline_t s_trampoline = NULL; + +namespace { + +class RegisterTrampoline : public Balau::AtStart { + public: + RegisterTrampoline() : AtStart(0) { } + void doStart() { + Balau::Task::registerTrampoline(); + } +}; + +static RegisterTrampoline registerTrampoline; + +} + +static void CALLBACK trampoline(void * arg) { + s_trampoline(arg); +} + +void Balau::Task::registerTrampoline() { + AAssert(s_trampoline == NULL, "Don't call registerTrampoline directly"); + s_trampoline = coroutineTrampoline; +} static Balau::LocalTmpl localTask; @@ -28,11 +63,11 @@ void Balau::Task::setup(TaskMan * taskMan, void * stack) { #ifndef _WIN32 IAssert(stack, "Can't setup a coroutine without a stack"); m_stack = stack; - coro_create(&m_ctx, coroutineTrampoline, this, m_stack, size); + coro_create(&m_ctx, trampoline, this, m_stack, size); #else IAssert(!stack, "We shouldn't allocate stacks with Fibers"); m_stack = NULL; - m_fiber = CreateFiber(size, coroutineTrampoline, this); + m_fiber = CreateFiber(size, trampoline, this); #endif } diff --git a/src/Threads.cc b/src/Threads.cc index c05d23f..f5f9a7f 100644 --- a/src/Threads.cc +++ b/src/Threads.cc @@ -29,14 +29,9 @@ Balau::Lock::Lock() { Balau::RWLock::RWLock() { int r; - pthread_rwlockattr_t attr; - r = pthread_rwlockattr_init(&attr); - RAssert(r == 0, "Couldn't initialize rwlock attribute; r = %i", r); - r = pthread_rwlock_init(&m_lock, &attr); - RAssert(r == 0, "Couldn't initialize mutex; r = %i", r); - r = pthread_rwlockattr_destroy(&attr); - RAssert(r == 0, "Couldn't destroy rwlock attribute; r = %i", r); + r = pthread_rwlock_init(&m_lock, NULL); + RAssert(r == 0, "Couldn't initialize read write lock; r = %i", r); } void * Balau::ThreadHelper::threadProc(void * arg) { -- cgit v1.2.3