Skip to content

Commit aaa653b

Browse files
committed
Updating test and api
1 parent eebbb83 commit aaa653b

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

Test/main.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
using namespace std::chrono_literals;
1313

1414
void wssautobahntest() {
15-
// auto listener = SL::WS_LITE::WSListener::CreateListener(3001, TEST_CERTIFICATE_PRIVATE_PASSWORD, TEST_CERTIFICATE_PRIVATE_PATH, TEST_CERTIFICATE_PUBLIC_PATH, TEST_DH_PATH);
16-
1715

1816
SL::WS_LITE::WSContext ctx(SL::WS_LITE::ThreadCount(1));
1917

@@ -77,7 +75,6 @@ void wssautobahntest() {
7775
}
7876
void generaltest() {
7977
std::cout << "Starting General test..." << std::endl;
80-
//auto listener = SL::WS_LITE::WSListener::CreateListener(3002, TEST_CERTIFICATE_PRIVATE_PASSWORD, TEST_CERTIFICATE_PRIVATE_PATH, TEST_CERTIFICATE_PUBLIC_PATH, TEST_DH_PATH);
8178

8279
SL::WS_LITE::PortNumber port(3002);
8380
SL::WS_LITE::WSContext ctx(SL::WS_LITE::ThreadCount(1));
@@ -109,8 +106,6 @@ void generaltest() {
109106
});
110107
listener.startlistening();
111108

112-
//auto client = SL::WS_LITE::WSClient::CreateClient(TEST_CERTIFICATE_PUBLIC_PATH);
113-
114109
auto client = ctx.CreateClient();
115110
client.onHttpUpgrade([&](const SL::WS_LITE::WSocket& socket) {
116111
lastheard = std::chrono::high_resolution_clock::now();
@@ -135,9 +130,9 @@ void multithreadtest() {
135130
std::cout << "Starting Multi threaded test..." << std::endl;
136131

137132
SL::WS_LITE::PortNumber port(3003);
138-
SL::WS_LITE::WSContext ctx(SL::WS_LITE::ThreadCount(4));
133+
SL::WS_LITE::WSContext listenerctx(SL::WS_LITE::ThreadCount(2));
139134

140-
auto listener = ctx.CreateListener(port);
135+
auto listener = listenerctx.CreateListener(port);
141136
auto lastheard = std::chrono::high_resolution_clock::now();
142137
listener.onHttpUpgrade([&](const SL::WS_LITE::WSocket& socket) {
143138
lastheard = std::chrono::high_resolution_clock::now();
@@ -160,10 +155,11 @@ void multithreadtest() {
160155
});
161156
listener.startlistening();
162157
std::vector<SL::WS_LITE::WSClient> clients;
163-
clients.reserve(100);
164-
for (auto i = 0; i < 100; i++) {
158+
SL::WS_LITE::WSContext clientctx(SL::WS_LITE::ThreadCount(2));
159+
clients.reserve(50);
160+
for (auto i = 0; i < 50; i++) {
165161

166-
clients.push_back(ctx.CreateClient());
162+
clients.push_back(clientctx.CreateClient());
167163
clients[i].onHttpUpgrade([&](const SL::WS_LITE::WSocket& socket) {
168164
lastheard = std::chrono::high_resolution_clock::now();
169165
});
@@ -197,7 +193,7 @@ void multithreadthroughputtest() {
197193
std::cout << "Starting Multi threaded throughput test" << std::endl;
198194

199195
SL::WS_LITE::PortNumber port(3004);
200-
SL::WS_LITE::WSContext listenerctx(SL::WS_LITE::ThreadCount(8));
196+
SL::WS_LITE::WSContext listenerctx(SL::WS_LITE::ThreadCount(2));
201197
std::vector<SL::WS_LITE::WSClient> clients;
202198
clients.reserve(50);//this should use about 1 GB of memory between sending and receiving
203199

@@ -228,7 +224,7 @@ void multithreadthroughputtest() {
228224

229225
std::atomic<unsigned long long> mbssent;
230226
mbssent = 0;
231-
SL::WS_LITE::WSContext clientctx(SL::WS_LITE::ThreadCount(8));
227+
SL::WS_LITE::WSContext clientctx(SL::WS_LITE::ThreadCount(2));
232228
auto sendtimer = std::chrono::high_resolution_clock::now();
233229
for (size_t i = 0; i < clients.capacity(); i++) {
234230

@@ -266,7 +262,7 @@ void multithreadthroughputtest() {
266262
std::cout << "Received " << mbsreceived<<" bytes"<< std::endl;
267263
}
268264
int main(int argc, char* argv[]) {
269-
wssautobahntest();
265+
//wssautobahntest();
270266
std::this_thread::sleep_for(1s);
271267
generaltest();
272268
std::this_thread::sleep_for(1s);

include/WS_Lite.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,19 @@ namespace SL {
5353
unsigned char *data;
5454
size_t len;
5555
OpCode code;
56+
//buffer is here to ensure the lifetime of the unsigned char *data in this structure
57+
//users should set the *data variable to be the beginning of the data to send. Then, set the Buffer shared ptr as well to make sure the lifetime of the data
5658
std::shared_ptr<unsigned char> Buffer;
5759
};
5860

59-
61+
class WSListener;
62+
class WSClient;
6063
struct WSocketImpl;
61-
struct WSocket {
64+
class WSocket {
6265
std::shared_ptr<WSocketImpl> WSocketImpl_;
63-
WSocket(const std::shared_ptr<WSocketImpl>& s) :WSocketImpl_(s){}
64-
WSocket() {}
66+
public:
67+
WSocket(const std::shared_ptr<WSocketImpl>& s) :WSocketImpl_(s) {}
68+
//WSocket() {}
6569
//can be used to compare two WSocket objects
6670
bool operator=(const WSocket& s) { return s.WSocketImpl_ == WSocketImpl_; }
6771
bool is_open();
@@ -71,7 +75,8 @@ namespace SL {
7175
bool is_v6();
7276
bool is_loopback();
7377
operator bool() const { return WSocketImpl_.operator bool(); }
74-
78+
friend WSListener;
79+
friend WSClient;
7580
};
7681
class WSContext;
7782
class WSListenerImpl;

0 commit comments

Comments
 (0)