diff --git a/CMakeLists.txt b/CMakeLists.txt index e93b90c..be7c81b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,7 +80,7 @@ message(STATUS "XEUS_ZMQ_BUILD_TESTS: ${XEUS_ZMQ_BUILD_TESTS}") # ============ set(xeus_REQUIRED_VERSION 3.2.0) -set(nlohmann_json_REQUIRED_VERSION 3.2.0) +set(nlohmann_json_REQUIRED_VERSION 3.11.2) set(cppzmq_REQUIRED_VERSION 4.8.1) set(zeromq_REQUIRED_VERSION 4.3.2) @@ -132,6 +132,7 @@ set(XEUS_ZMQ_HEADERS ${XEUS_ZMQ_INCLUDE_DIR}/xeus-zmq/xthread.hpp ${XEUS_ZMQ_INCLUDE_DIR}/xeus-zmq/xzmq_context.hpp ${XEUS_ZMQ_INCLUDE_DIR}/xeus-zmq/xzmq_serializer.hpp + ${XEUS_ZMQ_INCLUDE_DIR}/xeus-zmq/xclient_zmq.hpp ) set(XEUS_ZMQ_SOURCES @@ -164,6 +165,15 @@ set(XEUS_ZMQ_SOURCES ${XEUS_ZMQ_SOURCE_DIR}/xzmq_messenger.hpp ${XEUS_ZMQ_SOURCE_DIR}/xzmq_messenger.cpp ${XEUS_ZMQ_SOURCE_DIR}/xzmq_serializer.cpp + ${XEUS_ZMQ_SOURCE_DIR}/xclient_zmq.cpp + ${XEUS_ZMQ_SOURCE_DIR}/xclient_messenger.hpp + ${XEUS_ZMQ_SOURCE_DIR}/xclient_messenger.cpp + ${XEUS_ZMQ_SOURCE_DIR}/xclient_zmq_impl.hpp + ${XEUS_ZMQ_SOURCE_DIR}/xclient_zmq_impl.cpp + ${XEUS_ZMQ_SOURCE_DIR}/xdealer_channel.hpp + ${XEUS_ZMQ_SOURCE_DIR}/xdealer_channel.cpp + ${XEUS_ZMQ_SOURCE_DIR}/xiopub_client.hpp + ${XEUS_ZMQ_SOURCE_DIR}/xiopub_client.cpp ) # Targets and link diff --git a/README.md b/README.md index b3cf513..15ad4a5 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ See the [documentation](http://xeus.readthedocs.io/) for an exhaustive list of t We have packaged all these dependencies on conda-forge. The simplest way to install them is to run: ```bash -mamba install cmake pkg-config zeromq cppzmq OpenSSL nlohmann_json xtl xeus -c conda-forge +mamba install cmake pkg-config zeromq cppzmq OpenSSL nlohmann_json=3.11.2 xtl xeus -c conda-forge ``` Once you have installed the dependencies, you can build and install `xeus-zmq`: diff --git a/environment-dev.yml b/environment-dev.yml index 77576c1..77d5403 100644 --- a/environment-dev.yml +++ b/environment-dev.yml @@ -15,7 +15,7 @@ dependencies: - xeus>=3.2.0,<4.0 - OpenSSL=1 - libopenssl-static=1 - - nlohmann_json + - nlohmann_json=3.11.2 # Test dependencies - doctest >= 2.4.6 - pytest diff --git a/include/xeus-zmq/xclient_zmq.hpp b/include/xeus-zmq/xclient_zmq.hpp index 898a8b9..9eed125 100644 --- a/include/xeus-zmq/xclient_zmq.hpp +++ b/include/xeus-zmq/xclient_zmq.hpp @@ -47,8 +47,12 @@ namespace xeus void notify_control_listener(xmessage msg); void notify_iopub_listener(xmessage msg); - void start(); + std::size_t iopub_queue_size() const; std::optional pop_iopub_message(); + void connect(); + void stop_channels(); + void start(); + void wait_for_message(); private: std::unique_ptr p_client_impl; diff --git a/src/xclient_zmq.cpp b/src/xclient_zmq.cpp index 25a8829..ad9dc54 100644 --- a/src/xclient_zmq.cpp +++ b/src/xclient_zmq.cpp @@ -73,9 +73,9 @@ namespace xeus p_client_impl->notify_iopub_listener(std::move(msg)); } - void xclient_zmq::start() + std::size_t xclient_zmq::iopub_queue_size() const { - p_client_impl->start(); + return p_client_impl->iopub_queue_size(); } std::optional xclient_zmq::pop_iopub_message() @@ -83,6 +83,26 @@ namespace xeus return p_client_impl->pop_iopub_message(); } + void xclient_zmq::connect() + { + p_client_impl->connect(); + } + + void xclient_zmq::stop_channels() + { + p_client_impl->stop_channels(); + } + + void xclient_zmq::start() + { + p_client_impl->start(); + } + + void xclient_zmq::wait_for_message() + { + p_client_impl->wait_for_message(); + } + std::unique_ptr make_xclient_zmq(xcontext& context, const xconfiguration& config, nl::json::error_handler_t eh) diff --git a/src/xclient_zmq_impl.cpp b/src/xclient_zmq_impl.cpp index 4f682cc..699ade0 100644 --- a/src/xclient_zmq_impl.cpp +++ b/src/xclient_zmq_impl.cpp @@ -20,8 +20,8 @@ namespace xeus const xeus::xconfiguration& config, nl::json::error_handler_t eh) : p_auth(make_xauthentication(config.m_signature_scheme, config.m_key)) - , m_shell_client(context, config) - , m_control_client(context, config) + , m_shell_client(context, config.m_transport, config.m_ip, config.m_shell_port) + , m_control_client(context, config.m_transport, config.m_ip, config.m_control_port) , m_iopub_client(context, config) , p_messenger(context) , m_error_handler(eh) @@ -93,11 +93,6 @@ namespace xeus m_iopub_listener = l; } - xclient_messenger& xclient_zmq_impl::get_client_messenger() - { - return p_messenger; - } - void xclient_zmq_impl::connect() { p_messenger.connect(); @@ -171,7 +166,7 @@ namespace xeus void xclient_zmq_impl::start() { start_iopub_thread(); - // TODO + // TODO : Introduce a client, xheartbeat_client that runs on its own thread, m_heartbeat_thread. } void xclient_zmq_impl::start_iopub_thread() diff --git a/src/xclient_zmq_impl.hpp b/src/xclient_zmq_impl.hpp index c85f4d2..30cfdcb 100644 --- a/src/xclient_zmq_impl.hpp +++ b/src/xclient_zmq_impl.hpp @@ -64,7 +64,6 @@ namespace xeus // TODO // client messenger - xclient_messenger& get_client_messenger(); void connect(); void stop_channels(); diff --git a/src/xdealer_channel.cpp b/src/xdealer_channel.cpp index a3f96e7..81c986c 100644 --- a/src/xdealer_channel.cpp +++ b/src/xdealer_channel.cpp @@ -15,18 +15,16 @@ namespace xeus { xdealer_channel::xdealer_channel(zmq::context_t& context, - const xeus::xconfiguration& config) + const std::string& transport, + const std::string& ip, + const std::string& port) : m_socket(context, zmq::socket_type::dealer) - , m_end_point("") { - m_end_point = xeus::get_end_point(config.m_transport, config.m_ip, config.m_shell_port); - - m_socket.connect(m_end_point); + m_socket.connect(get_end_point(transport, ip, port)); } xdealer_channel::~xdealer_channel() { - m_socket.disconnect(m_end_point); } void xdealer_channel::send_message(zmq::multipart_t& message) @@ -37,7 +35,7 @@ namespace xeus std::optional xdealer_channel::receive_message(long timeout) { zmq::multipart_t wire_msg; - m_socket.set(zmq::sockopt::linger, timeout); + m_socket.set(zmq::sockopt::linger, static_cast(timeout)); if (wire_msg.recv(m_socket)) { return wire_msg; diff --git a/src/xdealer_channel.hpp b/src/xdealer_channel.hpp index 5204870..4893dc2 100644 --- a/src/xdealer_channel.hpp +++ b/src/xdealer_channel.hpp @@ -24,7 +24,9 @@ namespace xeus public: xdealer_channel(zmq::context_t& context, - const xeus::xconfiguration& config); + const std::string& transport, + const std::string& ip, + const std::string& port); ~xdealer_channel(); @@ -34,9 +36,7 @@ namespace xeus zmq::socket_t& get_socket(); private: - zmq::socket_t m_socket; - std::string m_end_point; }; } diff --git a/src/xiopub_client.cpp b/src/xiopub_client.cpp index fb98662..3519766 100644 --- a/src/xiopub_client.cpp +++ b/src/xiopub_client.cpp @@ -13,6 +13,7 @@ #include "xclient_zmq_impl.hpp" #include "xeus-zmq/xzmq_serializer.hpp" +#include "xeus-zmq/xmiddleware.hpp" namespace xeus { @@ -20,16 +21,14 @@ namespace xeus xiopub_client::xiopub_client(zmq::context_t& context, const xeus::xconfiguration& config) : m_iopub(context, zmq::socket_type::sub) - , m_iopub_end_point("") + , m_controller(context, zmq::socket_type::rep) { - m_iopub_end_point = xeus::get_end_point(config.m_transport, config.m_ip, config.m_iopub_port); - - m_iopub.connect(m_iopub_end_point); + m_iopub.connect(get_end_point(config.m_transport, config.m_ip, config.m_iopub_port)); + init_socket(m_controller, get_controller_end_point("iopub")); } xiopub_client::~xiopub_client() { - m_iopub.disconnect(m_iopub_end_point); } std::size_t xiopub_client::iopub_queue_size() const diff --git a/src/xiopub_client.hpp b/src/xiopub_client.hpp index d6c8349..f374e76 100644 --- a/src/xiopub_client.hpp +++ b/src/xiopub_client.hpp @@ -43,7 +43,7 @@ namespace xeus private: zmq::socket_t m_iopub; - std::string m_iopub_end_point; + zmq::socket_t m_controller; std::queue m_message_queue; mutable std::mutex m_queue_mutex; diff --git a/xeus-zmqConfig.cmake.in b/xeus-zmqConfig.cmake.in index 3f8761d..66bc431 100644 --- a/xeus-zmqConfig.cmake.in +++ b/xeus-zmqConfig.cmake.in @@ -22,7 +22,7 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR};${CMAKE_MODULE_PATH}") @XEUS_ZMQ_CONFIG_CODE@ include(CMakeFindDependencyMacro) -find_dependency(nlohmann_json @nlohmann_json_REQUIRED_VERSION@) +find_dependency(nlohmann_json @nlohmann_json_VERSION@ EXACT) find_dependency(xeus @xeus_REQUIRED_VERSION@) # On Unix platforms, ZeroMQ is built with autotools and pkg-config is