mirror of
https://github.com/falk-werner/webfuse-provider
synced 2026-03-02 04:09:18 +00:00
fixed unit tests; added logging support; allow to specify filesystem name
This commit is contained in:
@@ -101,12 +101,10 @@ public:
|
||||
info.mounts = NULL;
|
||||
info.protocols = protocols;
|
||||
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_EXPLICIT_VHOSTS;
|
||||
|
||||
context = lws_create_context(&info);
|
||||
|
||||
if (use_tls)
|
||||
{
|
||||
info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
|
||||
@@ -114,9 +112,11 @@ public:
|
||||
info.ssl_private_key_filepath = "server-key.pem";
|
||||
}
|
||||
|
||||
context = lws_create_context(&info);
|
||||
|
||||
struct lws_vhost * vhost = lws_create_vhost(context, &info);
|
||||
int port = lws_get_vhost_port(vhost);
|
||||
std::ostringstream stream;
|
||||
std::ostringstream stream;
|
||||
stream << (use_tls ? "wss://" : "ws://") << "localhost:" << port << "/";
|
||||
url = stream.str();
|
||||
|
||||
@@ -149,7 +149,7 @@ public:
|
||||
std::string Invoke(std::string const & method, std::string const & params)
|
||||
{
|
||||
std::promise<std::string> response;
|
||||
{
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
message = &response;
|
||||
id++;
|
||||
@@ -220,7 +220,7 @@ public:
|
||||
lws_callback_on_writable(wsi);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
wfp_impl_json_doc_dispose(doc);
|
||||
}
|
||||
}
|
||||
@@ -337,4 +337,4 @@ std::string WebfuseServer::ReadDir(int inode)
|
||||
return d->Invoke("readdir", params.str());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,10 @@ class WsServer::Private : IServer
|
||||
Private(Private const &) = delete;
|
||||
Private & operator=(Private const &) = delete;
|
||||
public:
|
||||
Private(std::string const & protocol, int port);
|
||||
Private(
|
||||
std::string const & protocol,
|
||||
std::function<void(std::string const &)> handleMessage,
|
||||
int port);
|
||||
~Private();
|
||||
bool IsConnected();
|
||||
std::string GetUrl() const;
|
||||
@@ -45,6 +48,7 @@ public:
|
||||
private:
|
||||
static void run(Private * self);
|
||||
std::string protocol_;
|
||||
std::function<void(std::string const &)> handleMessage_;
|
||||
int port_;
|
||||
bool is_connected;
|
||||
bool is_shutdown_requested;
|
||||
@@ -55,7 +59,6 @@ private:
|
||||
std::thread context;
|
||||
std::mutex mutex;
|
||||
std::queue<std::string> writeQueue;
|
||||
std::queue<std::string> recvQueue;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -107,8 +110,11 @@ static int wfp_test_utils_ws_server_callback(
|
||||
namespace webfuse_test
|
||||
{
|
||||
|
||||
WsServer::WsServer(std::string const & protocol, int port)
|
||||
: d(new Private(protocol, port))
|
||||
WsServer::WsServer(
|
||||
std::string const & protocol,
|
||||
std::function<void(std::string const &)> handleMessage,
|
||||
int port)
|
||||
: d(new Private(protocol, handleMessage, port))
|
||||
{
|
||||
|
||||
}
|
||||
@@ -128,19 +134,18 @@ void WsServer::SendMessage(std::string const & message)
|
||||
d->SendMessage(message);
|
||||
}
|
||||
|
||||
std::string WsServer::ReceiveMessage()
|
||||
{
|
||||
return d->ReceiveMessage();
|
||||
}
|
||||
|
||||
std::string WsServer::GetUrl() const
|
||||
{
|
||||
return d->GetUrl();
|
||||
}
|
||||
|
||||
|
||||
WsServer::Private::Private(std::string const & protocol, int port)
|
||||
WsServer::Private::Private(
|
||||
std::string const & protocol,
|
||||
std::function<void(std::string const &)> handleMessage,
|
||||
int port)
|
||||
: protocol_(protocol)
|
||||
, handleMessage_(handleMessage)
|
||||
, port_(port)
|
||||
, is_connected(false)
|
||||
, is_shutdown_requested(false)
|
||||
@@ -160,7 +165,7 @@ WsServer::Private::Private(std::string const & protocol, int port)
|
||||
info.mounts = NULL;
|
||||
info.protocols =ws_protocols;
|
||||
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_EXPLICIT_VHOSTS;
|
||||
|
||||
@@ -270,25 +275,16 @@ void WsServer::Private::SendMessage(std::string const & message)
|
||||
|
||||
void WsServer::Private::OnMessageReceived(struct lws * wsi, char const * data, size_t length)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
if (wsi == wsi_)
|
||||
bool handleMessage;
|
||||
{
|
||||
recvQueue.push(std::string(data, length));
|
||||
}
|
||||
}
|
||||
|
||||
std::string WsServer::Private::ReceiveMessage()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
|
||||
std::string message;
|
||||
if (!recvQueue.empty())
|
||||
{
|
||||
message = recvQueue.front();
|
||||
recvQueue.pop();
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
handleMessage = (wsi == wsi_);
|
||||
}
|
||||
|
||||
return message;
|
||||
if (handleMessage)
|
||||
{
|
||||
handleMessage_(std::string(data, length));
|
||||
}
|
||||
}
|
||||
|
||||
std::string WsServer::Private::GetUrl() const
|
||||
@@ -299,4 +295,4 @@ std::string WsServer::Private::GetUrl() const
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define WFP_TEST_UTILS_WS_SERVER_HPP
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
namespace webfuse_test
|
||||
{
|
||||
@@ -11,12 +12,14 @@ class WsServer
|
||||
WsServer(WsServer const &) = delete;
|
||||
WsServer & operator=(WsServer const &) = delete;
|
||||
public:
|
||||
WsServer(std::string const & protocol, int port = 0);
|
||||
WsServer(
|
||||
std::string const & protocol,
|
||||
std::function<void(std::string const &)> handleMessage,
|
||||
int port = 0);
|
||||
~WsServer();
|
||||
bool IsConnected();
|
||||
std::string GetUrl() const;
|
||||
void SendMessage(std::string const & message);
|
||||
std::string ReceiveMessage();
|
||||
private:
|
||||
class Private;
|
||||
Private * d;
|
||||
|
||||
Reference in New Issue
Block a user