Skip to content

Commit 542e3f7

Browse files
committed
Adding buffered data bytes
1 parent 5f6a859 commit 542e3f7

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

.appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ install:
1515
- ps: If ($env:Platform -Match "x86"){ $env:CMAKE_ARCH="" } Else { $env:CMAKE_ARCH=" Win64"}
1616
- mkdir C:\projects\deps
1717
- cd C:\projects\deps
18-
- set CMAKE_URL="https://cmake.org/files/v3.9/cmake-3.9.3-win64-x64.zip"
18+
- set CMAKE_URL="https://cmake.org/files/v3.9/cmake-3.9.4-win64-x64.zip"
1919
- appveyor DownloadFile %CMAKE_URL% -FileName cmake.zip
2020
- 7z x cmake.zip -oC:\projects\deps > nul
2121
- move C:\projects\deps\cmake-* C:\projects\deps\cmake # Move to a version-agnostic directory

include/WS_Lite.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ namespace WS_LITE {
170170
virtual bool is_v4() const = 0;
171171
virtual bool is_v6() const = 0;
172172
virtual bool is_loopback() const = 0;
173+
virtual size_t BufferedBytes() const = 0;
173174
virtual void send(const WSMessage &msg, CompressionOptions compressmessage) = 0;
174175
// send a close message and close the socket
175176
virtual void close(unsigned short code = 1000, const std::string &msg = "") = 0;

include/internal/DataStructures.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,14 @@ namespace WS_LITE {
139139
free(ReceiveBuffer);
140140
}
141141
}
142-
virtual SocketStatus is_open() const { return SocketStatus_; }
143-
virtual std::string get_address() const { return SL::WS_LITE::get_address(Socket); }
144-
virtual unsigned short get_port() const { return SL::WS_LITE::get_port(Socket); }
145-
virtual bool is_v4() const { return SL::WS_LITE::is_v4(Socket); }
146-
virtual bool is_v6() const { return SL::WS_LITE::is_v6(Socket); }
147-
virtual bool is_loopback() const { return SL::WS_LITE::is_loopback(Socket); }
148-
virtual void send(const WSMessage &msg, CompressionOptions compressmessage)
142+
virtual SocketStatus is_open() const override { return SocketStatus_; }
143+
virtual std::string get_address() const override { return SL::WS_LITE::get_address(Socket); }
144+
virtual unsigned short get_port() const override { return SL::WS_LITE::get_port(Socket); }
145+
virtual bool is_v4() const override { return SL::WS_LITE::is_v4(Socket); }
146+
virtual bool is_v6() const override { return SL::WS_LITE::is_v6(Socket); }
147+
virtual size_t BufferedBytes() const override { return Bytes_PendingFlush; }
148+
virtual bool is_loopback() const override { return SL::WS_LITE::is_loopback(Socket); }
149+
virtual void send(const WSMessage &msg, CompressionOptions compressmessage) override
149150
{
150151
if (SocketStatus_ == SocketStatus::CONNECTED) { // only send to a conected socket
151152
auto self(std::static_pointer_cast<WSocket<isServer, SOCKETTYPE>>(shared_from_this()));
@@ -156,7 +157,7 @@ namespace WS_LITE {
156157
}
157158
}
158159
// send a close message and close the socket
159-
virtual void close(unsigned short code, const std::string &msg)
160+
virtual void close(unsigned short code, const std::string &msg) override
160161
{
161162
if (SocketStatus_ == SocketStatus::CONNECTED) { // only send a close to an open socket
162163
auto self(std::static_pointer_cast<WSocket<isServer, SOCKETTYPE>>(shared_from_this()));
@@ -184,6 +185,7 @@ namespace WS_LITE {
184185
OpCode LastOpCode = OpCode::INVALID;
185186
std::shared_ptr<WSContextImpl> Parent;
186187
SOCKETTYPE Socket;
188+
size_t Bytes_PendingFlush = 0;
187189

188190
asio::basic_waitable_timer<std::chrono::steady_clock> ping_deadline;
189191
asio::basic_waitable_timer<std::chrono::steady_clock> read_deadline;

include/internal/WebSocketProtocol.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ namespace WS_LITE {
203203
if (msg.code == OpCode::CLOSE) {
204204
socket->SocketStatus_ = SocketStatus::CLOSING;
205205
}
206+
socket->Bytes_PendingFlush += msg.len;
206207
socket->SendMessageQueue.emplace_back(SendQueueItem{msg, compressmessage});
207208
SL::WS_LITE::startwrite<isServer>(parent, socket);
208209
}
@@ -248,6 +249,10 @@ namespace WS_LITE {
248249
socket->strand.wrap([parent, socket, msg](const std::error_code &ec, size_t bytes_transferred) {
249250
socket->Writing = false;
250251
UNUSED(bytes_transferred);
252+
253+
socket->Bytes_PendingFlush -= msg.len;
254+
255+
SL_WS_LITE_LOG(Logging_Levels::INFO_log_level, "socket->Bytes_PendingFlush: " << socket->Bytes_PendingFlush);
251256
if (msg.code == OpCode::CLOSE) {
252257
// final close.. get out and dont come back mm kay?
253258
return handleclose(parent, socket, 1000, "");

0 commit comments

Comments
 (0)