Make pause/resume cross-backend
This commit is contained in:
+29
-14
@@ -51,6 +51,29 @@ struct AsyncSocket {
|
||||
template <bool, typename> friend struct WebSocketContextData;
|
||||
template <typename, typename> friend struct TopicTree;
|
||||
|
||||
private:
|
||||
/* Helper, do not use directly (todo: move to uSockets or de-crazify) */
|
||||
void throttle_helper(int toggle) {
|
||||
/* These should be exposed by uSockets */
|
||||
static thread_local int us_events[2] = {0, 0};
|
||||
|
||||
struct us_poll_t *p = (struct us_poll_t *) this;
|
||||
struct us_loop_t *loop = us_socket_context_loop(SSL, us_socket_context(SSL, (us_socket_t *) this));
|
||||
|
||||
if (toggle) {
|
||||
/* Pause */
|
||||
int events = us_poll_events(p);
|
||||
if (events) {
|
||||
us_events[getBufferedAmount() ? 1 : 0] = events;
|
||||
}
|
||||
us_poll_change(p, loop, 0);
|
||||
} else {
|
||||
/* Resume */
|
||||
int events = us_events[getBufferedAmount() ? 1 : 0];
|
||||
us_poll_change(p, loop, events);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
/* Returns SSL pointer or FD as pointer */
|
||||
void *getNativeHandle() {
|
||||
@@ -77,23 +100,15 @@ protected:
|
||||
us_socket_shutdown(SSL, (us_socket_t *) this);
|
||||
}
|
||||
|
||||
/* Experimental pause (todo: move to uSockets as us_socket_pause) */
|
||||
us_socket_t *uv_pause() {
|
||||
struct us_poll_t *p = (struct us_poll_t *) this;
|
||||
struct us_loop_t *loop = us_socket_context_loop(SSL, us_socket_context(SSL, (us_socket_t *) this));
|
||||
//int events = us_poll_events(p);
|
||||
us_poll_change(p, loop, 0);
|
||||
/* Experimental pause */
|
||||
us_socket_t *pause() {
|
||||
throttle_helper(1);
|
||||
return (us_socket_t *) this;
|
||||
}
|
||||
|
||||
/* Experimental resume (kind of needs to know the size of write buffer) */
|
||||
us_socket_t *uv_resume() {
|
||||
struct us_poll_t *p = (struct us_poll_t *) this;
|
||||
struct us_loop_t *loop = us_socket_context_loop(SSL, us_socket_context(SSL, (us_socket_t *) this));
|
||||
// only valid for libuv
|
||||
int events = getBufferedAmount() ? 1 | 2 : 1;
|
||||
|
||||
us_poll_change(p, loop, events);
|
||||
/* Experimental resume */
|
||||
us_socket_t *resume() {
|
||||
throttle_helper(0);
|
||||
return (us_socket_t *) this;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -332,13 +332,13 @@ public:
|
||||
|
||||
/* Throttle reads and writes */
|
||||
HttpResponse *pause() {
|
||||
Super::uv_pause();
|
||||
Super::pause();
|
||||
Super::timeout(0);
|
||||
return this;
|
||||
}
|
||||
|
||||
HttpResponse *resume() {
|
||||
Super::uv_resume();
|
||||
Super::resume();
|
||||
Super::timeout(HTTP_TIMEOUT_S);
|
||||
return this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user