Cheaper timeout system
This commit is contained in:
@@ -140,7 +140,7 @@ public:
|
||||
/* Maximum message size we can receive */
|
||||
unsigned int maxPayloadLength = 16 * 1024;
|
||||
/* 2 minutes timeout is good */
|
||||
unsigned int idleTimeout = 120;
|
||||
unsigned short idleTimeout = 120;
|
||||
/* 64kb backpressure is probably good */
|
||||
unsigned int maxBackpressure = 64 * 1024;
|
||||
bool closeOnBackpressureLimit = false;
|
||||
@@ -167,6 +167,16 @@ public:
|
||||
return std::move(*this);
|
||||
}
|
||||
|
||||
/* Terminate on misleading idleTimeout values */
|
||||
if (behavior.idleTimeout && behavior.idleTimeout < 8) {
|
||||
std::cerr << "Error: idleTimeout must be either 0 or greater than 8!" << std::endl;
|
||||
std::terminate();
|
||||
}
|
||||
|
||||
if (behavior.idleTimeout % 4) {
|
||||
std::cerr << "Warning: idleTimeout should be a multiple of 4!" << std::endl;
|
||||
}
|
||||
|
||||
/* Every route has its own websocket context with its own behavior and user data type */
|
||||
auto *webSocketContext = WebSocketContext<SSL, true>::create(Loop::get(), (us_socket_context_t *) httpContext);
|
||||
|
||||
@@ -207,7 +217,6 @@ public:
|
||||
|
||||
/* Copy settings */
|
||||
webSocketContext->getExt()->maxPayloadLength = behavior.maxPayloadLength;
|
||||
webSocketContext->getExt()->idleTimeout = behavior.idleTimeout;
|
||||
webSocketContext->getExt()->maxBackpressure = behavior.maxBackpressure;
|
||||
webSocketContext->getExt()->closeOnBackpressureLimit = behavior.closeOnBackpressureLimit;
|
||||
webSocketContext->getExt()->resetIdleTimeoutOnSend = behavior.resetIdleTimeoutOnSend;
|
||||
@@ -215,7 +224,7 @@ public:
|
||||
webSocketContext->getExt()->compression = behavior.compression;
|
||||
|
||||
/* Calculate idleTimeoutCompnents */
|
||||
webSocketContext->getExt()->calculateIdleTimeoutCompnents();
|
||||
webSocketContext->getExt()->calculateIdleTimeoutCompnents(behavior.idleTimeout);
|
||||
|
||||
httpContext->onHttp("get", pattern, [webSocketContext, behavior = std::move(behavior)](auto *res, auto *req) mutable {
|
||||
|
||||
|
||||
+1
-1
@@ -300,7 +300,7 @@ public:
|
||||
}
|
||||
|
||||
/* Arm idleTimeout */
|
||||
us_socket_timeout(SSL, (us_socket_t *) webSocket, webSocketContextData->idleTimeout);
|
||||
us_socket_timeout(SSL, (us_socket_t *) webSocket, webSocketContextData->idleTimeoutComponents.first);
|
||||
|
||||
/* Move construct the UserData right before calling open handler */
|
||||
new (webSocket->getUserData()) UserData(std::move(userData));
|
||||
|
||||
@@ -57,7 +57,6 @@ public:
|
||||
|
||||
/* Settings for this context */
|
||||
size_t maxPayloadLength = 0;
|
||||
unsigned int idleTimeout = 0;
|
||||
|
||||
/* We do need these for async upgrade */
|
||||
CompressOptions compression;
|
||||
@@ -75,11 +74,11 @@ public:
|
||||
TopicTree topicTree;
|
||||
|
||||
/* This is run once on start-up */
|
||||
void calculateIdleTimeoutCompnents() {
|
||||
void calculateIdleTimeoutCompnents(unsigned short idleTimeout) {
|
||||
unsigned short margin = 4;
|
||||
/* 4, 8 or 16 seconds margin based on idleTimeout */
|
||||
while ((int) idleTimeout - margin * 2 >= margin * 2 && margin < 16) {
|
||||
margin *= 2;
|
||||
margin = (unsigned short) (margin << 2);
|
||||
}
|
||||
/* We should have no margin if not using sendPingsAutomatically */
|
||||
if (!sendPingsAutomatically) {
|
||||
|
||||
+1
-1
Submodule uSockets updated: 45a70140b1...6ae5e01f99
Reference in New Issue
Block a user