mirror of
https://github.com/falk-werner/webfuse-provider
synced 2024-10-27 20:44:10 +00:00
let system choose port of test server
This commit is contained in:
parent
eb48dbecc5
commit
e72e78180e
@ -112,7 +112,7 @@ TEST(client, general_usage)
|
||||
|
||||
TEST(client, connect)
|
||||
{
|
||||
ThreadedWsServer server(54321);
|
||||
ThreadedWsServer server;
|
||||
|
||||
context ctx;
|
||||
ctx.state = connection_state::connecting;
|
||||
@ -120,7 +120,7 @@ TEST(client, connect)
|
||||
wf_client * client = wf_client_create(
|
||||
&callback2, reinterpret_cast<void*>(&ctx));
|
||||
|
||||
wf_client_connect(client, "ws://localhost:54321/");
|
||||
wf_client_connect(client, server.GetUrl().c_str());
|
||||
while (ctx.state != connection_state::connected)
|
||||
{
|
||||
wf_client_service(client);
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <chrono>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
#define TIMEOUT (std::chrono::milliseconds(10 * 1000))
|
||||
@ -35,6 +36,7 @@ public:
|
||||
explicit Private(int port);
|
||||
~Private();
|
||||
void WaitForConnection();
|
||||
std::string GetUrl() const;
|
||||
void OnConnected(lws * wsi) override;
|
||||
void OnConnectionClosed(lws * wsi) override;
|
||||
|
||||
@ -108,6 +110,12 @@ void ThreadedWsServer::WaitForConnection()
|
||||
d->WaitForConnection();
|
||||
}
|
||||
|
||||
std::string ThreadedWsServer::GetUrl() const
|
||||
{
|
||||
return d->GetUrl();
|
||||
}
|
||||
|
||||
|
||||
ThreadedWsServer::Private::Private(int port)
|
||||
: port_(port)
|
||||
, is_connected(false)
|
||||
@ -130,9 +138,13 @@ ThreadedWsServer::Private::Private(int port)
|
||||
info.vhost_name = "localhost";
|
||||
info.ws_ping_pong_interval = 10;
|
||||
info.options = LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE;
|
||||
info.options |= LWS_SERVER_OPTION_EXPLICIT_VHOSTS;
|
||||
|
||||
ws_context = lws_create_context(&info);
|
||||
|
||||
struct lws_vhost * vhost = lws_create_vhost(ws_context, &info);
|
||||
port_ = lws_get_vhost_port(vhost);
|
||||
|
||||
context = std::thread(&run, this);
|
||||
}
|
||||
|
||||
@ -193,5 +205,12 @@ void ThreadedWsServer::Private::OnConnectionClosed(lws * wsi)
|
||||
}
|
||||
}
|
||||
|
||||
std::string ThreadedWsServer::Private::GetUrl() const
|
||||
{
|
||||
std::ostringstream stream;
|
||||
stream << "ws://localhost:" << port_ << "/";
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <libwebsockets.h>
|
||||
#include <jansson.h>
|
||||
#include <string>
|
||||
|
||||
namespace webfuse_test
|
||||
{
|
||||
@ -12,9 +13,10 @@ class ThreadedWsServer
|
||||
ThreadedWsServer(ThreadedWsServer const &) = delete;
|
||||
ThreadedWsServer & operator=(ThreadedWsServer const &) = delete;
|
||||
public:
|
||||
explicit ThreadedWsServer(int port);
|
||||
explicit ThreadedWsServer(int port = 0);
|
||||
~ThreadedWsServer();
|
||||
void WaitForConnection();
|
||||
std::string GetUrl() const;
|
||||
private:
|
||||
class Private;
|
||||
Private * d;
|
||||
|
Loading…
Reference in New Issue
Block a user