mirror of
https://github.com/CHN-beta/nixos.git
synced 2026-01-12 04:19:22 +08:00
init winjob
This commit is contained in:
17
flake.lock
generated
17
flake.lock
generated
@@ -1213,6 +1213,7 @@
|
||||
"rsshub": "rsshub",
|
||||
"rycee": "rycee",
|
||||
"slate": "slate",
|
||||
"sockpp": "sockpp",
|
||||
"sops-nix": "sops-nix",
|
||||
"sqlite-orm": "sqlite-orm",
|
||||
"tgbot-cpp": "tgbot-cpp",
|
||||
@@ -1269,6 +1270,22 @@
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"sockpp": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1707078447,
|
||||
"narHash": "sha256-lV3K6OGs4bFaCKKu1FeMwTMT5Q47Gxl+GzVf4rNnYjE=",
|
||||
"owner": "fpagliughi",
|
||||
"repo": "sockpp",
|
||||
"rev": "04002daccc8f66a77edf019124089a3ce966b2e3",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "fpagliughi",
|
||||
"repo": "sockpp",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"sops-nix": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
|
||||
@@ -63,6 +63,7 @@
|
||||
zxorm = { url = "github:CHN-beta/zxorm"; flake = false; };
|
||||
openxlsx = { url = "github:troldal/OpenXLSX"; flake = false; };
|
||||
sqlite-orm = { url = "github:fnc12/sqlite_orm"; flake = false; };
|
||||
sockpp = { url = "github:fpagliughi/sockpp"; flake = false; };
|
||||
|
||||
# does not support lfs yet
|
||||
# nixos-wallpaper = { url = "git+https://git.chn.moe/chn/nixos-wallpaper.git"; flake = false; };
|
||||
@@ -193,6 +194,12 @@
|
||||
buildInputs = [ pkgs.clang-tools_18 ];
|
||||
CMAKE_EXPORT_COMPILE_COMMANDS = "1";
|
||||
};
|
||||
winjob = pkgs.mkShell.override { stdenv = pkgs.gcc14Stdenv; }
|
||||
{
|
||||
inputsFrom = [ pkgs.localPackages.winjob ];
|
||||
buildInputs = [ pkgs.clang-tools_18 ];
|
||||
CMAKE_EXPORT_COMPILE_COMMANDS = "1";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -79,7 +79,8 @@ inputs: rec
|
||||
ufo = inputs.pkgs.callPackage ./ufo
|
||||
{ inherit concurrencpp biu glad matplotplusplus zpp-bits; tbb = inputs.pkgs.tbb_2021_11; };
|
||||
chn-bsub = inputs.pkgs.callPackage ./chn-bsub { inherit biu; };
|
||||
winjob = inputs.pkgs.callPackage ./winjob { inherit sqlite-orm; stdenv = inputs.pkgs.gcc14Stdenv; };
|
||||
winjob = inputs.pkgs.callPackage ./winjob { stdenv = inputs.pkgs.gcc14Stdenv; };
|
||||
sockpp = inputs.pkgs.callPackage ./sockpp.nix { src = inputs.topInputs.sockpp; };
|
||||
|
||||
fromYaml = content: builtins.fromJSON (builtins.readFile
|
||||
(inputs.pkgs.runCommand "toJSON" {}
|
||||
|
||||
7
local/pkgs/sockpp.nix
Normal file
7
local/pkgs/sockpp.nix
Normal file
@@ -0,0 +1,7 @@
|
||||
{ stdenv, src, cmake, pkg-config }: stdenv.mkDerivation
|
||||
{
|
||||
name = "sockpp";
|
||||
inherit src;
|
||||
nativeBuildInputs = [ cmake pkg-config ];
|
||||
buildInputs = [];
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
use flake .#hpcstat
|
||||
use flake .#winjob
|
||||
|
||||
@@ -13,7 +13,6 @@ endif()
|
||||
set(WINJOB_VERSION "unknown" CACHE STRING "Version of the winjob")
|
||||
|
||||
find_package(Boost REQUIRED COMPONENTS headers filesystem)
|
||||
find_package(SqliteOrm REQUIRED)
|
||||
find_package(nlohmann_json REQUIRED)
|
||||
find_package(range-v3 REQUIRED)
|
||||
|
||||
@@ -21,7 +20,7 @@ add_executable(winjob src/winjob.cpp)
|
||||
# target_compile_features(winjob PRIVATE cxx_std_26)
|
||||
target_compile_options(winjob PRIVATE "-std=c++26")
|
||||
target_include_directories(winjob PRIVATE ${PROJECT_SOURCE_DIR}/include)
|
||||
target_link_libraries(winjob PRIVATE Boost::headers Boost::filesystem sqlite_orm::sqlite_orm
|
||||
target_link_libraries(winjob PRIVATE Boost::headers Boost::filesystem
|
||||
nlohmann_json::nlohmann_json range-v3::range-v3)
|
||||
target_compile_definitions(winjob PRIVATE winjob_VERSION="${winjob_VERSION}")
|
||||
|
||||
@@ -29,7 +28,7 @@ add_executable(winjobd src/winjobd.cpp)
|
||||
# target_compile_features(winjob PRIVATE cxx_std_26)
|
||||
target_compile_options(winjobd PRIVATE "-std=c++26")
|
||||
target_include_directories(winjobd PRIVATE ${PROJECT_SOURCE_DIR}/include)
|
||||
target_link_libraries(winjobd PRIVATE Boost::headers Boost::filesystem sqlite_orm::sqlite_orm
|
||||
target_link_libraries(winjobd PRIVATE Boost::headers Boost::filesystem
|
||||
nlohmann_json::nlohmann_json range-v3::range-v3)
|
||||
target_compile_definitions(winjobd PRIVATE winjob_VERSION="${winjob_VERSION}")
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
stdenv, cmake, pkg-config, version ? null, lib,
|
||||
nlohmann_json, range-v3, sqlite-orm, boost
|
||||
nlohmann_json, range-v3, boost
|
||||
}: stdenv.mkDerivation
|
||||
{
|
||||
name = "winjob";
|
||||
src = ./.;
|
||||
buildInputs = [ nlohmann_json range-v3 sqlite-orm boost ];
|
||||
buildInputs = [ nlohmann_json range-v3 boost ];
|
||||
nativeBuildInputs = [ cmake pkg-config ];
|
||||
cmakeFlags = lib.optionals (version != null) [ "-DWINJOB_VERSION=${version}" ];
|
||||
}
|
||||
|
||||
@@ -1,4 +1,21 @@
|
||||
# include <boost/asio.hpp>
|
||||
# include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
}
|
||||
boost::asio::io_context io_context;
|
||||
boost::asio::local::stream_protocol::endpoint ep("/tmp/winjobd.sock");
|
||||
// send a message to the server
|
||||
boost::asio::local::stream_protocol::socket socket(io_context);
|
||||
socket.connect(ep);
|
||||
std::string message = "Hello, world!\n";
|
||||
boost::asio::write(socket, boost::asio::buffer(message));
|
||||
// receive a message from the server
|
||||
boost::asio::streambuf buf;
|
||||
boost::asio::read_until(socket, buf, '\n');
|
||||
std::istream is(&buf);
|
||||
std::string line;
|
||||
std::getline(is, line);
|
||||
std::cout << "Received: " << line << '\n';
|
||||
return 0;
|
||||
}
|
||||
@@ -1,4 +1,43 @@
|
||||
# include <boost/asio.hpp>
|
||||
# include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
boost::asio::io_context io_context;
|
||||
boost::asio::local::stream_protocol::endpoint ep("/tmp/winjobd.sock");
|
||||
boost::asio::local::stream_protocol::acceptor acceptor(io_context, ep);
|
||||
auto getuid = [](boost::asio::local::stream_protocol::socket& socket)
|
||||
{
|
||||
struct ucred ucred;
|
||||
socklen_t len = sizeof(ucred);
|
||||
if (getsockopt(socket.native_handle(), SOL_SOCKET, SO_PEERCRED, &ucred, &len) == -1)
|
||||
{
|
||||
std::cerr << "Failed to get SO_PEERCRED\n";
|
||||
return 0u;
|
||||
}
|
||||
return ucred.uid;
|
||||
};
|
||||
std::function<void(const boost::system::error_code&, boost::asio::local::stream_protocol::socket)> func =
|
||||
[&](const boost::system::error_code& ec, boost::asio::local::stream_protocol::socket socket)
|
||||
{
|
||||
if (ec)
|
||||
{
|
||||
std::cerr << "Failed to accept connection\n";
|
||||
return;
|
||||
}
|
||||
std::cout << "Accepted connection\n";
|
||||
boost::asio::streambuf buf;
|
||||
boost::asio::read_until(socket, buf, '\n');
|
||||
std::istream is(&buf);
|
||||
std::string line;
|
||||
std::getline(is, line);
|
||||
std::cout << "Received: " << line << '\n';
|
||||
std::cout << "Peer UID: " << getuid(socket) << '\n';
|
||||
// write a message to the client
|
||||
std::string message = "thanks for the message\n";
|
||||
boost::asio::write(socket, boost::asio::buffer(message));
|
||||
acceptor.async_accept(func);
|
||||
};
|
||||
acceptor.async_accept(func);
|
||||
io_context.run();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user