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 */
|
/* Add mark, we don't want to end anything */
|
||||||
res->writeHeader("WebSocket-Server", "uWebSockets")->end();
|
res->writeHeader("WebSocket-Server", "uWebSockets")->end();
|
||||||
|
|
||||||
/* bug: memory leak? What about HttpResponseData here? I'm thinking not delete it but destruct it? */
|
/* Move any backpressure */
|
||||||
/* Esp. if the functions hold dynamic memory like something big */
|
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 */
|
/* Destroy HttpResponseData */
|
||||||
|
res->getHttpResponseData()->~HttpResponseData();
|
||||||
/* 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 */
|
|
||||||
|
|
||||||
/* Adopting a socket invalidates it, do not rely on it directly to carry any data */
|
/* 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)(
|
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). */
|
/* Update corked socket in case we got a new one (assuming we always are corked in handlers). */
|
||||||
webSocket->cork();
|
webSocket->cork();
|
||||||
|
|
||||||
|
/* Initialize websocket with any moved backpressure intact */
|
||||||
httpContext->upgradeToWebSocket(
|
httpContext->upgradeToWebSocket(
|
||||||
webSocket->init(perMessageDeflate, slidingDeflateWindow)
|
webSocket->init(perMessageDeflate, slidingDeflateWindow, std::move(backpressure))
|
||||||
);
|
);
|
||||||
|
|
||||||
/* Emit open event and start the timeout */
|
/* Emit open event and start the timeout */
|
||||||
|
|||||||
@@ -26,6 +26,14 @@ template <bool SSL>
|
|||||||
struct AsyncSocketData {
|
struct AsyncSocketData {
|
||||||
/* This will do for now */
|
/* This will do for now */
|
||||||
std::string buffer;
|
std::string buffer;
|
||||||
|
|
||||||
|
/* Allow move constructing us */
|
||||||
|
AsyncSocketData(std::string &&backpressure) : buffer(std::move(backpressure)) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Or emppty */
|
||||||
|
AsyncSocketData() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ASYNCSOCKETDATA_H
|
#endif // ASYNCSOCKETDATA_H
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ static const int HTTP_TIMEOUT_S = 10;
|
|||||||
|
|
||||||
template <bool SSL>
|
template <bool SSL>
|
||||||
struct HttpResponse : public AsyncSocket<SSL> {
|
struct HttpResponse : public AsyncSocket<SSL> {
|
||||||
|
/* Solely used for getHttpResponseData() */
|
||||||
|
template <bool> friend struct TemplatedApp;
|
||||||
typedef AsyncSocket<SSL> Super;
|
typedef AsyncSocket<SSL> Super;
|
||||||
private:
|
private:
|
||||||
HttpResponseData<SSL> *getHttpResponseData() {
|
HttpResponseData<SSL> *getHttpResponseData() {
|
||||||
|
|||||||
+2
-2
@@ -35,8 +35,8 @@ private:
|
|||||||
using SOCKET_CONTEXT_TYPE = typename StaticDispatch<SSL>::SOCKET_CONTEXT_TYPE;
|
using SOCKET_CONTEXT_TYPE = typename StaticDispatch<SSL>::SOCKET_CONTEXT_TYPE;
|
||||||
using StaticDispatch<SSL>::static_dispatch;
|
using StaticDispatch<SSL>::static_dispatch;
|
||||||
|
|
||||||
void *init(bool perMessageDeflate, bool 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);
|
new (static_dispatch(us_ssl_socket_ext, us_socket_ext)((SOCKET_TYPE *) this)) WebSocketData(perMessageDeflate, slidingCompression, std::move(backpressure));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
|
|||||||
+1
-2
@@ -26,7 +26,6 @@
|
|||||||
|
|
||||||
namespace uWS {
|
namespace uWS {
|
||||||
|
|
||||||
// take care with get_ext here !
|
|
||||||
struct WebSocketData : AsyncSocketData<false>, WebSocketState<true> {
|
struct WebSocketData : AsyncSocketData<false>, WebSocketState<true> {
|
||||||
template <bool, bool> friend struct WebSocketContext;
|
template <bool, bool> friend struct WebSocketContext;
|
||||||
template <bool, bool> friend struct WebSocket;
|
template <bool, bool> friend struct WebSocket;
|
||||||
@@ -43,7 +42,7 @@ private:
|
|||||||
/* We might have a dedicated compressor */
|
/* We might have a dedicated compressor */
|
||||||
DeflationStream *deflationStream = nullptr;
|
DeflationStream *deflationStream = nullptr;
|
||||||
public:
|
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;
|
compressionStatus = perMessageDeflate ? ENABLED : DISABLED;
|
||||||
|
|
||||||
/* Initialize the dedicated sliding window */
|
/* Initialize the dedicated sliding window */
|
||||||
|
|||||||
Reference in New Issue
Block a user