Send TCP FIN from HttpContext if WebSocket FIN sent
This commit is contained in:
+11
-1
@@ -24,6 +24,7 @@
|
|||||||
#include "HttpContextData.h"
|
#include "HttpContextData.h"
|
||||||
#include "HttpResponseData.h"
|
#include "HttpResponseData.h"
|
||||||
#include "AsyncSocket.h"
|
#include "AsyncSocket.h"
|
||||||
|
#include "WebSocketData.h"
|
||||||
|
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -250,7 +251,16 @@ private:
|
|||||||
AsyncSocket<SSL> *asyncSocket = (AsyncSocket<SSL> *) httpContextData->upgradedWebSocket;
|
AsyncSocket<SSL> *asyncSocket = (AsyncSocket<SSL> *) httpContextData->upgradedWebSocket;
|
||||||
|
|
||||||
/* Uncork here as well (note: what if we failed to uncork and we then pub/sub before we even upgraded?) */
|
/* Uncork here as well (note: what if we failed to uncork and we then pub/sub before we even upgraded?) */
|
||||||
/*auto [written, failed] = */asyncSocket->uncork();
|
auto [written, failed] = asyncSocket->uncork();
|
||||||
|
|
||||||
|
/* If we succeeded in uncorking, check if we have sent WebSocket FIN */
|
||||||
|
if (!failed) {
|
||||||
|
WebSocketData *webSocketData = (WebSocketData *) asyncSocket->getAsyncSocketData();
|
||||||
|
if (webSocketData->isShuttingDown) {
|
||||||
|
/* In that case, also send TCP FIN (this is similar to what we have in ws drain handler) */
|
||||||
|
asyncSocket->shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Reset upgradedWebSocket before we return */
|
/* Reset upgradedWebSocket before we return */
|
||||||
httpContextData->upgradedWebSocket = nullptr;
|
httpContextData->upgradedWebSocket = nullptr;
|
||||||
|
|||||||
@@ -302,6 +302,10 @@ private:
|
|||||||
/* Handle HTTP write out (note: SSL_read may trigger this spuriously, the app need to handle spurious calls) */
|
/* Handle HTTP write out (note: SSL_read may trigger this spuriously, the app need to handle spurious calls) */
|
||||||
us_socket_context_on_writable(SSL, getSocketContext(), [](auto *s) {
|
us_socket_context_on_writable(SSL, getSocketContext(), [](auto *s) {
|
||||||
|
|
||||||
|
/* NOTE: Are we called here corked? If so, the below write code is broken, since
|
||||||
|
* we will have 0 as getBufferedAmount due to writing to cork buffer, then sending TCP FIN before
|
||||||
|
* we actually uncorked and sent off things */
|
||||||
|
|
||||||
/* It makes sense to check for us_is_shut_down here and return if so, to avoid shutting down twice */
|
/* It makes sense to check for us_is_shut_down here and return if so, to avoid shutting down twice */
|
||||||
if (us_socket_is_shut_down(SSL, (us_socket_t *) s)) {
|
if (us_socket_is_shut_down(SSL, (us_socket_t *) s)) {
|
||||||
return s;
|
return s;
|
||||||
|
|||||||
@@ -28,9 +28,11 @@
|
|||||||
namespace uWS {
|
namespace uWS {
|
||||||
|
|
||||||
struct WebSocketData : AsyncSocketData<false>, WebSocketState<true> {
|
struct WebSocketData : AsyncSocketData<false>, WebSocketState<true> {
|
||||||
|
/* This guy has a lot of friends - why? */
|
||||||
template <bool, bool> friend struct WebSocketContext;
|
template <bool, bool> friend struct WebSocketContext;
|
||||||
template <bool> friend struct WebSocketContextData;
|
template <bool> friend struct WebSocketContextData;
|
||||||
template <bool, bool> friend struct WebSocket;
|
template <bool, bool> friend struct WebSocket;
|
||||||
|
template <bool> friend struct HttpContext;
|
||||||
private:
|
private:
|
||||||
std::string fragmentBuffer;
|
std::string fragmentBuffer;
|
||||||
int controlTipLength = 0;
|
int controlTipLength = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user