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;
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_complete_callback &worker_complete);
void remove_client(std::string_view client_id);
void remove_client(std::string client_id);
void shutdown();
};

View File

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

View File

@@ -32,11 +32,11 @@ using boost::asio::ip::tcp;
namespace repertory {
class packet_server final {
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_handler_callback = std::function<void(
std::uint32_t, std::string_view, std::uint64_t, std::string_view,
packet *, packet &, message_complete_callback)>;
using message_handler_callback =
std::function<void(std::uint32_t, std::string, std::uint64_t, std::string,
packet *, packet &, message_complete_callback)>;
public:
packet_server(std::uint16_t port, std::string token, std::uint8_t pool_size,
@@ -78,7 +78,7 @@ private:
std::unordered_map<std::string, std::uint32_t> connection_lookup_;
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;

View File

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

View File

@@ -130,7 +130,7 @@ void client_pool::pool::shutdown() {
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_complete_callback &worker_complete) {
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");
}
auto str_id = std::string{client_id};
if (not pool_lookup_[str_id]) {
pool_lookup_[str_id] = std::make_shared<pool>(pool_size_);
if (not pool_lookup_[client_id]) {
pool_lookup_[client_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();
}
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_);
pool_lookup_.erase(std::string{client_id});
pool_lookup_.erase(client_id);
}
void client_pool::shutdown() {

View File

@@ -72,15 +72,14 @@ 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;
recur_mutex_lock connection_lock(connection_mutex_);
auto str_id = std::string{client_id};
if (connection_lookup_.contains(str_id)) {
connection_lookup_.at(str_id)++;
if (connection_lookup_.contains(client_id)) {
connection_lookup_.at(client_id)++;
} 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,
std::uint8_t pool_size = 2)
: server_(std::make_unique<packet_server>(
port, std::move(token), pool_size,
[](std::string_view /*client_id*/) {},
[](std::uint32_t /*service_flags_in*/,
std::string_view /*client_id*/, std::uint64_t /*thread_id*/,
std::string_view method, packet * /*request*/,
packet & /*response*/,
port, std::move(token), pool_size, [](std::string /*client_id*/) {},
[](std::uint32_t /*service_flags_in*/, std::string /*client_id*/,
std::uint64_t /*thread_id*/, std::string method,
packet * /*request*/, packet & /*response*/,
packet_server::message_complete_callback done) {
if (method == "ping") {
done(packet::error_type{0});
@@ -132,11 +130,10 @@ TEST(packet_client_test, pooled_connection_reused_on_second_send) {
packet_server server{
port, token, 2U,
[&close_count](std::string_view /*client_id*/) { ++close_count; },
[](std::uint32_t /*service_flags_in*/, std::string_view /*client_id*/,
std::uint64_t /*thread_id*/, std::string_view method,
packet * /*request*/, packet & /*response*/,
packet_server::message_complete_callback done) {
[&close_count](std::string /*client_id*/) { ++close_count; },
[](std::uint32_t /*service_flags_in*/, std::string /*client_id*/,
std::uint64_t /*thread_id*/, std::string method, packet * /*request*/,
packet & /*response*/, packet_server::message_complete_callback done) {
if (method == "ping") {
done(packet::error_type{0});
} else {