From af403dfb33057b3fcb9947926f3de4e101a5a57a Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Wed, 17 Apr 2024 13:29:58 +0530 Subject: [PATCH 1/5] Updating the ipc client based on the new framework --- test/xipc_client.hpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test/xipc_client.hpp diff --git a/test/xipc_client.hpp b/test/xipc_client.hpp new file mode 100644 index 0000000..4e8d7f5 --- /dev/null +++ b/test/xipc_client.hpp @@ -0,0 +1,29 @@ +/*************************************************************************** +* Copyright (c) 2016, Johan Mabille and Sylvain Corlay * +* * +* Distributed under the terms of the BSD 3-Clause License. * +* * +* The full license is in the file LICENSE, distributed with this software. * +****************************************************************************/ + +#ifndef XEUS_IPC_CLIENT_HPP +#define XEUS_IPC_CLIENT_HPP + +#include "xeus-zmq/xclient_zmq.hpp" + +namespace xeus +{ + class xipc_client : public xclient_zmq + { + + public: + + // TODO + + private: + + // TODO + }; +} + +#endif From 878383c3141d69dd78015b036809d75c56cbda88 Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Wed, 17 Apr 2024 14:23:18 +0530 Subject: [PATCH 2/5] using composition --- test/client_ipc.cpp | 4 ++-- test/xipc_client.cpp | 19 +++++++++++++++++++ test/xipc_client.hpp | 9 ++++----- 3 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 test/xipc_client.cpp diff --git a/test/client_ipc.cpp b/test/client_ipc.cpp index 763e0b0..5158103 100644 --- a/test/client_ipc.cpp +++ b/test/client_ipc.cpp @@ -11,7 +11,7 @@ // tested in the CI but was here for trying to reproduce // some issue with IPC. -/*#include +#include #include "zmq_addon.hpp" #include "nlohmann/json.hpp" @@ -58,5 +58,5 @@ int main(int, char**) std::cout << resp.content().dump(4) << std::endl; return 0; -}*/ +} diff --git a/test/xipc_client.cpp b/test/xipc_client.cpp new file mode 100644 index 0000000..6d56aea --- /dev/null +++ b/test/xipc_client.cpp @@ -0,0 +1,19 @@ +/*************************************************************************** +* Copyright (c) 2016, Johan Mabille and Sylvain Corlay * +* * +* Distributed under the terms of the BSD 3-Clause License. * +* * +* The full license is in the file LICENSE, distributed with this software. * +****************************************************************************/ + +#include "xipc_client.hpp" + +namespace xeus +{ + + xipc_client::xipc_client(xcontext& context, const xconfiguration& config) + : p_client(make_xclient_zmq(context, config)) + { + // Additional initialization if needed + } +} \ No newline at end of file diff --git a/test/xipc_client.hpp b/test/xipc_client.hpp index 4e8d7f5..67ef8e3 100644 --- a/test/xipc_client.hpp +++ b/test/xipc_client.hpp @@ -13,16 +13,15 @@ namespace xeus { - class xipc_client : public xclient_zmq + class xipc_client { - public: + using client_ptr = std::unique_ptr; - // TODO + xipc_client(xcontext& context, const xconfiguration& config); private: - - // TODO + client_ptr p_client; }; } From f934e4c331f5d9ad30b241effc1e467c371e7a2a Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Thu, 18 Apr 2024 11:37:58 +0530 Subject: [PATCH 3/5] Processing execute request through the ipc client --- test/client_ipc.cpp | 45 +++++++++++++++++++++++--------------------- test/xipc_client.cpp | 11 ++++++++++- test/xipc_client.hpp | 3 +++ 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/test/client_ipc.cpp b/test/client_ipc.cpp index 5158103..9970b95 100644 --- a/test/client_ipc.cpp +++ b/test/client_ipc.cpp @@ -6,34 +6,33 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -// TODO: this client should be reimplemented with -// the new client framework. Notice that it was not -// tested in the CI but was here for trying to reproduce -// some issue with IPC. - #include #include "zmq_addon.hpp" #include "nlohmann/json.hpp" #include "xeus/xguid.hpp" #include "xeus/xmessage.hpp" -#include "xeus-zmq/xauthentication.hpp" -#include "xeus-zmq/xmiddleware.hpp" -#include "xeus-zmq/xzmq_serializer.hpp" +#include "xeus/xkernel_configuration.hpp" namespace nl = nlohmann; int main(int, char**) { - zmq::context_t context; - zmq::socket_t cli(context, zmq::socket_type::dealer); - xeus::xguid socket_id = xeus::new_xguid(); - //cli.set(ZMQ_IDENTITY, socket_id.c_str(), socket_id.size()); - cli.set(zmq::sockopt::linger, xeus::get_socket_linger()); - cli.connect(xeus::get_end_point("ipc", "localhost", "shell")); + xeus::xcontext context; + xeus::xconfiguration config; + config.m_transport = "ipc"; + config.m_ip = "localhost"; + config.m_control_port = "control"; + config.m_shell_port = "shell"; + config.m_stdin_port = "stdin"; + config.m_iopub_port = "iopub"; + config.m_hb_port = "heartbeat"; + config.m_signature_scheme = "none"; + config.m_key = ""; - auto auth = xeus::make_xauthentication("none", ""); + xeus::xipc_client ipc_client(context, config); + xeus::xguid socket_id = xeus::new_xguid(); nl::json header = xeus::make_header("execute_request", "tester", "DAEDZFAEDE12"); std::string code = "std::cout << \"this is a test\" << std::endl;"; nl::json req = { @@ -48,14 +47,18 @@ int main(int, char**) nl::json::object(), xeus::buffer_sequence() ); - auto wire_msg = xeus::xzmq_serializer::serialize(std::move(msg), *auth); - wire_msg.send(cli); - zmq::multipart_t resp_msg; - resp_msg.recv(cli); + ipc_client.send_on_shell(msg); - auto resp = xeus::xzmq_serializer::deserialize(resp_msg, *auth); - std::cout << resp.content().dump(4) << std::endl; + auto response = ipc_client.check_shell_answer(); + if (response.has_value()) + { + std::cout << response->content().dump(4) << std::endl; + } + else + { + std::cout << "No response received" << std::endl; + } return 0; } diff --git a/test/xipc_client.cpp b/test/xipc_client.cpp index 6d56aea..43ab8c0 100644 --- a/test/xipc_client.cpp +++ b/test/xipc_client.cpp @@ -14,6 +14,15 @@ namespace xeus xipc_client::xipc_client(xcontext& context, const xconfiguration& config) : p_client(make_xclient_zmq(context, config)) { - // Additional initialization if needed + } + + void xipc_client::send_on_shell(const xmessage& msg) + { + p_client->send_on_shell(msg); + } + + std::optional xipc_client::check_shell_answer() + { + return p_client->check_shell_answer(); } } \ No newline at end of file diff --git a/test/xipc_client.hpp b/test/xipc_client.hpp index 67ef8e3..25ed50f 100644 --- a/test/xipc_client.hpp +++ b/test/xipc_client.hpp @@ -20,6 +20,9 @@ namespace xeus xipc_client(xcontext& context, const xconfiguration& config); + void send_on_shell(const xmessage& msg); + std::optional check_shell_answer(); + private: client_ptr p_client; }; From f0ed83883069c4826f2fb7d24aae203835b84600 Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Thu, 18 Apr 2024 12:31:59 +0530 Subject: [PATCH 4/5] Updating cmakelists.txt --- test/CMakeLists.txt | 8 ++++---- test/client_ipc.cpp | 7 +++++-- test/xipc_client.cpp | 4 ++-- test/xipc_client.hpp | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a8d938a..25f48aa 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -163,9 +163,7 @@ set_tests_properties(test_kernel_shell PROPERTIES ENVIRONMENT "JUPYTER_PATH=${CMAKE_CURRENT_BINARY_DIR}") -# TODO: enable this again when the ipc client -# is implemented -if (FALSE) +if (UNIX) # Test_kernel_ipc # =============== @@ -183,10 +181,12 @@ if (FALSE) # =============== set(TEST_CLIENT_IPC_SOURCES + xipc_client.cpp + xipc_client.hpp client_ipc.cpp) add_executable(test_client_ipc ${TEST_CLIENT_IPC_SOURCES}) target_link_libraries(test_client_ipc PRIVATE ${xeus-zmq_TARGET} Threads::Threads) target_compile_features(test_client_ipc PRIVATE cxx_std_17) -endif (FALSE) +endif (UNIX) diff --git a/test/client_ipc.cpp b/test/client_ipc.cpp index 9970b95..327f877 100644 --- a/test/client_ipc.cpp +++ b/test/client_ipc.cpp @@ -13,12 +13,15 @@ #include "xeus/xguid.hpp" #include "xeus/xmessage.hpp" #include "xeus/xkernel_configuration.hpp" +#include "xeus-zmq/xzmq_context.hpp" +#include "xipc_client.hpp" namespace nl = nlohmann; int main(int, char**) { - xeus::xcontext context; + auto context_ptr = xeus::make_zmq_context(); + xeus::xcontext& context = *context_ptr; xeus::xconfiguration config; config.m_transport = "ipc"; config.m_ip = "localhost"; @@ -48,7 +51,7 @@ int main(int, char**) xeus::buffer_sequence() ); - ipc_client.send_on_shell(msg); + ipc_client.send_on_shell(std::move(msg)); auto response = ipc_client.check_shell_answer(); if (response.has_value()) diff --git a/test/xipc_client.cpp b/test/xipc_client.cpp index 43ab8c0..6521a9a 100644 --- a/test/xipc_client.cpp +++ b/test/xipc_client.cpp @@ -16,9 +16,9 @@ namespace xeus { } - void xipc_client::send_on_shell(const xmessage& msg) + void xipc_client::send_on_shell(xmessage msg) { - p_client->send_on_shell(msg); + p_client->send_on_shell(std::move(msg)); } std::optional xipc_client::check_shell_answer() diff --git a/test/xipc_client.hpp b/test/xipc_client.hpp index 25ed50f..62779f0 100644 --- a/test/xipc_client.hpp +++ b/test/xipc_client.hpp @@ -20,7 +20,7 @@ namespace xeus xipc_client(xcontext& context, const xconfiguration& config); - void send_on_shell(const xmessage& msg); + void send_on_shell(xmessage msg); std::optional check_shell_answer(); private: From 9a377470267d20ea47f1a54b52ac3b01810144f0 Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Thu, 18 Apr 2024 12:50:18 +0530 Subject: [PATCH 5/5] No need to store reference --- test/client_ipc.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/client_ipc.cpp b/test/client_ipc.cpp index 327f877..4f74dfb 100644 --- a/test/client_ipc.cpp +++ b/test/client_ipc.cpp @@ -21,7 +21,6 @@ namespace nl = nlohmann; int main(int, char**) { auto context_ptr = xeus::make_zmq_context(); - xeus::xcontext& context = *context_ptr; xeus::xconfiguration config; config.m_transport = "ipc"; config.m_ip = "localhost"; @@ -33,7 +32,7 @@ int main(int, char**) config.m_signature_scheme = "none"; config.m_key = ""; - xeus::xipc_client ipc_client(context, config); + xeus::xipc_client ipc_client(*context_ptr, config); xeus::xguid socket_id = xeus::new_xguid(); nl::json header = xeus::make_header("execute_request", "tester", "DAEDZFAEDE12");