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)
|
TEST(client, connect)
|
||||||
{
|
{
|
||||||
ThreadedWsServer server(54321);
|
ThreadedWsServer server;
|
||||||
|
|
||||||
context ctx;
|
context ctx;
|
||||||
ctx.state = connection_state::connecting;
|
ctx.state = connection_state::connecting;
|
||||||
@ -120,7 +120,7 @@ TEST(client, connect)
|
|||||||
wf_client * client = wf_client_create(
|
wf_client * client = wf_client_create(
|
||||||
&callback2, reinterpret_cast<void*>(&ctx));
|
&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)
|
while (ctx.state != connection_state::connected)
|
||||||
{
|
{
|
||||||
wf_client_service(client);
|
wf_client_service(client);
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
|
||||||
#define TIMEOUT (std::chrono::milliseconds(10 * 1000))
|
#define TIMEOUT (std::chrono::milliseconds(10 * 1000))
|
||||||
@ -35,6 +36,7 @@ public:
|
|||||||
explicit Private(int port);
|
explicit Private(int port);
|
||||||
~Private();
|
~Private();
|
||||||
void WaitForConnection();
|
void WaitForConnection();
|
||||||
|
std::string GetUrl() const;
|
||||||
void OnConnected(lws * wsi) override;
|
void OnConnected(lws * wsi) override;
|
||||||
void OnConnectionClosed(lws * wsi) override;
|
void OnConnectionClosed(lws * wsi) override;
|
||||||
|
|
||||||
@ -108,6 +110,12 @@ void ThreadedWsServer::WaitForConnection()
|
|||||||
d->WaitForConnection();
|
d->WaitForConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string ThreadedWsServer::GetUrl() const
|
||||||
|
{
|
||||||
|
return d->GetUrl();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ThreadedWsServer::Private::Private(int port)
|
ThreadedWsServer::Private::Private(int port)
|
||||||
: port_(port)
|
: port_(port)
|
||||||
, is_connected(false)
|
, is_connected(false)
|
||||||
@ -130,9 +138,13 @@ ThreadedWsServer::Private::Private(int port)
|
|||||||
info.vhost_name = "localhost";
|
info.vhost_name = "localhost";
|
||||||
info.ws_ping_pong_interval = 10;
|
info.ws_ping_pong_interval = 10;
|
||||||
info.options = LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE;
|
info.options = LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE;
|
||||||
|
info.options |= LWS_SERVER_OPTION_EXPLICIT_VHOSTS;
|
||||||
|
|
||||||
ws_context = lws_create_context(&info);
|
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);
|
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 <libwebsockets.h>
|
||||||
#include <jansson.h>
|
#include <jansson.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace webfuse_test
|
namespace webfuse_test
|
||||||
{
|
{
|
||||||
@ -12,9 +13,10 @@ class ThreadedWsServer
|
|||||||
ThreadedWsServer(ThreadedWsServer const &) = delete;
|
ThreadedWsServer(ThreadedWsServer const &) = delete;
|
||||||
ThreadedWsServer & operator=(ThreadedWsServer const &) = delete;
|
ThreadedWsServer & operator=(ThreadedWsServer const &) = delete;
|
||||||
public:
|
public:
|
||||||
explicit ThreadedWsServer(int port);
|
explicit ThreadedWsServer(int port = 0);
|
||||||
~ThreadedWsServer();
|
~ThreadedWsServer();
|
||||||
void WaitForConnection();
|
void WaitForConnection();
|
||||||
|
std::string GetUrl() const;
|
||||||
private:
|
private:
|
||||||
class Private;
|
class Private;
|
||||||
Private * d;
|
Private * d;
|
||||||
|
Loading…
Reference in New Issue
Block a user