mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-11-24 20:31:50 +00:00
mark a websocket closed when a frame write fails
WebSocket::send_frame returned false when write_websocket_frame failed but left the connection open, and the Pong reply in read() ignored a failed write. A write that fails partway (the write timeout expiring while the peer is not reading) has already sent a frame header that announces the whole payload, so anything written after it is read by the peer as the rest of that frame, and a later payload's bytes as a frame of their own. Mark the connection closed on a failed write, as the heartbeat already does for its Ping, and send the Pong through send_frame.
This commit is contained in:
1 parent
277b1d62a4
commit
77b035c892
3 files changed
+67
-8
No files matched your search
+2
-1
@@ -129,7 +129,8 @@ Passed to the handler registered with `Server::WebSocket()`. The handler runs in
|
||||
// Read next message (blocks until received, returns Fail/Text/Binary/Timeout)
|
||||
ReadResult read(std::string &msg);
|
||||
|
||||
// Send messages
|
||||
// Send messages. A send that fails (e.g. the write timeout elapsed) closes the
|
||||
// connection, since part of the frame may already have gone out.
|
||||
bool send(const std::string &data); // Text
|
||||
bool send(const char *data, size_t len); // Binary
|
||||
|
||||
|
||||
Reference in new issue
Block a user