WebSocket::send returns SendStatus now

This commit is contained in:
Alex Hultman
2021-02-19 07:37:17 +01:00
parent d13aac1af8
commit 26b7f8c7a6
+13 -6
View File
@@ -56,8 +56,15 @@ public:
/* Simple, immediate close of the socket. Emits close event */ /* Simple, immediate close of the socket. Emits close event */
using Super::close; using Super::close;
/* Send or buffer a WebSocket frame, compressed or not. Returns false on increased user space backpressure. */ enum SendStatus : int {
bool send(std::string_view message, uWS::OpCode opCode = uWS::OpCode::BINARY, bool compress = false) { BACKPRESSURE,
SUCCESS,
DROPPED
};
/* Send or buffer a WebSocket frame, compressed or not. Returns BACKPRESSURE on increased user space backpressure,
* DROPPED on dropped message (due to backpressure) or SUCCCESS if you are free to send even more now. */
SendStatus send(std::string_view message, uWS::OpCode opCode = uWS::OpCode::BINARY, bool compress = false) {
WebSocketContextData<SSL> *webSocketContextData = (WebSocketContextData<SSL> *) us_socket_context_ext(SSL, WebSocketContextData<SSL> *webSocketContextData = (WebSocketContextData<SSL> *) us_socket_context_ext(SSL,
(us_socket_context_t *) us_socket_context(SSL, (us_socket_t *) this) (us_socket_context_t *) us_socket_context(SSL, (us_socket_t *) this)
); );
@@ -68,7 +75,7 @@ public:
if (webSocketContextData->closeOnBackpressureLimit) { if (webSocketContextData->closeOnBackpressureLimit) {
us_socket_shutdown_read(SSL, (us_socket_t *) this); us_socket_shutdown_read(SSL, (us_socket_t *) this);
} }
return true; return DROPPED;
} }
/* Transform the message to compressed domain if requested */ /* Transform the message to compressed domain if requested */
@@ -109,7 +116,7 @@ public:
if (failed) { if (failed) {
/* Return false for failure, skipping to reset the timeout below */ /* Return false for failure, skipping to reset the timeout below */
return false; return BACKPRESSURE;
} }
} }
@@ -117,7 +124,7 @@ public:
if (automaticallyCorked) { if (automaticallyCorked) {
auto [written, failed] = Super::uncork(); auto [written, failed] = Super::uncork();
if (failed) { if (failed) {
return false; return BACKPRESSURE;
} }
} }
@@ -129,7 +136,7 @@ public:
} }
/* Return success */ /* Return success */
return true; return SUCCESS;
} }
/* Send websocket close frame, emit close event, send FIN if successful. /* Send websocket close frame, emit close event, send FIN if successful.