Unverified Commit fe82c643 authored by Luca Boccassi's avatar Luca Boccassi Committed by GitHub

Merge pull request #3220 from sigiesec/code-improvements

Various refactorings
parents 31f69937 987e75b8
......@@ -404,7 +404,6 @@ test_apps = \
tests/test_stream_disconnect \
tests/test_stream_timeout \
tests/test_disconnect_inproc \
tests/test_unbind_inproc \
tests/test_unbind_wildcard \
tests/test_ctx_options \
tests/test_ctx_destroy \
......@@ -556,9 +555,6 @@ tests_test_stream_disconnect_LDADD = src/libzmq.la
tests_test_disconnect_inproc_SOURCES = tests/test_disconnect_inproc.cpp
tests_test_disconnect_inproc_LDADD = src/libzmq.la
tests_test_unbind_inproc_SOURCES = tests/test_unbind_inproc.cpp
tests_test_unbind_inproc_LDADD = src/libzmq.la
tests_test_unbind_wildcard_SOURCES = tests/test_unbind_wildcard.cpp
tests_test_unbind_wildcard_LDADD = src/libzmq.la
......@@ -819,7 +815,8 @@ test_apps += \
tests/test_address_tipc
tests_test_connect_delay_tipc_SOURCES = tests/test_connect_delay_tipc.cpp
tests_test_connect_delay_tipc_LDADD = src/libzmq.la
tests_test_connect_delay_tipc_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_connect_delay_tipc_CPPFLAGS = ${UNITY_CPPFLAGS}
tests_test_pair_tipc_SOURCES = tests/test_pair_tipc.cpp
tests_test_pair_tipc_LDADD = src/libzmq.la
......@@ -986,8 +983,13 @@ XFAIL_TESTS += tests/test_abstract_ipc
endif
if ON_GNU
XFAIL_TESTS += test_ipc_wildcard \
test_term_endpoint
XFAIL_TESTS += tests/test_ipc_wildcard \
tests/test_term_endpoint
endif
# TODO remove this again when resolving https://github.com/zeromq/libzmq/issues/3124
if BUILD_TIPC
XFAIL_TESTS += tests/test_connect_delay_tipc
endif
EXTRA_DIST = \
......
......@@ -49,6 +49,7 @@ class vmci_address_t;
namespace protocol_name
{
static const char inproc[] = "inproc";
static const char tcp[] = "tcp";
static const char udp[] = "udp";
#if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS \
......
......@@ -617,15 +617,7 @@ void zmq::ctx_t::connect_inproc_sockets (
errno_assert (rc == 0);
}
bool conflate =
pending_connection_.endpoint.options.conflate
&& (pending_connection_.endpoint.options.type == ZMQ_DEALER
|| pending_connection_.endpoint.options.type == ZMQ_PULL
|| pending_connection_.endpoint.options.type == ZMQ_PUSH
|| pending_connection_.endpoint.options.type == ZMQ_PUB
|| pending_connection_.endpoint.options.type == ZMQ_SUB);
if (!conflate) {
if (!get_effective_conflate_option (pending_connection_.endpoint.options)) {
pending_connection_.connect_pipe->set_hwms_boost (bind_options_.sndhwm,
bind_options_.rcvhwm);
pending_connection_.bind_pipe->set_hwms_boost (
......@@ -660,15 +652,7 @@ void zmq::ctx_t::connect_inproc_sockets (
// is open before sending.
if (pending_connection_.endpoint.options.recv_routing_id
&& pending_connection_.endpoint.socket->check_tag ()) {
msg_t routing_id;
const int rc = routing_id.init_size (bind_options_.routing_id_size);
errno_assert (rc == 0);
memcpy (routing_id.data (), bind_options_.routing_id,
bind_options_.routing_id_size);
routing_id.set_flags (msg_t::routing_id);
const bool written = pending_connection_.bind_pipe->write (&routing_id);
zmq_assert (written);
pending_connection_.bind_pipe->flush ();
send_routing_id (pending_connection_.bind_pipe, bind_options_);
}
}
......
......@@ -268,6 +268,15 @@ struct options_t
std::map<std::string, std::string> app_metadata;
};
inline bool get_effective_conflate_option (const options_t &options)
{
// conflate is only effective for some socket types
return options.conflate
&& (options.type == ZMQ_DEALER || options.type == ZMQ_PULL
|| options.type == ZMQ_PUSH || options.type == ZMQ_PUB
|| options.type == ZMQ_SUB);
}
int do_getsockopt (void *const optval_,
size_t *const optvallen_,
const void *value_,
......
......@@ -76,6 +76,18 @@ int zmq::pipepair (class object_t *parents_[2],
return 0;
}
void zmq::send_routing_id (pipe_t *pipe_, const options_t &options_)
{
zmq::msg_t id;
const int rc = id.init_size (options_.routing_id_size);
errno_assert (rc == 0);
memcpy (id.data (), options_.routing_id, options_.routing_id_size);
id.set_flags (zmq::msg_t::routing_id);
const bool written = pipe_->write (&id);
zmq_assert (written);
pipe_->flush ();
}
zmq::pipe_t::pipe_t (object_t *parent_,
upipe_t *inpipe_,
upipe_t *outpipe_,
......
......@@ -36,6 +36,7 @@
#include "stdint.hpp"
#include "array.hpp"
#include "blob.hpp"
#include "options.hpp"
namespace zmq
{
......@@ -235,9 +236,6 @@ class pipe_t : public object_t,
// Routing id of the writer. Used uniquely by the reader side.
int _server_socket_routing_id;
// Pipe's credential.
blob_t _credential;
// Returns true if the message is delimiter; false otherwise.
static bool is_delimiter (const msg_t &msg_);
......@@ -250,6 +248,8 @@ class pipe_t : public object_t,
pipe_t (const pipe_t &);
const pipe_t &operator= (const pipe_t &);
};
void send_routing_id (pipe_t *pipe_, const options_t &options_);
}
#endif
This diff is collapsed.
......@@ -105,6 +105,33 @@ class session_base_t : public own_t, public io_object_t, public i_pipe_events
private:
void start_connecting (bool wait_);
typedef own_t *(session_base_t::*connecter_factory_fun_t) (
io_thread_t *io_thread, bool wait_);
typedef std::pair<std::string, connecter_factory_fun_t>
connecter_factory_entry_t;
static connecter_factory_entry_t _connecter_factories[];
typedef std::map<std::string, connecter_factory_fun_t>
connecter_factory_map_t;
static connecter_factory_map_t _connecter_factories_map;
own_t *create_connecter_vmci (io_thread_t *io_thread_, bool wait_);
own_t *create_connecter_tipc (io_thread_t *io_thread_, bool wait_);
own_t *create_connecter_ipc (io_thread_t *io_thread_, bool wait_);
own_t *create_connecter_tcp (io_thread_t *io_thread_, bool wait_);
typedef void (session_base_t::*start_connecting_fun_t) (
io_thread_t *io_thread);
typedef std::pair<std::string, start_connecting_fun_t>
start_connecting_entry_t;
static start_connecting_entry_t _start_connecting_entries[];
typedef std::map<std::string, start_connecting_fun_t>
start_connecting_map_t;
static start_connecting_map_t _start_connecting_map;
void start_connecting_pgm (io_thread_t *io_thread_);
void start_connecting_norm (io_thread_t *io_thread_);
void start_connecting_udp (io_thread_t *io_thread_);
void reconnect ();
// Handlers for incoming commands.
......
This diff is collapsed.
......@@ -82,9 +82,9 @@ class socket_base_t : public own_t,
// Interface for communication with the API layer.
int setsockopt (int option_, const void *optval_, size_t optvallen_);
int getsockopt (int option_, void *optval_, size_t *optvallen_);
int bind (const char *addr_);
int connect (const char *addr_);
int term_endpoint (const char *addr_);
int bind (const char *endpoint_uri_);
int connect (const char *endpoint_uri_);
int term_endpoint (const char *endpoint_uri_);
int send (zmq::msg_t *msg_, int flags_);
int recv (zmq::msg_t *msg_, int flags_);
void add_signaler (signaler_t *s_);
......@@ -120,20 +120,24 @@ class socket_base_t : public own_t,
int monitor (const char *endpoint_, int events_);
void event_connected (const std::string &addr_, zmq::fd_t fd_);
void event_connect_delayed (const std::string &addr_, int err_);
void event_connect_retried (const std::string &addr_, int interval_);
void event_listening (const std::string &addr_, zmq::fd_t fd_);
void event_bind_failed (const std::string &addr_, int err_);
void event_accepted (const std::string &addr_, zmq::fd_t fd_);
void event_accept_failed (const std::string &addr_, int err_);
void event_closed (const std::string &addr_, zmq::fd_t fd_);
void event_close_failed (const std::string &addr_, int err_);
void event_disconnected (const std::string &addr_, zmq::fd_t fd_);
void event_handshake_failed_no_detail (const std::string &addr_, int err_);
void event_handshake_failed_protocol (const std::string &addr_, int err_);
void event_handshake_failed_auth (const std::string &addr_, int err_);
void event_handshake_succeeded (const std::string &addr_, int err_);
void event_connected (const std::string &endpoint_uri_, zmq::fd_t fd_);
void event_connect_delayed (const std::string &endpoint_uri_, int err_);
void event_connect_retried (const std::string &endpoint_uri_,
int interval_);
void event_listening (const std::string &endpoint_uri_, zmq::fd_t fd_);
void event_bind_failed (const std::string &endpoint_uri_, int err_);
void event_accepted (const std::string &endpoint_uri_, zmq::fd_t fd_);
void event_accept_failed (const std::string &endpoint_uri_, int err_);
void event_closed (const std::string &endpoint_uri_, zmq::fd_t fd_);
void event_close_failed (const std::string &endpoint_uri_, int err_);
void event_disconnected (const std::string &endpoint_uri_, zmq::fd_t fd_);
void event_handshake_failed_no_detail (const std::string &endpoint_uri_,
int err_);
void event_handshake_failed_protocol (const std::string &endpoint_uri_,
int err_);
void event_handshake_failed_auth (const std::string &endpoint_uri_,
int err_);
void event_handshake_succeeded (const std::string &endpoint_uri_, int err_);
// Query the state of a specific peer. The default implementation
// always returns an ENOTSUP error.
......@@ -182,17 +186,19 @@ class socket_base_t : public own_t,
private:
// test if event should be sent and then dispatch it
void event (const std::string &addr_, intptr_t value_, int type_);
void event (const std::string &endpoint_uri_, intptr_t value_, int type_);
// Socket event data dispatch
void
monitor_event (int event_, intptr_t value_, const std::string &addr_) const;
void monitor_event (int event_,
intptr_t value_,
const std::string &endpoint_uri_) const;
// Monitor socket cleanup
void stop_monitor (bool send_monitor_stopped_event_ = true);
// Creates new endpoint ID and adds the endpoint to the map.
void add_endpoint (const char *addr_, own_t *endpoint_, pipe_t *pipe_);
void
add_endpoint (const char *endpoint_uri_, own_t *endpoint_, pipe_t *pipe_);
// Map of open endpoints.
typedef std::pair<own_t *, pipe_t *> endpoint_pipe_t;
......@@ -200,7 +206,17 @@ class socket_base_t : public own_t,
endpoints_t _endpoints;
// Map of open inproc endpoints.
typedef std::multimap<std::string, pipe_t *> inprocs_t;
class inprocs_t
{
public:
void emplace (const char *endpoint_uri_, pipe_t *pipe_);
int erase_pipes (const std::string &endpoint_uri_str_);
void erase_pipe (pipe_t *pipe_);
private:
typedef std::multimap<std::string, pipe_t *> map_t;
map_t _inprocs;
};
inprocs_t _inprocs;
// To be called after processing commands or invoking any command
......@@ -224,7 +240,7 @@ class socket_base_t : public own_t,
// Parse URI string.
static int
parse_uri (const char *uri_, std::string &protocol_, std::string &address_);
parse_uri (const char *uri_, std::string &protocol_, std::string &path_);
// Check whether transport protocol, as specified in connect or
// bind, is available and compatible with the socket type.
......@@ -249,6 +265,9 @@ class socket_base_t : public own_t,
void update_pipe_options (int option_);
std::string resolve_tcp_addr (std::string endpoint_uri_,
const char *tcp_address_);
// Socket's mailbox object.
i_mailbox *_mailbox;
......
......@@ -67,7 +67,6 @@ zmq::stream_engine_t::stream_engine_t (fd_t fd_,
const options_t &options_,
const std::string &endpoint_) :
_s (fd_),
_as_server (false),
_handle (static_cast<handle_t> (NULL)),
_inpos (NULL),
_insize (0),
......
......@@ -145,9 +145,6 @@ class stream_engine_t : public io_object_t, public i_engine
// Underlying socket.
fd_t _s;
// True iff this is server's engine.
bool _as_server;
msg_t _tx_msg;
// Need to store PING payload for PONG
msg_t _pong_msg;
......
......@@ -28,7 +28,6 @@ set(tests
test_stream_empty
test_stream_disconnect
test_disconnect_inproc
test_unbind_inproc
test_unbind_wildcard
test_ctx_options
test_ctx_destroy
......
This diff is collapsed.
/*
Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
This file is part of 0MQ.
0MQ is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
0MQ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "testutil.hpp"
int main (void)
{
setup_test_environment ();
void *ctx = zmq_ctx_new ();
assert (ctx);
void *sb = zmq_socket (ctx, ZMQ_REP);
assert (sb);
int rc = zmq_bind (sb, "inproc://a");
assert (rc == 0);
rc = zmq_unbind (sb, "inproc://a");
assert (rc == 0);
rc = zmq_close (sb);
assert (rc == 0);
rc = zmq_ctx_term (ctx);
assert (rc == 0);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment