summaryrefslogtreecommitdiff
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
parent28e250cda01038c91fb9b69206c6f61f24764469 (diff)
A few more Win32 / VisualStudio fixes.
-rw-r--r--includes/Http.h6
-rw-r--r--includes/SimpleMustache.h2
-rw-r--r--includes/Socket.h2
-rw-r--r--includes/Task.h11
-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
-rw-r--r--win32/regex/msvc-regex.c2
11 files changed, 82 insertions, 26 deletions
diff --git a/includes/Http.h b/includes/Http.h
index 62f8786..7c351a6 100644
--- a/includes/Http.h
+++ b/includes/Http.h
@@ -4,6 +4,12 @@
#include <BString.h>
#include <Handle.h>
+#ifdef _MSC_VER
+// SERIOUSLY ?!
+#undef DELETE
+#undef ERROR
+#endif
+
namespace Balau {
namespace Http {
diff --git a/includes/SimpleMustache.h b/includes/SimpleMustache.h
index b01955b..f30c831 100644
--- a/includes/SimpleMustache.h
+++ b/includes/SimpleMustache.h
@@ -57,8 +57,6 @@ class SimpleMustache {
LAMBDA,
} m_type = CONTEXTLIST;
Context(ContextType type) : m_type(type), m_root(false) { }
- Context(Context & c) { Failure("You can't copy a Context; use references"); }
- Context & operator=(Context & c) { Failure("You can't assign a Context; use references"); return *this; }
String m_str;
bool m_bool;
typedef std::map<String, Context *> SubContext;
diff --git a/includes/Socket.h b/includes/Socket.h
index cfa8218..22bf972 100644
--- a/includes/Socket.h
+++ b/includes/Socket.h
@@ -1,7 +1,9 @@
#pragma once
#ifdef _WIN32
+#ifndef _MSC_VER
#include <windows.h>
+#endif
#include <winsock2.h>
#include <ws2tcpip.h>
#else
diff --git a/includes/Task.h b/includes/Task.h
index 3d206ff..1041d08 100644
--- a/includes/Task.h
+++ b/includes/Task.h
@@ -10,10 +10,6 @@
#include <Exceptions.h>
#include <Printer.h>
-#ifdef _MSC_VER
-#include <Windows.h> // for CALLBACK
-#endif
-
namespace Balau {
namespace Events { class BaseEvent; };
@@ -119,10 +115,6 @@ class Async : public BaseEvent {
ev::async m_evt;
};
-#ifndef _WIN32
-#define CALLBACK
-#endif
-
class Custom : public BaseEvent {
public:
void doSignal() { BaseEvent::doSignal(); ev_break(m_loop, EVBREAK_ALL); }
@@ -180,6 +172,7 @@ class Task {
private:
bool m_oldStatus;
};
+ static void registerTrampoline();
protected:
void yield() throw (GeneralException) {
if (yield(false)) {
@@ -223,7 +216,7 @@ class Task {
void setup(TaskMan * taskMan, void * stack);
static bool needsStacks();
void switchTo();
- static void CALLBACK coroutineTrampoline(void *);
+ static void coroutineTrampoline(void *);
void coroutine();
bool enterSimpleContext() {
bool r;
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) {
diff --git a/win32/regex/msvc-regex.c b/win32/regex/msvc-regex.c
index f0746f8..2d74eae 100644
--- a/win32/regex/msvc-regex.c
+++ b/win32/regex/msvc-regex.c
@@ -4078,7 +4078,7 @@ re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop)
`pop_failure_point'. */
unsigned dummy_low_reg, dummy_high_reg;
unsigned char *pdummy;
- const char *sdummy;
+ const char *sdummy = NULL;
DEBUG_PRINT1 ("EXECUTING pop_failure_jump.\n");
POP_FAILURE_POINT (sdummy, pdummy,