Skip to content

Commit b7d8137

Browse files
committed
Cleaning the public API
1 parent 250d946 commit b7d8137

File tree

5 files changed

+32
-33
lines changed

5 files changed

+32
-33
lines changed

Test/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ void wssautobahntest() {
1515
SL::WS_LITE::ThreadCount thrdcount(1);
1616
SL::WS_LITE::PortNumber port(3001);
1717
auto listener = SL::WS_LITE::WSListener::CreateListener(thrdcount, port);
18-
listener.set_ReadTimeout(100);
19-
listener.set_WriteTimeout(100);
18+
listener.set_ReadTimeout(std::chrono::seconds(100));
19+
listener.set_WriteTimeout(std::chrono::seconds(100));
2020
auto lastheard = std::chrono::high_resolution_clock::now();
2121
listener.onHttpUpgrade([&](const SL::WS_LITE::WSocket& socket) {
2222
lastheard = std::chrono::high_resolution_clock::now();

include/WS_Lite.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <string>
44
#include <functional>
55
#include <unordered_map>
6+
#include <chrono>
67

78
namespace SL {
89
namespace WS_LITE {
@@ -108,13 +109,13 @@ namespace SL {
108109
//the maximum payload size
109110
unsigned long long int get_MaxPayload();
110111
//maximum time in seconds before a client is considered disconnected -- for reads
111-
void set_ReadTimeout(unsigned int seconds);
112+
void set_ReadTimeout(std::chrono::seconds seconds);
112113
//get the current read timeout in seconds
113-
unsigned int get_ReadTimeout();
114+
std::chrono::seconds get_ReadTimeout();
114115
//maximum time in seconds before a client is considered disconnected -- for writes
115-
void set_WriteTimeout(unsigned int seconds);
116+
void set_WriteTimeout(std::chrono::seconds seconds);
116117
//get the current write timeout in seconds
117-
unsigned int get_WriteTimeout();
118+
std::chrono::seconds get_WriteTimeout();
118119
//send a message to a specific client
119120
void send(const WSocket& s, WSMessage& msg, bool compressmessage);
120121
//send a close message and close the socket
@@ -165,13 +166,13 @@ namespace SL {
165166
//the maximum payload size
166167
unsigned long long int get_MaxPayload();
167168
//maximum time in seconds before a client is considered disconnected -- for reads
168-
void set_ReadTimeout(unsigned int seconds);
169+
void set_ReadTimeout(std::chrono::seconds seconds);
169170
//get the current read timeout in seconds
170-
unsigned int get_ReadTimeout();
171+
std::chrono::seconds get_ReadTimeout();
171172
//maximum time in seconds before a client is considered disconnected -- for writes
172-
void set_WriteTimeout(unsigned int seconds);
173+
void set_WriteTimeout(std::chrono::seconds seconds);
173174
//get the current write timeout in seconds
174-
unsigned int get_WriteTimeout();
175+
std::chrono::seconds get_WriteTimeout();
175176
//send a message to a specific client
176177
void send(const WSocket& s, WSMessage& msg, bool compressmessage);
177178
//send a close message and close the socket

include/internal/WebSocketProtocol.h

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ namespace SL {
169169
}
170170
Threads.clear();
171171
}
172-
unsigned int ReadTimeout = 30;
173-
unsigned int WriteTimeout = 30;
172+
std::chrono::seconds ReadTimeout = std::chrono::seconds(30);
173+
std::chrono::seconds WriteTimeout = std::chrono::seconds(30);
174174
size_t MaxPayload = 1024 * 1024 * 20;//20 MB
175175
asio::io_service io_service;
176176
std::vector<ThreadContext> Threads;
@@ -270,33 +270,33 @@ namespace SL {
270270
}
271271
};
272272

273-
template<class PARENTTYPE, class SOCKETTYPE> void readexpire_from_now(const std::shared_ptr<PARENTTYPE>& parent, const std::shared_ptr<WSocketImpl>& websocket, const SOCKETTYPE& socket, int seconds)
273+
template<class PARENTTYPE, class SOCKETTYPE> void readexpire_from_now(const std::shared_ptr<PARENTTYPE>& parent, const std::shared_ptr<WSocketImpl>& websocket, const SOCKETTYPE& socket, std::chrono::seconds secs)
274274
{
275275

276276
std::error_code ec;
277-
if (seconds <= 0) websocket->read_deadline.cancel(ec);
278-
else websocket->read_deadline.expires_from_now(std::chrono::seconds(seconds), ec);
277+
if (secs.count() <= 0) websocket->read_deadline.cancel(ec);
278+
else websocket->read_deadline.expires_from_now(secs, ec);
279279
if (ec) {
280280
SL_WS_LITE_LOG(Logging_Levels::ERROR_log_level, ec.message());
281281
}
282-
else if (seconds >= 0) {
282+
else if (secs.count() >= 0) {
283283
websocket->read_deadline.async_wait([parent, websocket, socket](const std::error_code& ec) {
284284
if (ec != asio::error::operation_aborted) {
285285
return closeImpl(parent, websocket, 1001, "read timer expired on the socket ");
286286
}
287287
});
288288
}
289289
}
290-
template<class PARENTTYPE, class SOCKETTYPE> void writeexpire_from_now(const std::shared_ptr<PARENTTYPE>& parent, const std::shared_ptr<WSocketImpl>& websocket, const SOCKETTYPE& socket, int seconds)
290+
template<class PARENTTYPE, class SOCKETTYPE> void writeexpire_from_now(const std::shared_ptr<PARENTTYPE>& parent, const std::shared_ptr<WSocketImpl>& websocket, const SOCKETTYPE& socket, std::chrono::seconds secs)
291291
{
292292
std::error_code ec;
293-
if (seconds <= 0) websocket->write_deadline.cancel(ec);
294-
else websocket->write_deadline.expires_from_now(std::chrono::seconds(seconds), ec);
293+
if (secs.count() <= 0) websocket->write_deadline.cancel(ec);
294+
else websocket->write_deadline.expires_from_now(secs, ec);
295295
if (ec) {
296296
SL_WS_LITE_LOG(Logging_Levels::ERROR_log_level, ec.message());
297297
}
298-
else if (seconds >= 0) {
299-
websocket->write_deadline.async_wait([parent, websocket, socket, seconds](const std::error_code& ec) {
298+
else if (secs.count() >= 0) {
299+
websocket->write_deadline.async_wait([parent, websocket, socket](const std::error_code& ec) {
300300
if (ec != asio::error::operation_aborted) {
301301
return closeImpl(parent, websocket, 1001, "write timer expired on the socket ");
302302
}
@@ -638,12 +638,10 @@ namespace SL {
638638
return closeImpl(parent, websocket, 1002, "Closing connection because mask requirement not met");
639639
}
640640

641-
if (getrsv2(websocket->ReceiveHeader) || getrsv3(websocket->ReceiveHeader)) {
642-
return closeImpl(parent, websocket, 1002, "Closing connection. rsv bit set");
643-
}
644-
if ((getrsv1(websocket->ReceiveHeader) && !websocket->CompressionEnabled)) {
641+
if (getrsv2(websocket->ReceiveHeader) || getrsv3(websocket->ReceiveHeader) ||(getrsv1(websocket->ReceiveHeader) && !websocket->CompressionEnabled)) {
645642
return closeImpl(parent, websocket, 1002, "Closing connection. rsv bit set");
646643
}
644+
647645
auto opcode = getOpCode(websocket->ReceiveHeader);
648646

649647
size_t size = getpayloadLength1(websocket->ReceiveHeader);

src/internal/ClientImpl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,16 +234,16 @@ namespace SL {
234234
void WSClient::onHttpUpgrade(const std::function<void(WSocket&)>& handle) {
235235
Impl_->onHttpUpgrade = handle;
236236
}
237-
void WSClient::set_ReadTimeout(unsigned int seconds) {
237+
void WSClient::set_ReadTimeout(std::chrono::seconds seconds) {
238238
Impl_->ReadTimeout = seconds;
239239
}
240-
unsigned int WSClient::get_ReadTimeout() {
240+
std::chrono::seconds WSClient::get_ReadTimeout() {
241241
return Impl_->ReadTimeout;
242242
}
243-
void WSClient::set_WriteTimeout(unsigned int seconds) {
243+
void WSClient::set_WriteTimeout(std::chrono::seconds seconds) {
244244
Impl_->WriteTimeout = seconds;
245245
}
246-
unsigned int WSClient::get_WriteTimeout() {
246+
std::chrono::seconds WSClient::get_WriteTimeout() {
247247
return Impl_->WriteTimeout;
248248
}
249249
void WSClient::set_MaxPayload(size_t bytes) {

src/internal/ListenerImpl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,16 @@ namespace SL {
173173
void WSListener::onHttpUpgrade(const std::function<void(WSocket&)>& handle) {
174174
Impl_->onHttpUpgrade = handle;
175175
}
176-
void WSListener::set_ReadTimeout(unsigned int seconds) {
176+
void WSListener::set_ReadTimeout(std::chrono::seconds seconds) {
177177
Impl_->ReadTimeout = seconds;
178178
}
179-
unsigned int WSListener::get_ReadTimeout() {
179+
std::chrono::seconds WSListener::get_ReadTimeout() {
180180
return Impl_->ReadTimeout;
181181
}
182-
void WSListener::set_WriteTimeout(unsigned int seconds) {
182+
void WSListener::set_WriteTimeout(std::chrono::seconds seconds) {
183183
Impl_->WriteTimeout = seconds;
184184
}
185-
unsigned int WSListener::get_WriteTimeout() {
185+
std::chrono::seconds WSListener::get_WriteTimeout() {
186186
return Impl_->WriteTimeout;
187187
}
188188
void WSListener::set_MaxPayload(size_t bytes) {

0 commit comments

Comments
 (0)