Commit 77514e0e authored by Pieter Hintjens's avatar Pieter Hintjens

Merge pull request #1053 from hurtonm/master

Code cleanup
parents 96501d72 414fc86b
...@@ -405,19 +405,23 @@ zmq::endpoint_t zmq::ctx_t::find_endpoint (const char *addr_) ...@@ -405,19 +405,23 @@ zmq::endpoint_t zmq::ctx_t::find_endpoint (const char *addr_)
return endpoint; return endpoint;
} }
void zmq::ctx_t::pend_connection (const char *addr_, pending_connection_t &pending_connection_) void zmq::ctx_t::pend_connection (const std::string &addr_,
const endpoint_t &endpoint_, pipe_t **pipes_)
{ {
const pending_connection_t pending_connection =
{endpoint_, pipes_ [0], pipes_ [1]};
endpoints_sync.lock (); endpoints_sync.lock ();
endpoints_t::iterator it = endpoints.find (addr_); endpoints_t::iterator it = endpoints.find (addr_);
if (it == endpoints.end ()) { if (it == endpoints.end ()) {
// Still no bind. // Still no bind.
pending_connection_.endpoint.socket->inc_seqnum (); endpoint_.socket->inc_seqnum ();
pending_connections.insert (pending_connections_t::value_type (std::string (addr_), pending_connection_)); pending_connections.insert (pending_connections_t::value_type (addr_, pending_connection));
} }
else else
// Bind has happened in the mean time, connect directly // Bind has happened in the mean time, connect directly
connect_inproc_sockets(it->second.socket, it->second.options, pending_connection_, connect_side); connect_inproc_sockets (it->second.socket, it->second.options, pending_connection, connect_side);
endpoints_sync.unlock (); endpoints_sync.unlock ();
} }
...@@ -436,7 +440,7 @@ void zmq::ctx_t::connect_pending (const char *addr_, zmq::socket_base_t *bind_so ...@@ -436,7 +440,7 @@ void zmq::ctx_t::connect_pending (const char *addr_, zmq::socket_base_t *bind_so
} }
void zmq::ctx_t::connect_inproc_sockets (zmq::socket_base_t *bind_socket_, void zmq::ctx_t::connect_inproc_sockets (zmq::socket_base_t *bind_socket_,
options_t& bind_options, pending_connection_t &pending_connection_, side side_) options_t& bind_options, const pending_connection_t &pending_connection_, side side_)
{ {
bind_socket_->inc_seqnum(); bind_socket_->inc_seqnum();
pending_connection_.bind_pipe->set_tid(bind_socket_->get_tid()); pending_connection_.bind_pipe->set_tid(bind_socket_->get_tid());
......
...@@ -51,13 +51,6 @@ namespace zmq ...@@ -51,13 +51,6 @@ namespace zmq
options_t options; options_t options;
}; };
struct pending_connection_t
{
endpoint_t endpoint;
pipe_t* connect_pipe;
pipe_t* bind_pipe;
};
// Context object encapsulates all the global state associated with // Context object encapsulates all the global state associated with
// the library. // the library.
...@@ -109,7 +102,8 @@ namespace zmq ...@@ -109,7 +102,8 @@ namespace zmq
int register_endpoint (const char *addr_, endpoint_t &endpoint_); int register_endpoint (const char *addr_, endpoint_t &endpoint_);
void unregister_endpoints (zmq::socket_base_t *socket_); void unregister_endpoints (zmq::socket_base_t *socket_);
endpoint_t find_endpoint (const char *addr_); endpoint_t find_endpoint (const char *addr_);
void pend_connection (const char *addr_, pending_connection_t &pending_connection_); void pend_connection (const std::string &addr_,
const endpoint_t &endpoint_, pipe_t **pipes_);
void connect_pending (const char *addr_, zmq::socket_base_t *bind_socket_); void connect_pending (const char *addr_, zmq::socket_base_t *bind_socket_);
enum { enum {
...@@ -121,6 +115,12 @@ namespace zmq ...@@ -121,6 +115,12 @@ namespace zmq
private: private:
struct pending_connection_t
{
endpoint_t endpoint;
pipe_t* connect_pipe;
pipe_t* bind_pipe;
};
// Used to check whether the object is a context. // Used to check whether the object is a context.
uint32_t tag; uint32_t tag;
...@@ -196,7 +196,7 @@ namespace zmq ...@@ -196,7 +196,7 @@ namespace zmq
pid_t pid; pid_t pid;
#endif #endif
enum side { connect_side, bind_side }; enum side { connect_side, bind_side };
void connect_inproc_sockets(zmq::socket_base_t *bind_socket_, options_t& bind_options, pending_connection_t &pending_connection_, side side_); void connect_inproc_sockets(zmq::socket_base_t *bind_socket_, options_t& bind_options, const pending_connection_t &pending_connection_, side side_);
}; };
} }
......
...@@ -152,9 +152,10 @@ zmq::endpoint_t zmq::object_t::find_endpoint (const char *addr_) ...@@ -152,9 +152,10 @@ zmq::endpoint_t zmq::object_t::find_endpoint (const char *addr_)
return ctx->find_endpoint (addr_); return ctx->find_endpoint (addr_);
} }
void zmq::object_t::pend_connection (const char *addr_, pending_connection_t &pending_connection_) void zmq::object_t::pend_connection (const std::string &addr_,
const endpoint_t &endpoint_, pipe_t **pipes_)
{ {
ctx->pend_connection (addr_, pending_connection_); ctx->pend_connection (addr_, endpoint_, pipes_);
} }
void zmq::object_t::connect_pending (const char *addr_, zmq::socket_base_t *bind_socket_) void zmq::object_t::connect_pending (const char *addr_, zmq::socket_base_t *bind_socket_)
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#ifndef __ZMQ_OBJECT_HPP_INCLUDED__ #ifndef __ZMQ_OBJECT_HPP_INCLUDED__
#define __ZMQ_OBJECT_HPP_INCLUDED__ #define __ZMQ_OBJECT_HPP_INCLUDED__
#include <string>
#include "stdint.hpp" #include "stdint.hpp"
namespace zmq namespace zmq
...@@ -61,7 +62,8 @@ namespace zmq ...@@ -61,7 +62,8 @@ namespace zmq
int register_endpoint (const char *addr_, zmq::endpoint_t &endpoint_); int register_endpoint (const char *addr_, zmq::endpoint_t &endpoint_);
void unregister_endpoints (zmq::socket_base_t *socket_); void unregister_endpoints (zmq::socket_base_t *socket_);
zmq::endpoint_t find_endpoint (const char *addr_); zmq::endpoint_t find_endpoint (const char *addr_);
void pend_connection (const char *addr_, pending_connection_t &pending_connection_); void pend_connection (const std::string &addr_,
const endpoint_t &endpoint, pipe_t **pipes_);
void connect_pending (const char *addr_, zmq::socket_base_t *bind_socket_); void connect_pending (const char *addr_, zmq::socket_base_t *bind_socket_);
void destroy_socket (zmq::socket_base_t *socket_); void destroy_socket (zmq::socket_base_t *socket_);
......
...@@ -527,9 +527,8 @@ int zmq::socket_base_t::connect (const char *addr_) ...@@ -527,9 +527,8 @@ int zmq::socket_base_t::connect (const char *addr_)
zmq_assert (written); zmq_assert (written);
new_pipes [0]->flush (); new_pipes [0]->flush ();
endpoint_t endpoint = {this, options}; const endpoint_t endpoint = {this, options};
pending_connection_t pending_connection = {endpoint, new_pipes [0], new_pipes [1]}; pend_connection (std::string (addr_), endpoint, new_pipes);
pend_connection (addr_, pending_connection);
} }
else else
{ {
......
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