Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.

Commit

Permalink
添加request notifier
Browse files Browse the repository at this point in the history
  • Loading branch information
EtherealAO committed Feb 8, 2022
1 parent f666e52 commit 98bc160
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/carrotjuicer/notifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,18 @@ namespace notifier
}
}
}
void notify_request(const std::string& data)
{
if (client == nullptr) {
init();
}

if (auto res = client->Post("/notify/request", data, "application/x-msgpack"))
{
if (res->status != 200)
{
std::cout << "Unexpected response from listener: " << res->status << "\n";
}
}
}
}
2 changes: 2 additions & 0 deletions src/carrotjuicer/notifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ namespace notifier
void init();

void notify_response(const std::string& data);

void notify_request(const std::string& data);
}
9 changes: 9 additions & 0 deletions src/hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ namespace
const int ret = reinterpret_cast<decltype(LZ4_compress_default_ext_hook)*>(LZ4_compress_default_ext_orig)(
src, dst, srcSize, dstCapacity);

const std::string data(src, srcSize);

auto notifier_thread = std::thread([&]
{
notifier::notify_request(data);
});

notifier_thread.join();

return ret;
}
void bootstrap_carrot_juicer()
Expand Down

0 comments on commit 98bc160

Please sign in to comment.