Skip to content

Commit b7f1b7f

Browse files
committed
Updates
1 parent 280e582 commit b7f1b7f

File tree

5 files changed

+48
-59
lines changed

5 files changed

+48
-59
lines changed

Test/CMakeLists.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,7 @@ if(${BUILD_SHARED_LIBS})
3434

3535
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
3636
COMMAND ${CMAKE_COMMAND} -E copy_if_different
37-
$<TARGET_FILE:${OPENSSL_LIBRARIES}>
38-
$<TARGET_FILE_DIR:${PROJECT_NAME}>)
39-
40-
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
41-
COMMAND ${CMAKE_COMMAND} -E copy_if_different
42-
$<TARGET_FILE:${ZLIB_LIBRARIES}>
37+
$<TARGET_FILE:${COMMON_LIBRARIES}>
4338
$<TARGET_FILE_DIR:${PROJECT_NAME}>)
4439

4540
endif()

Test/fuzzingclient.json

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
{
2-
"options": {"failByDrop": false},
3-
"outdir": "../../Test/autobahn",
4-
"servers": [
5-
{"agent": "WebSockets SSL",
6-
"url": "wss://localhost:3001",
7-
"options": {"version": 18}},
8-
{"agent": "WebSockets",
9-
"url": "ws://localhost:3000",
10-
"options": {"version": 18}}
11-
],
2+
"options": { "failByDrop": false },
3+
"outdir": "../../Test/autobahn",
4+
"servers": [
5+
{
6+
{
7+
"agent": "WebSockets SSL",
8+
"url": "wss://localhost:3001",
9+
"options": { "version": 18 }
10+
},
11+
{
12+
"agent": "WebSockets",
13+
"url": "ws://localhost:3000",
14+
"options": { "version": 18 }
15+
},
1216

13-
"cases": ["1.*","2.*","3.*","4.*", "5.*", "6.*", "7.*", "9.*", "10.*"],
14-
"exclude-cases": [],
15-
"exclude-agent-cases": {}
16-
}
17+
18+
"cases": [ "1.*", "2.*", "3.*", "4.*", "5.*", "6.*", "7.*", "9.*", "10.*" ],
19+
"exclude-cases": [],
20+
"exclude-agent-cases": {}
21+
}

Test/main.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,13 @@ void multithreadthroughputtest()
415415
int main(int argc, char *argv[])
416416
{
417417
wssautobahntest();
418-
std::this_thread::sleep_for(1s);
419-
generaltest();
420-
std::this_thread::sleep_for(1s);
421-
generalTLStest();
422-
std::this_thread::sleep_for(1s);
423-
multithreadtest();
424-
std::this_thread::sleep_for(1s);
425-
multithreadthroughputtest();
418+
/* std::this_thread::sleep_for(1s);
419+
generaltest();
420+
std::this_thread::sleep_for(1s);
421+
generalTLStest();
422+
std::this_thread::sleep_for(1s);
423+
multithreadtest();
424+
std::this_thread::sleep_for(1s);
425+
multithreadthroughputtest();*/
426426
return 0;
427427
}

include/internal/WebSocketProtocol.h

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@
1010

1111
namespace SL {
1212
namespace WS_LITE {
13-
template <bool isServer, class SOCKETTYPE>
14-
void ReadHeaderNext(const std::shared_ptr<WSContextImpl> parent, const SOCKETTYPE &socket,
15-
const std::shared_ptr<asio::streambuf> &extradata);
1613
template <bool isServer, class SOCKETTYPE>
17-
void ReadHeaderStart(const std::shared_ptr<WSContextImpl> parent, const SOCKETTYPE &socket,
18-
const std::shared_ptr<asio::streambuf> &extradata);
14+
void ReadHeaderNext(const std::shared_ptr<WSContextImpl> parent, const SOCKETTYPE &socket, const std::shared_ptr<asio::streambuf> &extradata);
15+
template <bool isServer, class SOCKETTYPE>
16+
void ReadHeaderStart(const std::shared_ptr<WSContextImpl> parent, const SOCKETTYPE &socket, const std::shared_ptr<asio::streambuf> &extradata);
1917
template <bool isServer, class SOCKETTYPE, class SENDBUFFERTYPE>
2018
void write_end(const std::shared_ptr<WSContextImpl> parent, const SOCKETTYPE &socket, const SENDBUFFERTYPE &msg);
21-
19+
2220
template <bool isServer, class SOCKETTYPE>
2321
void readexpire_from_now(const std::shared_ptr<WSContextImpl> parent, const SOCKETTYPE &socket, std::chrono::seconds secs)
2422
{
@@ -82,7 +80,7 @@ template <bool isServer, class SOCKETTYPE>
8280
});
8381
}
8482
}
85-
83+
8684
template <bool isServer, class SOCKETTYPE, class SENDBUFFERTYPE>
8785
void writeend(const std::shared_ptr<WSContextImpl> parent, const SOCKETTYPE &socket, const SENDBUFFERTYPE &msg, bool iserver)
8886
{
@@ -245,7 +243,6 @@ template <bool isServer, class SOCKETTYPE>
245243
}));
246244
}
247245

248-
249246
inline void UnMaskMessage(size_t readsize, unsigned char *buffer, bool isserver)
250247
{
251248
if (isserver) {
@@ -483,10 +480,9 @@ template <bool isServer, class SOCKETTYPE>
483480
return sendclosemessage<isServer>(parent, socket, 1002, "Closing connection. nonvalid op code");
484481
}
485482
}
486-
483+
487484
template <bool isServer, class SOCKETTYPE>
488-
void ReadHeaderNext(const std::shared_ptr<WSContextImpl> parent, const SOCKETTYPE &socket,
489-
const std::shared_ptr<asio::streambuf> &extradata)
485+
void ReadHeaderNext(const std::shared_ptr<WSContextImpl> parent, const SOCKETTYPE &socket, const std::shared_ptr<asio::streambuf> &extradata)
490486
{
491487
readexpire_from_now<isServer>(parent, socket, parent->ReadTimeout);
492488
size_t dataconsumed = 0;
@@ -498,46 +494,40 @@ template <bool isServer, class SOCKETTYPE>
498494
else if (extradata->size() == 1) {
499495
dataconsumed = 1;
500496
}
501-
else {
502-
dataconsumed = 0;
503-
}
504497
// zero is not possible
505498
bytestoread -= dataconsumed;
506499
memcpy(socket->ReceiveHeader, asio::buffer_cast<const void *>(extradata->data()), dataconsumed);
507500
extradata->consume(dataconsumed);
508501

509502
asio::async_read(socket->Socket, asio::buffer(socket->ReceiveHeader + dataconsumed, bytestoread),
510-
[parent, socket, extradata](const std::error_code &ec, size_t) {
503+
[parent, socket, extradata](const std::error_code &ec, size_t readdata) {
511504
if (!ec) {
512-
size_t readbytes = getpayloadLength1(socket->ReceiveHeader);
513-
switch (readbytes) {
505+
size_t bytestoread = getpayloadLength1(socket->ReceiveHeader);
506+
switch (bytestoread) {
514507
case 126:
515-
readbytes = 2;
508+
bytestoread = 2;
516509
break;
517510
case 127:
518-
readbytes = 8;
511+
bytestoread = 8;
519512
break;
520513
default:
521-
readbytes = 0;
514+
bytestoread = 0;
522515
}
523-
if (readbytes > 1) {
516+
if (bytestoread > 1) {
524517
size_t dataconsumed = 0;
525-
size_t bytestoread = 2;
526518
if (extradata->size() > 1) {
527519
dataconsumed = 2;
528520
}
529521
else if (extradata->size() == 1) {
530522
dataconsumed = 1;
531523
}
532-
else {
533-
dataconsumed = 0;
534-
}
535524
bytestoread -= dataconsumed;
536525
memcpy(socket->ReceiveHeader + 2, asio::buffer_cast<const void *>(extradata->data()), dataconsumed);
537526
extradata->consume(dataconsumed);
527+
memset(socket->ReceiveHeader + 2, 255, 2);
538528

539529
asio::async_read(socket->Socket, asio::buffer(socket->ReceiveHeader + 2 + dataconsumed, bytestoread),
540-
[parent, socket, extradata](const std::error_code &ec, size_t) {
530+
[parent, socket, extradata](const std::error_code &ec, size_t readdata) {
541531
if (!ec) {
542532
ReadBody<isServer>(parent, socket, extradata);
543533
}
@@ -557,8 +547,7 @@ template <bool isServer, class SOCKETTYPE>
557547
});
558548
}
559549
template <bool isServer, class SOCKETTYPE>
560-
void ReadHeaderStart(const std::shared_ptr<WSContextImpl> parent, const SOCKETTYPE &socket,
561-
const std::shared_ptr<asio::streambuf> &extradata)
550+
void ReadHeaderStart(const std::shared_ptr<WSContextImpl> parent, const SOCKETTYPE &socket, const std::shared_ptr<asio::streambuf> &extradata)
562551
{
563552
free(socket->ReceiveBuffer);
564553
socket->ReceiveBuffer = nullptr;
@@ -567,7 +556,6 @@ template <bool isServer, class SOCKETTYPE>
567556
ReadHeaderNext<isServer>(parent, socket, extradata);
568557
}
569558

570-
571559
class WSClient : public IWSHub {
572560
std::shared_ptr<WSContextImpl> Impl_;
573561

src/ListenerImpl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ namespace WS_LITE {
3535
if (!ec) {
3636
SL_WS_LITE_LOG(Logging_Levels::INFO_log_level,
3737
"Connected: Sent Handshake bytes " << bytes_transferred);
38-
socket->SocketStatus_ = SocketStatus::CONNECTED;
39-
start_ping<true>(listener, socket, std::chrono::seconds(5));
38+
4039
if (listener->onConnection) {
4140
listener->onConnection(socket, handshakecontainer->Header);
4241
}
4342
auto bufptr = std::make_shared<asio::streambuf>();
4443
ReadHeaderStart<true>(listener, socket, bufptr);
44+
socket->SocketStatus_ = SocketStatus::CONNECTED;
45+
start_ping<true>(listener, socket, std::chrono::seconds(5));
4546
}
4647
else {
4748
socket->SocketStatus_ = SocketStatus::CLOSED;

0 commit comments

Comments
 (0)