summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNicolas "Pixel" Noble <pixel@nobis-crew.org>2013-12-20 01:34:09 -0800
committerNicolas "Pixel" Noble <pixel@nobis-crew.org>2013-12-20 01:34:09 -0800
commit3a91332a70abfc777a352c46727f54426c982371 (patch)
treee2ea6da7b045af8daf749c957b70bdf721864a1e /src
parent28e250cda01038c91fb9b69206c6f61f24764469 (diff)
A few more Win32 / VisualStudio fixes.
Diffstat (limited to 'src')
-rw-r--r--src/BRegex.cc6
-rw-r--r--src/HttpServer.cc6
-rw-r--r--src/Selectable.cc3
-rw-r--r--src/Socket.cc22
-rw-r--r--src/Task.cc39
-rw-r--r--src/Threads.cc9
6 files changed, 71 insertions, 14 deletions
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<Balau::Handle> 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 <winsock2.h>
#include <sys/types.h>
+#ifndef _MSC_VER
#include <unistd.h>
+#endif
#include <fcntl.h>
#include <sys/stat.h>
#include <stdio.h>
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 <sys/socket.h>
#endif
#include <sys/types.h>
+#ifdef _MSC_VER
+#else
#include <unistd.h>
+#endif
#include <fcntl.h>
#include <sys/stat.h>
#include <stdio.h>
@@ -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> 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 <windows.h> // 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<Balau::Task> 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) {