fix remote server

This commit is contained in:
2025-10-01 20:41:34 -05:00
parent 8dbb0d9fd9
commit 4bee40228d
7 changed files with 430 additions and 438 deletions

View File

@@ -97,11 +97,11 @@ private:
static constexpr auto min_pool_size = 10U; static constexpr auto min_pool_size = 10U;
public: public:
void execute(std::string_view client_id, std::uint64_t thread_id, void execute(std::string client_id, std::uint64_t thread_id,
const worker_callback &worker, const worker_callback &worker,
const worker_complete_callback &worker_complete); const worker_complete_callback &worker_complete);
void remove_client(std::string_view client_id); void remove_client(std::string client_id);
void shutdown(); void shutdown();
}; };

View File

@@ -122,8 +122,8 @@ auto run_with_deadline(boost::asio::io_context &ctx,
} }
state_ptr->timer.cancel(); state_ptr->timer.cancel();
while (ctx.poll_one() > 0) { // while (ctx.poll_one() > 0) {
} // }
state_ptr->work_guard.reset(); state_ptr->work_guard.reset();

View File

@@ -32,10 +32,10 @@ using boost::asio::ip::tcp;
namespace repertory { namespace repertory {
class packet_server final { class packet_server final {
public: public:
using closed_callback = std::function<void(std::string_view)>; using closed_callback = std::function<void(std::string)>;
using message_complete_callback = client_pool::worker_complete_callback; using message_complete_callback = client_pool::worker_complete_callback;
using message_handler_callback = std::function<void( using message_handler_callback =
std::uint32_t, std::string_view, std::uint64_t, std::string_view, std::function<void(std::uint32_t, std::string, std::uint64_t, std::string,
packet *, packet &, message_complete_callback)>; packet *, packet &, message_complete_callback)>;
public: public:
@@ -78,7 +78,7 @@ private:
std::unordered_map<std::string, std::uint32_t> connection_lookup_; std::unordered_map<std::string, std::uint32_t> connection_lookup_;
private: private:
void add_client(connection &conn, std::string_view client_id); void add_client(connection &conn, std::string client_id);
[[nodiscard]] auto handshake(std::shared_ptr<connection> conn) const -> bool; [[nodiscard]] auto handshake(std::shared_ptr<connection> conn) const -> bool;

View File

@@ -46,8 +46,8 @@ class remote_server_base : public remote_open_file_table,
public virtual remote_fuse::i_remote_instance { public virtual remote_fuse::i_remote_instance {
public: public:
using handler_callback = std::function<packet::error_type( using handler_callback = std::function<packet::error_type(
std::uint32_t, std::string_view, std::uint64_t, std::string_view, std::uint32_t, std::string, std::uint64_t, std::string, packet *,
packet *, packet &)>; packet &)>;
public: public:
remote_server_base(const remote_server_base &) = delete; remote_server_base(const remote_server_base &) = delete;
@@ -103,8 +103,7 @@ private:
std::unique_ptr<packet_server> packet_server_; std::unique_ptr<packet_server> packet_server_;
private: private:
const std::unordered_map<std::string_view, handler_callback> handler_lookup_ = const std::unordered_map<std::string, handler_callback> handler_lookup_ = {
{
{ {
"::check", "::check",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
@@ -115,40 +114,40 @@ private:
{ {
"::fuse_access", "::fuse_access",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto && /* response */) -> auto { auto && /* response */) -> auto {
return this->handle_fuse_access(request); return this->handle_fuse_access(request);
}, },
}, },
{ {
"::fuse_chflags", "::fuse_chflags",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto && /* response */) -> auto { auto && /* response */) -> auto {
return this->handle_fuse_chflags(request); return this->handle_fuse_chflags(request);
}, },
}, },
{ {
"::fuse_chmod", "::fuse_chmod",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto && /* response */) -> auto { auto && /* response */) -> auto {
return this->handle_fuse_chmod(request); return this->handle_fuse_chmod(request);
}, },
}, },
{ {
"::fuse_chown", "::fuse_chown",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto && /* response */) -> auto { auto && /* response */) -> auto {
return this->handle_fuse_chown(request); return this->handle_fuse_chown(request);
}, },
}, },
{ {
"::fuse_create", "::fuse_create",
[this](auto && /* service_flags */, auto &&client_id, [this](auto && /* service_flags */, auto &&client_id,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto &&response) -> auto { auto &&response) -> auto {
return this->handle_fuse_create(client_id, request, response); return this->handle_fuse_create(client_id, request, response);
}, },
}, },
@@ -163,48 +162,48 @@ private:
{ {
"::fuse_fgetattr", "::fuse_fgetattr",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto &&response) -> auto { auto &&response) -> auto {
return this->handle_fuse_fgetattr(request, response); return this->handle_fuse_fgetattr(request, response);
}, },
}, },
{ {
"::fuse_fsetattr_x", "::fuse_fsetattr_x",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto && /* response */) -> auto { auto && /* response */) -> auto {
return this->handle_fuse_fsetattr_x(request); return this->handle_fuse_fsetattr_x(request);
}, },
}, },
{ {
"::fuse_fsync", "::fuse_fsync",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto && /* response */) -> auto { auto && /* response */) -> auto {
return this->handle_fuse_fsync(request); return this->handle_fuse_fsync(request);
}, },
}, },
{ {
"::fuse_ftruncate", "::fuse_ftruncate",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto && /* response */) -> auto { auto && /* response */) -> auto {
return this->handle_fuse_ftruncate(request); return this->handle_fuse_ftruncate(request);
}, },
}, },
{ {
"::fuse_getattr", "::fuse_getattr",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto &&response) -> auto { auto &&response) -> auto {
return this->handle_fuse_getattr(request, response); return this->handle_fuse_getattr(request, response);
}, },
}, },
{ {
"::fuse_getxtimes", "::fuse_getxtimes",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto &&response) -> auto { auto &&response) -> auto {
return this->handle_fuse_getxtimes(request, response); return this->handle_fuse_getxtimes(request, response);
}, },
}, },
@@ -219,176 +218,176 @@ private:
{ {
"::fuse_mkdir", "::fuse_mkdir",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto && /* response */) -> auto { auto && /* response */) -> auto {
return this->handle_fuse_mkdir(request); return this->handle_fuse_mkdir(request);
}, },
}, },
{ {
"::fuse_open", "::fuse_open",
[this](auto && /* service_flags */, auto &&client_id, [this](auto && /* service_flags */, auto &&client_id,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto &&response) -> auto { auto &&response) -> auto {
return this->handle_fuse_open(client_id, request, response); return this->handle_fuse_open(client_id, request, response);
}, },
}, },
{ {
"::fuse_opendir", "::fuse_opendir",
[this](auto && /* service_flags */, auto &&client_id, [this](auto && /* service_flags */, auto &&client_id,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto &&response) -> auto { auto &&response) -> auto {
return this->handle_fuse_opendir(client_id, request, response); return this->handle_fuse_opendir(client_id, request, response);
}, },
}, },
{ {
"::fuse_read", "::fuse_read",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto &&response) -> auto { auto &&response) -> auto {
return this->handle_fuse_read(request, response); return this->handle_fuse_read(request, response);
}, },
}, },
{ {
"::fuse_readdir", "::fuse_readdir",
[this](auto && /* service_flags */, auto &&client_id, [this](auto && /* service_flags */, auto &&client_id,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto &&response) -> auto { auto &&response) -> auto {
return this->handle_fuse_readdir(client_id, request, response); return this->handle_fuse_readdir(client_id, request, response);
}, },
}, },
{ {
"::fuse_release", "::fuse_release",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto && /* response */) -> auto { auto && /* response */) -> auto {
return this->handle_fuse_release(request); return this->handle_fuse_release(request);
}, },
}, },
{ {
"::fuse_releasedir", "::fuse_releasedir",
[this](auto && /* service_flags */, auto &&client_id, [this](auto && /* service_flags */, auto &&client_id,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto && /* response */) -> auto { auto && /* response */) -> auto {
return this->handle_fuse_releasedir(client_id, request); return this->handle_fuse_releasedir(client_id, request);
}, },
}, },
{ {
"::fuse_rename", "::fuse_rename",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto && /* response */) -> auto { auto && /* response */) -> auto {
return this->handle_fuse_rename(request); return this->handle_fuse_rename(request);
}, },
}, },
{ {
"::fuse_rmdir", "::fuse_rmdir",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto && /* response */) -> auto { auto && /* response */) -> auto {
return this->handle_fuse_rmdir(request); return this->handle_fuse_rmdir(request);
}, },
}, },
{ {
"::fuse_setattr_x", "::fuse_setattr_x",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto && /* response */) -> auto { auto && /* response */) -> auto {
return this->handle_fuse_setattr_x(request); return this->handle_fuse_setattr_x(request);
}, },
}, },
{ {
"::fuse_setbkuptime", "::fuse_setbkuptime",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto && /* response */) -> auto { auto && /* response */) -> auto {
return this->handle_fuse_setbkuptime(request); return this->handle_fuse_setbkuptime(request);
}, },
}, },
{ {
"::fuse_setchgtime", "::fuse_setchgtime",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto && /* response */) -> auto { auto && /* response */) -> auto {
return this->handle_fuse_setchgtime(request); return this->handle_fuse_setchgtime(request);
}, },
}, },
{ {
"::fuse_setcrtime", "::fuse_setcrtime",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto && /* response */) -> auto { auto && /* response */) -> auto {
return this->handle_fuse_setcrtime(request); return this->handle_fuse_setcrtime(request);
}, },
}, },
{ {
"::fuse_setvolname", "::fuse_setvolname",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto && /* response */) -> auto { auto && /* response */) -> auto {
return this->handle_fuse_setvolname(request); return this->handle_fuse_setvolname(request);
}, },
}, },
{ {
"::fuse_statfs", "::fuse_statfs",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto &&response) -> auto { auto &&response) -> auto {
return this->handle_fuse_statfs(request, response); return this->handle_fuse_statfs(request, response);
}, },
}, },
{ {
"::fuse_statfs_x", "::fuse_statfs_x",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto &&response) -> auto { auto &&response) -> auto {
return this->handle_fuse_statfs_x(request, response); return this->handle_fuse_statfs_x(request, response);
}, },
}, },
{ {
"::fuse_truncate", "::fuse_truncate",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto && /* response */) -> auto { auto && /* response */) -> auto {
return this->handle_fuse_truncate(request); return this->handle_fuse_truncate(request);
}, },
}, },
{ {
"::fuse_unlink", "::fuse_unlink",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto && /* response */) -> auto { auto && /* response */) -> auto {
return this->handle_fuse_unlink(request); return this->handle_fuse_unlink(request);
}, },
}, },
{ {
"::fuse_utimens", "::fuse_utimens",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto && /* response */) -> auto { auto && /* response */) -> auto {
return this->handle_fuse_utimens(request); return this->handle_fuse_utimens(request);
}, },
}, },
{ {
"::fuse_write", "::fuse_write",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto && /* response */) -> auto { auto && /* response */) -> auto {
return this->handle_fuse_write(request); return this->handle_fuse_write(request);
}, },
}, },
{ {
"::fuse_write_base64", "::fuse_write_base64",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto && /* response */) -> auto { auto && /* response */) -> auto {
return this->handle_fuse_write_base64(request); return this->handle_fuse_write_base64(request);
}, },
}, },
{ {
"::json_create_directory_snapshot", "::json_create_directory_snapshot",
[this](auto && /* service_flags */, auto &&client_id, [this](auto && /* service_flags */, auto &&client_id,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto &&response) -> auto { auto &&response) -> auto {
return this->handle_json_create_directory_snapshot( return this->handle_json_create_directory_snapshot(
client_id, request, response); client_id, request, response);
}, },
@@ -396,17 +395,17 @@ private:
{ {
"::json_read_directory_snapshot", "::json_read_directory_snapshot",
[this](auto && /* service_flags */, auto &&client_id, [this](auto && /* service_flags */, auto &&client_id,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto &&response) -> auto { auto &&response) -> auto {
return this->handle_json_read_directory_snapshot( return this->handle_json_read_directory_snapshot(client_id, request,
client_id, request, response); response);
}, },
}, },
{ {
"::json_release_directory_snapshot", "::json_release_directory_snapshot",
[this](auto && /* service_flags */, auto &&client_id, [this](auto && /* service_flags */, auto &&client_id,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto && /* response */) -> auto { auto && /* response */) -> auto {
return this->handle_json_release_directory_snapshot(client_id, return this->handle_json_release_directory_snapshot(client_id,
request); request);
}, },
@@ -414,58 +413,57 @@ private:
{ {
"::winfsp_can_delete", "::winfsp_can_delete",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto && /* response */) -> auto { auto && /* response */) -> auto {
return this->handle_winfsp_can_delete(request); return this->handle_winfsp_can_delete(request);
}, },
}, },
{ {
"::winfsp_cleanup", "::winfsp_cleanup",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto &&response) -> auto { auto &&response) -> auto {
return this->handle_winfsp_cleanup(request, response); return this->handle_winfsp_cleanup(request, response);
}, },
}, },
{ {
"::winfsp_close", "::winfsp_close",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto && /* response */) -> auto { auto && /* response */) -> auto {
return this->handle_winfsp_close(request); return this->handle_winfsp_close(request);
}, },
}, },
{ {
"::winfsp_create", "::winfsp_create",
[this](auto && /* service_flags */, auto &&client_id, [this](auto && /* service_flags */, auto &&client_id,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto &&response) -> auto { auto &&response) -> auto {
return this->handle_winfsp_create(client_id, request, response); return this->handle_winfsp_create(client_id, request, response);
}, },
}, },
{ {
"::winfsp_flush", "::winfsp_flush",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto &&response) -> auto { auto &&response) -> auto {
return this->handle_winfsp_flush(request, response); return this->handle_winfsp_flush(request, response);
}, },
}, },
{ {
"::winfsp_get_file_info", "::winfsp_get_file_info",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto &&response) -> auto { auto &&response) -> auto {
return this->handle_winfsp_get_file_info(request, response); return this->handle_winfsp_get_file_info(request, response);
}, },
}, },
{ {
"::winfsp_get_security_by_name", "::winfsp_get_security_by_name",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto &&response) -> auto { auto &&response) -> auto {
return this->handle_winfsp_get_security_by_name(request, return this->handle_winfsp_get_security_by_name(request, response);
response);
}, },
}, },
{ {
@@ -479,87 +477,87 @@ private:
{ {
"::winfsp_mounted", "::winfsp_mounted",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto && /* response */) -> auto { auto && /* response */) -> auto {
return this->handle_winfsp_mounted(request); return this->handle_winfsp_mounted(request);
}, },
}, },
{ {
"::winfsp_open", "::winfsp_open",
[this](auto && /* service_flags */, auto &&client_id, [this](auto && /* service_flags */, auto &&client_id,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto &&response) -> auto { auto &&response) -> auto {
return this->handle_winfsp_open(client_id, request, response); return this->handle_winfsp_open(client_id, request, response);
}, },
}, },
{ {
"::winfsp_overwrite", "::winfsp_overwrite",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto &&response) -> auto { auto &&response) -> auto {
return this->handle_winfsp_overwrite(request, response); return this->handle_winfsp_overwrite(request, response);
}, },
}, },
{ {
"::winfsp_read", "::winfsp_read",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto &&response) -> auto { auto &&response) -> auto {
return this->handle_winfsp_read(request, response); return this->handle_winfsp_read(request, response);
}, },
}, },
{ {
"::winfsp_read_directory", "::winfsp_read_directory",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto &&response) -> auto { auto &&response) -> auto {
return this->handle_winfsp_read_directory(request, response); return this->handle_winfsp_read_directory(request, response);
}, },
}, },
{ {
"::winfsp_rename", "::winfsp_rename",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto && /* response */) -> auto { auto && /* response */) -> auto {
return this->handle_winfsp_rename(request); return this->handle_winfsp_rename(request);
}, },
}, },
{ {
"::winfsp_set_basic_info", "::winfsp_set_basic_info",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto &&response) -> auto { auto &&response) -> auto {
return this->handle_winfsp_set_basic_info(request, response); return this->handle_winfsp_set_basic_info(request, response);
}, },
}, },
{ {
"::winfsp_set_file_size", "::winfsp_set_file_size",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto &&response) -> auto { auto &&response) -> auto {
return this->handle_winfsp_set_file_size(request, response); return this->handle_winfsp_set_file_size(request, response);
}, },
}, },
{ {
"::winfsp_unmounted", "::winfsp_unmounted",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto && /* response */) -> auto { auto && /* response */) -> auto {
return this->handle_winfsp_unmounted(request); return this->handle_winfsp_unmounted(request);
}, },
}, },
{ {
"::winfsp_write", "::winfsp_write",
[this](auto && /* service_flags */, auto && /* client_id */, [this](auto && /* service_flags */, auto && /* client_id */,
auto && /* thread_id */, auto && /* method */, auto && /* thread_id */, auto && /* method */, auto &&request,
auto &&request, auto &&response) -> auto { auto &&response) -> auto {
return this->handle_winfsp_write(request, response); return this->handle_winfsp_write(request, response);
}, },
}, },
}; };
private: private:
void closed_handler(std::string_view client_id) { void closed_handler(std::string client_id) {
client_pool_.remove_client(client_id); client_pool_.remove_client(client_id);
close_all(client_id); close_all(client_id);
} }
@@ -1615,14 +1613,13 @@ private:
} }
void void
message_handler(std::uint32_t service_flags, std::string_view client_id, message_handler(std::uint32_t service_flags, std::string client_id,
std::uint64_t thread_id, std::string_view method, std::uint64_t thread_id, std::string method, packet *request,
packet *request, packet &response, packet &response,
packet_server::message_complete_callback message_complete) { packet_server::message_complete_callback message_complete) {
auto idx{method.find_last_of("::")}; auto idx{method.find_last_of("::")};
auto lookup_method_name{ auto lookup_method_name{
((idx == std::string::npos) ? "::" + std::string{method} ((idx == std::string::npos) ? "::" + method : method.substr(idx - 1)),
: method.substr(idx - 1)),
}; };
if (handler_lookup_.find(lookup_method_name) == handler_lookup_.end()) { if (handler_lookup_.find(lookup_method_name) == handler_lookup_.end()) {
message_complete(static_cast<packet::error_type>(STATUS_NOT_IMPLEMENTED)); message_complete(static_cast<packet::error_type>(STATUS_NOT_IMPLEMENTED));

View File

@@ -130,7 +130,7 @@ void client_pool::pool::shutdown() {
pool_threads_.clear(); pool_threads_.clear();
} }
void client_pool::execute(std::string_view client_id, std::uint64_t thread_id, void client_pool::execute(std::string client_id, std::uint64_t thread_id,
const worker_callback &worker, const worker_callback &worker,
const worker_complete_callback &worker_complete) { const worker_complete_callback &worker_complete) {
unique_mutex_lock pool_lock(pool_mutex_); unique_mutex_lock pool_lock(pool_mutex_);
@@ -139,18 +139,17 @@ void client_pool::execute(std::string_view client_id, std::uint64_t thread_id,
throw std::runtime_error("Client pool is shutdown"); throw std::runtime_error("Client pool is shutdown");
} }
auto str_id = std::string{client_id}; if (not pool_lookup_[client_id]) {
if (not pool_lookup_[str_id]) { pool_lookup_[client_id] = std::make_shared<pool>(pool_size_);
pool_lookup_[str_id] = std::make_shared<pool>(pool_size_);
} }
pool_lookup_[str_id]->execute(thread_id, worker, worker_complete); pool_lookup_[client_id]->execute(thread_id, worker, worker_complete);
pool_lock.unlock(); pool_lock.unlock();
} }
void client_pool::remove_client(std::string_view client_id) { void client_pool::remove_client(std::string client_id) {
mutex_lock pool_lock(pool_mutex_); mutex_lock pool_lock(pool_mutex_);
pool_lookup_.erase(std::string{client_id}); pool_lookup_.erase(client_id);
} }
void client_pool::shutdown() { void client_pool::shutdown() {

View File

@@ -72,15 +72,14 @@ packet_server::~packet_server() {
"packet_server"); "packet_server");
} }
void packet_server::add_client(connection &conn, std::string_view client_id) { void packet_server::add_client(connection &conn, std::string client_id) {
conn.client_id = client_id; conn.client_id = client_id;
recur_mutex_lock connection_lock(connection_mutex_); recur_mutex_lock connection_lock(connection_mutex_);
auto str_id = std::string{client_id}; if (connection_lookup_.contains(client_id)) {
if (connection_lookup_.contains(str_id)) { connection_lookup_.at(client_id)++;
connection_lookup_.at(str_id)++;
} else { } else {
connection_lookup_[str_id] = 1U; connection_lookup_[client_id] = 1U;
} }
} }

View File

@@ -38,12 +38,10 @@ public:
test_packet_server(std::uint16_t port, std::string token, test_packet_server(std::uint16_t port, std::string token,
std::uint8_t pool_size = 2) std::uint8_t pool_size = 2)
: server_(std::make_unique<packet_server>( : server_(std::make_unique<packet_server>(
port, std::move(token), pool_size, port, std::move(token), pool_size, [](std::string /*client_id*/) {},
[](std::string_view /*client_id*/) {}, [](std::uint32_t /*service_flags_in*/, std::string /*client_id*/,
[](std::uint32_t /*service_flags_in*/, std::uint64_t /*thread_id*/, std::string method,
std::string_view /*client_id*/, std::uint64_t /*thread_id*/, packet * /*request*/, packet & /*response*/,
std::string_view method, packet * /*request*/,
packet & /*response*/,
packet_server::message_complete_callback done) { packet_server::message_complete_callback done) {
if (method == "ping") { if (method == "ping") {
done(packet::error_type{0}); done(packet::error_type{0});
@@ -132,11 +130,10 @@ TEST(packet_client_test, pooled_connection_reused_on_second_send) {
packet_server server{ packet_server server{
port, token, 2U, port, token, 2U,
[&close_count](std::string_view /*client_id*/) { ++close_count; }, [&close_count](std::string /*client_id*/) { ++close_count; },
[](std::uint32_t /*service_flags_in*/, std::string_view /*client_id*/, [](std::uint32_t /*service_flags_in*/, std::string /*client_id*/,
std::uint64_t /*thread_id*/, std::string_view method, std::uint64_t /*thread_id*/, std::string method, packet * /*request*/,
packet * /*request*/, packet & /*response*/, packet & /*response*/, packet_server::message_complete_callback done) {
packet_server::message_complete_callback done) {
if (method == "ping") { if (method == "ping") {
done(packet::error_type{0}); done(packet::error_type{0});
} else { } else {