Commit 8e937117 authored by Yuri Mikhailov's avatar Yuri Mikhailov Committed by Alex Hultman

Asio, Libuv and Epoll are now inside uS namespace (#715)

* Asio, Libuv and Epoll are now inside uS namespace

* uv_sock_t, UV_READABLE, UV_WRITABLE are returned back to global namespace
parent 5bce99c2
......@@ -7,6 +7,8 @@ typedef boost::asio::ip::tcp::socket::native_type uv_os_sock_t;
static const int UV_READABLE = 1;
static const int UV_WRITABLE = 2;
namespace uS {
struct Loop : boost::asio::io_service {
static Loop *createLoop(bool defaultLoop = true) {
......@@ -181,4 +183,6 @@ struct Poll {
}
};
}
#endif // ASIO_H
......@@ -2,6 +2,8 @@
#ifdef USE_EPOLL
namespace uS {
// todo: remove this mutex, have callbacks set at program start
std::recursive_mutex cbMutex;
void (*callbacks[16])(Poll *, int, int);
......@@ -57,4 +59,7 @@ void Loop::run() {
}
}
}
}
#endif
......@@ -14,6 +14,8 @@ typedef int uv_os_sock_t;
static const int UV_READABLE = EPOLLIN;
static const int UV_WRITABLE = EPOLLOUT;
namespace uS {
struct Poll;
struct Timer;
......@@ -254,4 +256,6 @@ struct Async : Poll {
}
};
}
#endif // EPOLL_H
......@@ -14,7 +14,7 @@ void *Group<isServer>::getUserData() {
}
template <bool isServer>
void Group<isServer>::timerCallback(Timer *timer) {
void Group<isServer>::timerCallback(uS::Timer *timer) {
Group<isServer> *group = (Group<isServer> *) timer->getData();
group->forEach([](uWS::WebSocket<isServer> *webSocket) {
......@@ -34,7 +34,7 @@ void Group<isServer>::timerCallback(Timer *timer) {
template <bool isServer>
void Group<isServer>::startAutoPing(int intervalMs, std::string userMessage) {
timer = new Timer(loop);
timer = new uS::Timer(loop);
timer->setData(this);
timer->start(timerCallback, intervalMs, intervalMs);
userPingMessage = userMessage;
......@@ -48,9 +48,9 @@ void Group<isServer>::addHttpSocket(HttpSocket<isServer> *httpSocket) {
} else {
httpSocket->next = nullptr;
// start timer
httpTimer = new Timer(hub->getLoop());
httpTimer = new uS::Timer(hub->getLoop());
httpTimer->setData(this);
httpTimer->start([](Timer *httpTimer) {
httpTimer->start([](uS::Timer *httpTimer) {
Group<isServer> *group = (Group<isServer> *) httpTimer->getData();
group->forEachHttpSocket([](HttpSocket<isServer> *httpSocket) {
if (httpSocket->missedDeadline) {
......
......@@ -42,13 +42,13 @@ protected:
unsigned int maxPayload;
Hub *hub;
int extensionOptions;
Timer *timer = nullptr, *httpTimer = nullptr;
uS::Timer *timer = nullptr, *httpTimer = nullptr;
std::string userPingMessage;
std::stack<Poll *> iterators;
std::stack<uS::Poll *> iterators;
// todo: cannot be named user, collides with parent!
void *userData = nullptr;
static void timerCallback(Timer *timer);
static void timerCallback(uS::Timer *timer);
WebSocket<isServer> *webSocketHead = nullptr;
HttpSocket<isServer> *httpSocketHead = nullptr;
......@@ -103,10 +103,10 @@ public:
template <class F>
void forEach(const F &cb) {
Poll *iterator = webSocketHead;
uS::Poll *iterator = webSocketHead;
iterators.push(iterator);
while (iterator) {
Poll *lastIterator = iterator;
uS::Poll *lastIterator = iterator;
cb((WebSocket<isServer> *) iterator);
iterator = iterators.top();
if (lastIterator == iterator) {
......@@ -120,10 +120,10 @@ public:
// duplicated code for now!
template <class F>
void forEachHttpSocket(const F &cb) {
Poll *iterator = httpSocketHead;
uS::Poll *iterator = httpSocketHead;
iterators.push(iterator);
while (iterator) {
Poll *lastIterator = iterator;
uS::Poll *lastIterator = iterator;
cb((HttpSocket<isServer> *) iterator);
iterator = iterators.top();
if (lastIterator == iterator) {
......
......@@ -4,6 +4,8 @@
#include <uv.h>
static_assert (UV_VERSION_MINOR >= 3, "µWebSockets requires libuv >=1.3.0");
namespace uS {
struct Loop : uv_loop_t {
static Loop *createLoop(bool defaultLoop = true) {
if (defaultLoop) {
......@@ -172,4 +174,6 @@ struct Poll {
}
};
}
#endif // LIBUV_H
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment