Commit 4ac6aab8 authored by Alex Hultman's avatar Alex Hultman

Fix clang build errors, fix warnings, set EFD_CLOEXEC

parent 4ab13b07
......@@ -199,7 +199,7 @@ struct Async : Poll {
Loop *loop;
void *data;
Async(Loop *loop) : Poll(loop, ::eventfd(0, 0)) {
Async(Loop *loop) : Poll(loop, ::eventfd(0, EFD_CLOEXEC)) {
this->loop = loop;
}
......@@ -216,7 +216,9 @@ struct Async : Poll {
void send() {
uint64_t one = 1;
::write(state.fd, &one, 8);
if (::write(state.fd, &one, 8) != 8) {
return;
}
}
void close() {
......
......@@ -16,7 +16,7 @@ struct WIN32_EXPORT Group : uS::NodeData {
protected:
friend struct Hub;
friend struct WebSocket<isServer>;
friend struct WebSocketProtocol<isServer>;
friend class WebSocketProtocol<isServer>;
friend struct HttpSocket<false>;
friend struct HttpSocket<true>;
......@@ -44,8 +44,6 @@ protected:
// todo: cannot be named user, collides with parent!
void *userData = nullptr;
void setUserData(void *user);
void *getUserData();
static void timerCallback(Timer *timer);
WebSocket<isServer> *webSocketHead = nullptr;
......@@ -78,6 +76,8 @@ public:
// Thread safe
void broadcast(const char *message, size_t length, OpCode opCode);
void setUserData(void *user);
void *getUserData();
// Not thread safe
void terminate();
......
......@@ -110,7 +110,7 @@ uS::Socket *HttpSocket<isServer>::onData(uS::Socket *s, char *data, size_t lengt
// Warning: changes socket, needs to inform the stack of Poll address change!
WebSocket<isServer> *webSocket = new WebSocket<isServer>(perMessageDeflate, httpSocket);
webSocket->setState<WebSocket<isServer>>();
webSocket->template setState<WebSocket<isServer>>();
webSocket->change(webSocket->nodeData->loop, webSocket, webSocket->setPoll(UV_READABLE));
getGroup<isServer>(webSocket)->addWebSocket(webSocket);
......@@ -162,7 +162,7 @@ uS::Socket *HttpSocket<isServer>::onData(uS::Socket *s, char *data, size_t lengt
WebSocket<isServer> *webSocket = new WebSocket<isServer>(false, httpSocket);
httpSocket->cancelTimeout();
webSocket->setUserData(httpSocket->httpUser);
webSocket->setState<WebSocket<isServer>>();
webSocket->template setState<WebSocket<isServer>>();
webSocket->change(webSocket->nodeData->loop, webSocket, webSocket->setPoll(UV_READABLE));
getGroup<isServer>(webSocket)->addWebSocket(webSocket);
......
......@@ -118,7 +118,7 @@ struct WIN32_EXPORT HttpSocket : uS::Socket {
size_t contentLength = 0;
bool missedDeadline = false;
HttpSocket(uS::Socket *socket, bool areYouSure) : uS::Socket(std::move(*socket)) {}
HttpSocket(uS::Socket *socket) : uS::Socket(std::move(*socket)) {}
void terminate() {
onEnd(this);
......@@ -213,7 +213,7 @@ struct HttpResponse {
};
if (httpSocket->outstandingResponsesHead != this) {
uS::Socket::Queue::Message *messagePtr = httpSocket->allocMessage(HttpTransformer::estimate(message, length));
HttpSocket<true>::Queue::Message *messagePtr = httpSocket->allocMessage(HttpTransformer::estimate(message, length));
messagePtr->length = HttpTransformer::transform(message, (char *) messagePtr->data, length, transformData);
messagePtr->callback = callback;
messagePtr->callbackData = callbackData;
......@@ -226,9 +226,9 @@ struct HttpResponse {
HttpResponse *head = next;
while (head) {
// empty message queue
uS::Socket::Queue::Message *messagePtr = head->messageQueue;
HttpSocket<true>::Queue::Message *messagePtr = head->messageQueue;
while (messagePtr) {
uS::Socket::Queue::Message *nextMessage = messagePtr->nextMessage;
HttpSocket<true>::Queue::Message *nextMessage = messagePtr->nextMessage;
bool wasTransferred;
if (httpSocket->write(messagePtr, wasTransferred)) {
......
......@@ -43,7 +43,7 @@ char *Hub::inflate(char *data, size_t &length) {
}
void Hub::onServerAccept(uS::Socket *s) {
HttpSocket<SERVER> *httpSocket = new HttpSocket<SERVER>(s, true);
HttpSocket<SERVER> *httpSocket = new HttpSocket<SERVER>(s);
delete s;
httpSocket->setState<HttpSocket<SERVER>>();
......@@ -84,7 +84,7 @@ bool Hub::listen(int port, uS::TLS::Context sslContext, int options, Group<SERVE
}
uS::Socket *allocateHttpSocket(uS::Socket *s) {
return (uS::Socket *) new HttpSocket<CLIENT>(s, true);
return (uS::Socket *) new HttpSocket<CLIENT>(s);
}
void Hub::connect(std::string uri, void *user, std::map<std::string, std::string> extraHeaders, int timeoutMs, Group<CLIENT> *eh) {
......@@ -163,7 +163,7 @@ void Hub::upgrade(uv_os_sock_t fd, const char *secKey, SSL *ssl, const char *ext
s.setNoDelay(true);
// todo: skip httpSocket -> it cannot fail anyways!
HttpSocket<SERVER> *httpSocket = new HttpSocket<SERVER>(&s, true);
HttpSocket<SERVER> *httpSocket = new HttpSocket<SERVER>(&s);
httpSocket->setState<HttpSocket<SERVER>>();
httpSocket->change(httpSocket->nodeData->loop, httpSocket, httpSocket->setPoll(UV_READABLE));
bool perMessageDeflate;
......
......@@ -88,8 +88,8 @@ public:
using Group<SERVER>::onHttpUpgrade;
using Group<SERVER>::onCancelledHttpRequest;
friend struct WebSocketProtocol<true>;
friend struct WebSocketProtocol<false>;
friend class WebSocketProtocol<true>;
friend class WebSocketProtocol<false>;
};
}
......
......@@ -477,7 +477,7 @@ public:
return state.shuttingDown;
}
friend struct Node;
friend class Node;
friend struct NodeData;
};
......
......@@ -65,7 +65,7 @@ public:
friend struct Group<isServer>;
friend struct HttpSocket<isServer>;
friend struct uS::Socket;
friend struct WebSocketProtocol<isServer>;
friend class WebSocketProtocol<isServer>;
};
}
......
......@@ -171,7 +171,7 @@ private:
}
// 16 bytes
struct {
struct State {
unsigned int wantsHead : 1;
unsigned int spillLength : 4;
int opStack : 2; // -1, 0, 1
......@@ -180,7 +180,15 @@ private:
// 15 bytes
unsigned char spill[LONG_MESSAGE_HEADER - 1];
OpCode opCode[2];
} state = {true, 0, -1, true};
State() {
wantsHead = true;
spillLength = 0;
opStack = -1;
lastFin = true;
}
} state;
// 8 bytes
unsigned int remainingBytes = 0;
......
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