Carry over backpressure from Http to WS
This commit is contained in:
@@ -184,16 +184,11 @@ public:
|
||||
/* Add mark, we don't want to end anything */
|
||||
res->writeHeader("WebSocket-Server", "uWebSockets")->end();
|
||||
|
||||
/* bug: memory leak? What about HttpResponseData here? I'm thinking not delete it but destruct it? */
|
||||
/* Esp. if the functions hold dynamic memory like something big */
|
||||
/* Move any backpressure */
|
||||
std::string backpressure(std::move(((AsyncSocketData<SSL> *) res->getHttpResponseData())->buffer));
|
||||
|
||||
/* Vad om vi inte får plats i cork, och vi har vårt svar i corkbuffern */
|
||||
|
||||
/* vad om vi är en socket som har endat, men har svaret i sin buffer och strömmas ut? */
|
||||
|
||||
/* vi antar att vi kan bara kasta asyncsocketdata här */
|
||||
|
||||
/* res.end ska egentligen inte sätta att man svarat på den före den har drainats */
|
||||
/* Destroy HttpResponseData */
|
||||
res->getHttpResponseData()->~HttpResponseData();
|
||||
|
||||
/* Adopting a socket invalidates it, do not rely on it directly to carry any data */
|
||||
WebSocket<SSL, true> *webSocket = (WebSocket<SSL, true> *) StaticDispatch<SSL>::static_dispatch(us_ssl_socket_context_adopt_socket, us_socket_context_adopt_socket)(
|
||||
@@ -202,8 +197,9 @@ public:
|
||||
/* Update corked socket in case we got a new one (assuming we always are corked in handlers). */
|
||||
webSocket->cork();
|
||||
|
||||
/* Initialize websocket with any moved backpressure intact */
|
||||
httpContext->upgradeToWebSocket(
|
||||
webSocket->init(perMessageDeflate, slidingDeflateWindow)
|
||||
webSocket->init(perMessageDeflate, slidingDeflateWindow, std::move(backpressure))
|
||||
);
|
||||
|
||||
/* Emit open event and start the timeout */
|
||||
|
||||
@@ -26,6 +26,14 @@ template <bool SSL>
|
||||
struct AsyncSocketData {
|
||||
/* This will do for now */
|
||||
std::string buffer;
|
||||
|
||||
/* Allow move constructing us */
|
||||
AsyncSocketData(std::string &&backpressure) : buffer(std::move(backpressure)) {
|
||||
|
||||
}
|
||||
|
||||
/* Or emppty */
|
||||
AsyncSocketData() = default;
|
||||
};
|
||||
|
||||
#endif // ASYNCSOCKETDATA_H
|
||||
|
||||
@@ -39,6 +39,8 @@ static const int HTTP_TIMEOUT_S = 10;
|
||||
|
||||
template <bool SSL>
|
||||
struct HttpResponse : public AsyncSocket<SSL> {
|
||||
/* Solely used for getHttpResponseData() */
|
||||
template <bool> friend struct TemplatedApp;
|
||||
typedef AsyncSocket<SSL> Super;
|
||||
private:
|
||||
HttpResponseData<SSL> *getHttpResponseData() {
|
||||
|
||||
+2
-2
@@ -35,8 +35,8 @@ private:
|
||||
using SOCKET_CONTEXT_TYPE = typename StaticDispatch<SSL>::SOCKET_CONTEXT_TYPE;
|
||||
using StaticDispatch<SSL>::static_dispatch;
|
||||
|
||||
void *init(bool perMessageDeflate, bool slidingCompression) {
|
||||
new (static_dispatch(us_ssl_socket_ext, us_socket_ext)((SOCKET_TYPE *) this)) WebSocketData(perMessageDeflate, slidingCompression);
|
||||
void *init(bool perMessageDeflate, bool slidingCompression, std::string &&backpressure) {
|
||||
new (static_dispatch(us_ssl_socket_ext, us_socket_ext)((SOCKET_TYPE *) this)) WebSocketData(perMessageDeflate, slidingCompression, std::move(backpressure));
|
||||
return this;
|
||||
}
|
||||
public:
|
||||
|
||||
+1
-2
@@ -26,7 +26,6 @@
|
||||
|
||||
namespace uWS {
|
||||
|
||||
// take care with get_ext here !
|
||||
struct WebSocketData : AsyncSocketData<false>, WebSocketState<true> {
|
||||
template <bool, bool> friend struct WebSocketContext;
|
||||
template <bool, bool> friend struct WebSocket;
|
||||
@@ -43,7 +42,7 @@ private:
|
||||
/* We might have a dedicated compressor */
|
||||
DeflationStream *deflationStream = nullptr;
|
||||
public:
|
||||
WebSocketData(bool perMessageDeflate, bool slidingCompression) : WebSocketState<true>() {
|
||||
WebSocketData(bool perMessageDeflate, bool slidingCompression, std::string &&backpressure) : AsyncSocketData<false>(std::move(backpressure)), WebSocketState<true>() {
|
||||
compressionStatus = perMessageDeflate ? ENABLED : DISABLED;
|
||||
|
||||
/* Initialize the dedicated sliding window */
|
||||
|
||||
Reference in New Issue
Block a user