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 <bool, typename> friend struct WebSocketContextData;
|
||||||
template <typename, typename> friend struct TopicTree;
|
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:
|
protected:
|
||||||
/* Returns SSL pointer or FD as pointer */
|
/* Returns SSL pointer or FD as pointer */
|
||||||
void *getNativeHandle() {
|
void *getNativeHandle() {
|
||||||
@@ -77,23 +100,15 @@ protected:
|
|||||||
us_socket_shutdown(SSL, (us_socket_t *) this);
|
us_socket_shutdown(SSL, (us_socket_t *) this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Experimental pause (todo: move to uSockets as us_socket_pause) */
|
/* Experimental pause */
|
||||||
us_socket_t *uv_pause() {
|
us_socket_t *pause() {
|
||||||
struct us_poll_t *p = (struct us_poll_t *) this;
|
throttle_helper(1);
|
||||||
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);
|
|
||||||
return (us_socket_t *) this;
|
return (us_socket_t *) this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Experimental resume (kind of needs to know the size of write buffer) */
|
/* Experimental resume */
|
||||||
us_socket_t *uv_resume() {
|
us_socket_t *resume() {
|
||||||
struct us_poll_t *p = (struct us_poll_t *) this;
|
throttle_helper(0);
|
||||||
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);
|
|
||||||
return (us_socket_t *) this;
|
return (us_socket_t *) this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -332,13 +332,13 @@ public:
|
|||||||
|
|
||||||
/* Throttle reads and writes */
|
/* Throttle reads and writes */
|
||||||
HttpResponse *pause() {
|
HttpResponse *pause() {
|
||||||
Super::uv_pause();
|
Super::pause();
|
||||||
Super::timeout(0);
|
Super::timeout(0);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpResponse *resume() {
|
HttpResponse *resume() {
|
||||||
Super::uv_resume();
|
Super::resume();
|
||||||
Super::timeout(HTTP_TIMEOUT_S);
|
Super::timeout(HTTP_TIMEOUT_S);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user