mirror of
https://github.com/zeromq/libzmq.git
synced 2025-10-06 19:14:05 +02:00
Problem: formatting inconsistent
Solution: applied clang-format
This commit is contained in:
@@ -242,10 +242,11 @@ ZMQ_EXPORT int zmq_ctx_destroy (void *context);
|
||||
* alignment and raise sigbus on violations. Make sure applications allocate
|
||||
* zmq_msg_t on addresses aligned on a pointer-size boundary to avoid this issue.
|
||||
*/
|
||||
typedef struct zmq_msg_t {
|
||||
#if defined (__GNUC__) || defined ( __INTEL_COMPILER) || \
|
||||
(defined (__SUNPRO_C) && __SUNPRO_C >= 0x590) || \
|
||||
(defined (__SUNPRO_CC) && __SUNPRO_CC >= 0x590)
|
||||
typedef struct zmq_msg_t
|
||||
{
|
||||
#if defined(__GNUC__) || defined(__INTEL_COMPILER) \
|
||||
|| (defined(__SUNPRO_C) && __SUNPRO_C >= 0x590) \
|
||||
|| (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x590)
|
||||
unsigned char _[64] __attribute__ ((aligned (sizeof (void *))));
|
||||
#elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_ARM64))
|
||||
__declspec(align (8)) unsigned char _[64];
|
||||
@@ -260,8 +261,8 @@ typedef void (zmq_free_fn) (void *data, void *hint);
|
||||
|
||||
ZMQ_EXPORT int zmq_msg_init (zmq_msg_t *msg);
|
||||
ZMQ_EXPORT int zmq_msg_init_size (zmq_msg_t *msg, size_t size);
|
||||
ZMQ_EXPORT int zmq_msg_init_data (zmq_msg_t *msg, void *data,
|
||||
size_t size, zmq_free_fn *ffn, void *hint);
|
||||
ZMQ_EXPORT int zmq_msg_init_data (
|
||||
zmq_msg_t *msg, void *data, size_t size, zmq_free_fn *ffn, void *hint);
|
||||
ZMQ_EXPORT int zmq_msg_send (zmq_msg_t *msg, void *s, int flags);
|
||||
ZMQ_EXPORT int zmq_msg_recv (zmq_msg_t *msg, void *s, int flags);
|
||||
ZMQ_EXPORT int zmq_msg_close (zmq_msg_t *msg);
|
||||
@@ -272,7 +273,8 @@ ZMQ_EXPORT size_t zmq_msg_size (const zmq_msg_t *msg);
|
||||
ZMQ_EXPORT int zmq_msg_more (const zmq_msg_t *msg);
|
||||
ZMQ_EXPORT int zmq_msg_get (const zmq_msg_t *msg, int property);
|
||||
ZMQ_EXPORT int zmq_msg_set (zmq_msg_t *msg, int property, int optval);
|
||||
ZMQ_EXPORT const char *zmq_msg_gets (const zmq_msg_t *msg, const char *property);
|
||||
ZMQ_EXPORT const char *zmq_msg_gets (const zmq_msg_t *msg,
|
||||
const char *property);
|
||||
|
||||
/******************************************************************************/
|
||||
/* 0MQ socket definition. */
|
||||
@@ -425,10 +427,10 @@ ZMQ_EXPORT const char *zmq_msg_gets (const zmq_msg_t *msg, const char *property)
|
||||
|
||||
ZMQ_EXPORT void *zmq_socket (void *, int type);
|
||||
ZMQ_EXPORT int zmq_close (void *s);
|
||||
ZMQ_EXPORT int zmq_setsockopt (void *s, int option, const void *optval,
|
||||
size_t optvallen);
|
||||
ZMQ_EXPORT int zmq_getsockopt (void *s, int option, void *optval,
|
||||
size_t *optvallen);
|
||||
ZMQ_EXPORT int
|
||||
zmq_setsockopt (void *s, int option, const void *optval, size_t optvallen);
|
||||
ZMQ_EXPORT int
|
||||
zmq_getsockopt (void *s, int option, void *optval, size_t *optvallen);
|
||||
ZMQ_EXPORT int zmq_bind (void *s, const char *addr);
|
||||
ZMQ_EXPORT int zmq_connect (void *s, const char *addr);
|
||||
ZMQ_EXPORT int zmq_unbind (void *s, const char *addr);
|
||||
@@ -469,7 +471,10 @@ ZMQ_EXPORT int zmq_poll (zmq_pollitem_t *items, int nitems, long timeout);
|
||||
/******************************************************************************/
|
||||
|
||||
ZMQ_EXPORT int zmq_proxy (void *frontend, void *backend, void *capture);
|
||||
ZMQ_EXPORT int zmq_proxy_steerable (void *frontend, void *backend, void *capture, void *control);
|
||||
ZMQ_EXPORT int zmq_proxy_steerable (void *frontend,
|
||||
void *backend,
|
||||
void *capture,
|
||||
void *control);
|
||||
|
||||
/******************************************************************************/
|
||||
/* Probe library capabilities */
|
||||
@@ -488,8 +493,10 @@ ZMQ_EXPORT int zmq_device (int type, void *frontend, void *backend);
|
||||
ZMQ_EXPORT int zmq_sendmsg (void *s, zmq_msg_t *msg, int flags);
|
||||
ZMQ_EXPORT int zmq_recvmsg (void *s, zmq_msg_t *msg, int flags);
|
||||
struct iovec;
|
||||
ZMQ_EXPORT int zmq_sendiov (void *s, struct iovec *iov, size_t count, int flags);
|
||||
ZMQ_EXPORT int zmq_recviov (void *s, struct iovec *iov, size_t *count, int flags);
|
||||
ZMQ_EXPORT int
|
||||
zmq_sendiov (void *s, struct iovec *iov, size_t count, int flags);
|
||||
ZMQ_EXPORT int
|
||||
zmq_recviov (void *s, struct iovec *iov, size_t *count, int flags);
|
||||
|
||||
/******************************************************************************/
|
||||
/* Encryption functions */
|
||||
@@ -507,7 +514,8 @@ ZMQ_EXPORT int zmq_curve_keypair (char *z85_public_key, char *z85_secret_key);
|
||||
|
||||
/* Derive the z85-encoded public key from the z85-encoded secret key. */
|
||||
/* Returns 0 on success. */
|
||||
ZMQ_EXPORT int zmq_curve_public (char *z85_public_key, const char *z85_secret_key);
|
||||
ZMQ_EXPORT int zmq_curve_public (char *z85_public_key,
|
||||
const char *z85_secret_key);
|
||||
|
||||
/******************************************************************************/
|
||||
/* Atomic utility methods */
|
||||
@@ -650,18 +658,25 @@ typedef struct zmq_poller_event_t
|
||||
|
||||
ZMQ_EXPORT void *zmq_poller_new (void);
|
||||
ZMQ_EXPORT int zmq_poller_destroy (void **poller_p);
|
||||
ZMQ_EXPORT int zmq_poller_add (void *poller, void *socket, void *user_data, short events);
|
||||
ZMQ_EXPORT int
|
||||
zmq_poller_add (void *poller, void *socket, void *user_data, short events);
|
||||
ZMQ_EXPORT int zmq_poller_modify (void *poller, void *socket, short events);
|
||||
ZMQ_EXPORT int zmq_poller_remove (void *poller, void *socket);
|
||||
ZMQ_EXPORT int zmq_poller_wait (void *poller, zmq_poller_event_t *event, long timeout);
|
||||
ZMQ_EXPORT int zmq_poller_wait_all (void *poller, zmq_poller_event_t *events, int n_events, long timeout);
|
||||
ZMQ_EXPORT int
|
||||
zmq_poller_wait (void *poller, zmq_poller_event_t *event, long timeout);
|
||||
ZMQ_EXPORT int zmq_poller_wait_all (void *poller,
|
||||
zmq_poller_event_t *events,
|
||||
int n_events,
|
||||
long timeout);
|
||||
|
||||
#if defined _WIN32
|
||||
ZMQ_EXPORT int zmq_poller_add_fd (void *poller, SOCKET fd, void *user_data, short events);
|
||||
ZMQ_EXPORT int
|
||||
zmq_poller_add_fd (void *poller, SOCKET fd, void *user_data, short events);
|
||||
ZMQ_EXPORT int zmq_poller_modify_fd (void *poller, SOCKET fd, short events);
|
||||
ZMQ_EXPORT int zmq_poller_remove_fd (void *poller, SOCKET fd);
|
||||
#else
|
||||
ZMQ_EXPORT int zmq_poller_add_fd (void *poller, int fd, void *user_data, short events);
|
||||
ZMQ_EXPORT int
|
||||
zmq_poller_add_fd (void *poller, int fd, void *user_data, short events);
|
||||
ZMQ_EXPORT int zmq_poller_modify_fd (void *poller, int fd, short events);
|
||||
ZMQ_EXPORT int zmq_poller_remove_fd (void *poller, int fd);
|
||||
#endif
|
||||
@@ -680,9 +695,11 @@ typedef void (zmq_timer_fn)(int timer_id, void *arg);
|
||||
|
||||
ZMQ_EXPORT void *zmq_timers_new (void);
|
||||
ZMQ_EXPORT int zmq_timers_destroy (void **timers_p);
|
||||
ZMQ_EXPORT int zmq_timers_add (void *timers, size_t interval, zmq_timer_fn handler, void *arg);
|
||||
ZMQ_EXPORT int
|
||||
zmq_timers_add (void *timers, size_t interval, zmq_timer_fn handler, void *arg);
|
||||
ZMQ_EXPORT int zmq_timers_cancel (void *timers, int timer_id);
|
||||
ZMQ_EXPORT int zmq_timers_set_interval (void *timers, int timer_id, size_t interval);
|
||||
ZMQ_EXPORT int
|
||||
zmq_timers_set_interval (void *timers, int timer_id, size_t interval);
|
||||
ZMQ_EXPORT int zmq_timers_reset (void *timers, int timer_id);
|
||||
ZMQ_EXPORT long zmq_timers_timeout (void *timers);
|
||||
ZMQ_EXPORT int zmq_timers_execute (void *timers);
|
||||
|
@@ -34,14 +34,16 @@
|
||||
compilers even have an equivalent concept.
|
||||
So in the worst case, this include file is treated as silently empty. */
|
||||
|
||||
#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) || defined(_MSC_VER)
|
||||
#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) \
|
||||
|| defined(_MSC_VER)
|
||||
#if defined(__GNUC__) || defined(__GNUG__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic warning "-Wcpp"
|
||||
#pragma GCC diagnostic ignored "-Werror"
|
||||
#pragma GCC diagnostic ignored "-Wall"
|
||||
#endif
|
||||
#pragma message("Warning: zmq_utils.h is deprecated. All its functionality is provided by zmq.h.")
|
||||
#pragma message( \
|
||||
"Warning: zmq_utils.h is deprecated. All its functionality is provided by zmq.h.")
|
||||
#if defined(__GNUC__) || defined(__GNUG__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
@@ -149,8 +149,7 @@ int main (int argc, char *argv [])
|
||||
}
|
||||
|
||||
#if defined ZMQ_HAVE_WINDOWS
|
||||
local_thread = (HANDLE) _beginthreadex (NULL, 0,
|
||||
worker, ctx, 0 , NULL);
|
||||
local_thread = (HANDLE) _beginthreadex (NULL, 0, worker, ctx, 0, NULL);
|
||||
if (local_thread == 0) {
|
||||
printf ("error in _beginthreadex\n");
|
||||
return -1;
|
||||
@@ -237,4 +236,3 @@ int main (int argc, char *argv [])
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -71,7 +71,6 @@ static void *worker (void *ctx_)
|
||||
}
|
||||
|
||||
for (i = 0; i != message_count; i++) {
|
||||
|
||||
rc = zmq_msg_init_size (&msg, message_size);
|
||||
if (rc != 0) {
|
||||
printf ("error in zmq_msg_init_size: %s\n", zmq_strerror (errno));
|
||||
@@ -150,8 +149,7 @@ int main (int argc, char *argv [])
|
||||
}
|
||||
|
||||
#if defined ZMQ_HAVE_WINDOWS
|
||||
local_thread = (HANDLE) _beginthreadex (NULL, 0,
|
||||
worker, ctx, 0 , NULL);
|
||||
local_thread = (HANDLE) _beginthreadex (NULL, 0, worker, ctx, 0, NULL);
|
||||
if (local_thread == 0) {
|
||||
printf ("error in _beginthreadex\n");
|
||||
return -1;
|
||||
@@ -238,8 +236,8 @@ int main (int argc, char *argv [])
|
||||
return -1;
|
||||
}
|
||||
|
||||
throughput = (unsigned long)
|
||||
((double) message_count / (double) elapsed * 1000000);
|
||||
throughput =
|
||||
(unsigned long) ((double) message_count / (double) elapsed * 1000000);
|
||||
megabits = (double) (throughput * message_size * 8) / 1000000;
|
||||
|
||||
printf ("mean throughput: %d [msg/s]\n", (int) throughput);
|
||||
@@ -247,4 +245,3 @@ int main (int argc, char *argv [])
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -51,7 +51,8 @@ int main (int argc, char *argv [])
|
||||
int curve = 0;
|
||||
|
||||
if (argc != 4 && argc != 5) {
|
||||
printf ("usage: local_thr <bind-to> <message-size> <message-count> [<enable_curve>]\n");
|
||||
printf ("usage: local_thr <bind-to> <message-size> <message-count> "
|
||||
"[<enable_curve>]\n");
|
||||
return 1;
|
||||
}
|
||||
bind_to = argv[1];
|
||||
@@ -76,7 +77,8 @@ int main (int argc, char *argv [])
|
||||
// Add your socket options here.
|
||||
// For example ZMQ_RATE, ZMQ_RECOVERY_IVL and ZMQ_MCAST_LOOP for PGM.
|
||||
if (curve) {
|
||||
rc = zmq_setsockopt (s, ZMQ_CURVE_SECRETKEY, server_prvkey, sizeof(server_prvkey));
|
||||
rc = zmq_setsockopt (s, ZMQ_CURVE_SECRETKEY, server_prvkey,
|
||||
sizeof (server_prvkey));
|
||||
if (rc != 0) {
|
||||
printf ("error in zmq_setsockoopt: %s\n", zmq_strerror (errno));
|
||||
return -1;
|
||||
@@ -135,8 +137,7 @@ int main (int argc, char *argv [])
|
||||
return -1;
|
||||
}
|
||||
|
||||
throughput =
|
||||
((double) message_count / (double) elapsed * 1000000);
|
||||
throughput = ((double) message_count / (double) elapsed * 1000000);
|
||||
megabits = ((double) throughput * message_size * 8) / 1000000;
|
||||
|
||||
printf ("message size: %d [B]\n", (int) message_size);
|
||||
|
@@ -76,19 +76,22 @@ int main (int argc, char *argv [])
|
||||
// Add your socket options here.
|
||||
// For example ZMQ_RATE, ZMQ_RECOVERY_IVL and ZMQ_MCAST_LOOP for PGM.
|
||||
if (curve) {
|
||||
rc = zmq_setsockopt (s, ZMQ_CURVE_SECRETKEY, client_prvkey, sizeof (client_prvkey));
|
||||
rc = zmq_setsockopt (s, ZMQ_CURVE_SECRETKEY, client_prvkey,
|
||||
sizeof (client_prvkey));
|
||||
if (rc != 0) {
|
||||
printf ("error in zmq_setsockoopt: %s\n", zmq_strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = zmq_setsockopt (s, ZMQ_CURVE_PUBLICKEY, client_pubkey, sizeof (client_pubkey));
|
||||
rc = zmq_setsockopt (s, ZMQ_CURVE_PUBLICKEY, client_pubkey,
|
||||
sizeof (client_pubkey));
|
||||
if (rc != 0) {
|
||||
printf ("error in zmq_setsockoopt: %s\n", zmq_strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = zmq_setsockopt (s, ZMQ_CURVE_SERVERKEY, server_pubkey, sizeof (server_pubkey));
|
||||
rc = zmq_setsockopt (s, ZMQ_CURVE_SERVERKEY, server_pubkey,
|
||||
sizeof (server_pubkey));
|
||||
if (rc != 0) {
|
||||
printf ("error in zmq_setsockoopt: %s\n", zmq_strerror (errno));
|
||||
return -1;
|
||||
|
@@ -44,9 +44,10 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
zmq::address_t::address_t (
|
||||
const std::string &protocol_, const std::string &address_, ctx_t *parent_)
|
||||
: protocol (protocol_),
|
||||
zmq::address_t::address_t (const std::string &protocol_,
|
||||
const std::string &address_,
|
||||
ctx_t *parent_) :
|
||||
protocol (protocol_),
|
||||
address (address_),
|
||||
parent (parent_)
|
||||
{
|
||||
@@ -66,24 +67,21 @@ zmq::address_t::~address_t ()
|
||||
}
|
||||
}
|
||||
#if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS
|
||||
else
|
||||
if (protocol == "ipc") {
|
||||
else if (protocol == "ipc") {
|
||||
if (resolved.ipc_addr) {
|
||||
LIBZMQ_DELETE (resolved.ipc_addr);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined ZMQ_HAVE_TIPC
|
||||
else
|
||||
if (protocol == "tipc") {
|
||||
else if (protocol == "tipc") {
|
||||
if (resolved.tipc_addr) {
|
||||
LIBZMQ_DELETE (resolved.tipc_addr);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined ZMQ_HAVE_VMCI
|
||||
else
|
||||
if (protocol == "vmci") {
|
||||
else if (protocol == "vmci") {
|
||||
if (resolved.vmci_addr) {
|
||||
LIBZMQ_DELETE (resolved.vmci_addr);
|
||||
}
|
||||
@@ -102,22 +100,19 @@ int zmq::address_t::to_string (std::string &addr_) const
|
||||
return resolved.udp_addr->to_string (addr_);
|
||||
}
|
||||
#if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS
|
||||
else
|
||||
if (protocol == "ipc") {
|
||||
else if (protocol == "ipc") {
|
||||
if (resolved.ipc_addr)
|
||||
return resolved.ipc_addr->to_string (addr_);
|
||||
}
|
||||
#endif
|
||||
#if defined ZMQ_HAVE_TIPC
|
||||
else
|
||||
if (protocol == "tipc") {
|
||||
else if (protocol == "tipc") {
|
||||
if (resolved.tipc_addr)
|
||||
return resolved.tipc_addr->to_string (addr_);
|
||||
}
|
||||
#endif
|
||||
#if defined ZMQ_HAVE_VMCI
|
||||
else
|
||||
if (protocol == "vmci") {
|
||||
else if (protocol == "vmci") {
|
||||
if (resolved.vmci_addr)
|
||||
return resolved.vmci_addr->to_string (addr_);
|
||||
}
|
||||
|
@@ -46,8 +46,11 @@ namespace zmq
|
||||
#if defined ZMQ_HAVE_VMCI
|
||||
class vmci_address_t;
|
||||
#endif
|
||||
struct address_t {
|
||||
address_t (const std::string &protocol_, const std::string &address_, ctx_t *parent_);
|
||||
struct address_t
|
||||
{
|
||||
address_t (const std::string &protocol_,
|
||||
const std::string &address_,
|
||||
ctx_t *parent_);
|
||||
|
||||
~address_t ();
|
||||
|
||||
@@ -56,7 +59,8 @@ namespace zmq
|
||||
ctx_t *parent;
|
||||
|
||||
// Protocol specific resolved address
|
||||
union {
|
||||
union
|
||||
{
|
||||
tcp_address_t *tcp_addr;
|
||||
udp_address_t *udp_addr;
|
||||
#if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS
|
||||
|
@@ -51,30 +51,17 @@ namespace zmq
|
||||
template <int ID = 0> class array_item_t
|
||||
{
|
||||
public:
|
||||
|
||||
inline array_item_t () :
|
||||
array_index (-1)
|
||||
{
|
||||
}
|
||||
inline array_item_t () : array_index (-1) {}
|
||||
|
||||
// The destructor doesn't have to be virtual. It is made virtual
|
||||
// just to keep ICC and code checking tools from complaining.
|
||||
inline virtual ~array_item_t ()
|
||||
{
|
||||
}
|
||||
inline virtual ~array_item_t () {}
|
||||
|
||||
inline void set_array_index (int index_)
|
||||
{
|
||||
array_index = index_;
|
||||
}
|
||||
inline void set_array_index (int index_) { array_index = index_; }
|
||||
|
||||
inline int get_array_index ()
|
||||
{
|
||||
return array_index;
|
||||
}
|
||||
inline int get_array_index () { return array_index; }
|
||||
|
||||
private:
|
||||
|
||||
int array_index;
|
||||
|
||||
array_item_t (const array_item_t &);
|
||||
@@ -85,35 +72,20 @@ namespace zmq
|
||||
template <typename T, int ID = 0> class array_t
|
||||
{
|
||||
private:
|
||||
|
||||
typedef array_item_t<ID> item_t;
|
||||
|
||||
public:
|
||||
|
||||
typedef typename std::vector<T *>::size_type size_type;
|
||||
|
||||
inline array_t ()
|
||||
{
|
||||
}
|
||||
inline array_t () {}
|
||||
|
||||
inline ~array_t ()
|
||||
{
|
||||
}
|
||||
inline ~array_t () {}
|
||||
|
||||
inline size_type size ()
|
||||
{
|
||||
return items.size ();
|
||||
}
|
||||
inline size_type size () { return items.size (); }
|
||||
|
||||
inline bool empty ()
|
||||
{
|
||||
return items.empty ();
|
||||
}
|
||||
inline bool empty () { return items.empty (); }
|
||||
|
||||
inline T *&operator [] (size_type index_)
|
||||
{
|
||||
return items [index_];
|
||||
}
|
||||
inline T *&operator[] (size_type index_) { return items[index_]; }
|
||||
|
||||
inline void push_back (T *item_)
|
||||
{
|
||||
@@ -122,11 +94,13 @@ namespace zmq
|
||||
items.push_back (item_);
|
||||
}
|
||||
|
||||
inline void erase (T *item_) {
|
||||
inline void erase (T *item_)
|
||||
{
|
||||
erase (((item_t *) item_)->get_array_index ());
|
||||
}
|
||||
|
||||
inline void erase (size_type index_) {
|
||||
inline void erase (size_type index_)
|
||||
{
|
||||
if (items.back ())
|
||||
((item_t *) items.back ())->set_array_index ((int) index_);
|
||||
items[index_] = items.back ();
|
||||
@@ -142,10 +116,7 @@ namespace zmq
|
||||
std::swap (items[index1_], items[index2_]);
|
||||
}
|
||||
|
||||
inline void clear ()
|
||||
{
|
||||
items.clear ();
|
||||
}
|
||||
inline void clear () { items.clear (); }
|
||||
|
||||
inline size_type index (T *item_)
|
||||
{
|
||||
@@ -153,15 +124,12 @@ namespace zmq
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
typedef std::vector<T *> items_t;
|
||||
items_t items;
|
||||
|
||||
array_t (const array_t &);
|
||||
const array_t &operator= (const array_t &);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -44,7 +44,8 @@
|
||||
#define ZMQ_ATOMIC_COUNTER_ARM
|
||||
#elif defined ZMQ_HAVE_WINDOWS
|
||||
#define ZMQ_ATOMIC_COUNTER_WINDOWS
|
||||
#elif (defined ZMQ_HAVE_SOLARIS || defined ZMQ_HAVE_NETBSD || defined ZMQ_HAVE_GNU)
|
||||
#elif (defined ZMQ_HAVE_SOLARIS || defined ZMQ_HAVE_NETBSD \
|
||||
|| defined ZMQ_HAVE_GNU)
|
||||
#define ZMQ_ATOMIC_COUNTER_ATOMIC_H
|
||||
#elif defined __tile__
|
||||
#define ZMQ_ATOMIC_COUNTER_TILE
|
||||
@@ -66,7 +67,6 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
// This class represents an integer that can be incremented/decremented
|
||||
// in atomic fashion.
|
||||
//
|
||||
@@ -87,23 +87,14 @@ namespace zmq
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
|
||||
typedef uint32_t integer_t;
|
||||
|
||||
inline atomic_counter_t (integer_t value_ = 0) :
|
||||
value (value_)
|
||||
{
|
||||
}
|
||||
inline atomic_counter_t (integer_t value_ = 0) : value (value_) {}
|
||||
|
||||
inline ~atomic_counter_t ()
|
||||
{
|
||||
}
|
||||
inline ~atomic_counter_t () {}
|
||||
|
||||
// Set counter value (not thread-safe).
|
||||
inline void set (integer_t value_)
|
||||
{
|
||||
value = value_;
|
||||
}
|
||||
inline void set (integer_t value_) { value = value_; }
|
||||
|
||||
// Atomic addition. Returns the old value.
|
||||
inline integer_t add (integer_t increment_)
|
||||
@@ -122,22 +113,21 @@ namespace zmq
|
||||
#elif defined ZMQ_ATOMIC_COUNTER_TILE
|
||||
old_value = arch_atomic_add (&value, increment_);
|
||||
#elif defined ZMQ_ATOMIC_COUNTER_X86
|
||||
__asm__ volatile (
|
||||
"lock; xadd %0, %1 \n\t"
|
||||
__asm__ volatile("lock; xadd %0, %1 \n\t"
|
||||
: "=r"(old_value), "=m"(value)
|
||||
: "0"(increment_), "m"(value)
|
||||
: "cc", "memory");
|
||||
#elif defined ZMQ_ATOMIC_COUNTER_ARM
|
||||
integer_t flag, tmp;
|
||||
__asm__ volatile (
|
||||
" dmb sy\n\t"
|
||||
__asm__ volatile(" dmb sy\n\t"
|
||||
"1: ldrex %0, [%5]\n\t"
|
||||
" add %2, %0, %4\n\t"
|
||||
" strex %1, %2, [%5]\n\t"
|
||||
" teq %1, #0\n\t"
|
||||
" bne 1b\n\t"
|
||||
" dmb sy\n\t"
|
||||
: "=&r"(old_value), "=&r"(flag), "=&r"(tmp), "+Qo"(value)
|
||||
: "=&r"(old_value), "=&r"(flag), "=&r"(tmp),
|
||||
"+Qo"(value)
|
||||
: "Ir"(increment_), "r"(&value)
|
||||
: "cc");
|
||||
#elif defined ZMQ_ATOMIC_COUNTER_MUTEX
|
||||
@@ -182,15 +172,15 @@ namespace zmq
|
||||
return oldval != decrement;
|
||||
#elif defined ZMQ_ATOMIC_COUNTER_ARM
|
||||
integer_t old_value, flag, tmp;
|
||||
__asm__ volatile (
|
||||
" dmb sy\n\t"
|
||||
__asm__ volatile(" dmb sy\n\t"
|
||||
"1: ldrex %0, [%5]\n\t"
|
||||
" sub %2, %0, %4\n\t"
|
||||
" strex %1, %2, [%5]\n\t"
|
||||
" teq %1, #0\n\t"
|
||||
" bne 1b\n\t"
|
||||
" dmb sy\n\t"
|
||||
: "=&r"(old_value), "=&r"(flag), "=&r"(tmp), "+Qo"(value)
|
||||
: "=&r"(old_value), "=&r"(flag), "=&r"(tmp),
|
||||
"+Qo"(value)
|
||||
: "Ir"(decrement), "r"(&value)
|
||||
: "cc");
|
||||
return old_value - decrement != 0;
|
||||
@@ -205,13 +195,9 @@ namespace zmq
|
||||
#endif
|
||||
}
|
||||
|
||||
inline integer_t get () const
|
||||
{
|
||||
return value;
|
||||
}
|
||||
inline integer_t get () const { return value; }
|
||||
|
||||
private:
|
||||
|
||||
#if defined ZMQ_ATOMIC_COUNTER_CXX11
|
||||
std::atomic<integer_t> value;
|
||||
#else
|
||||
@@ -226,14 +212,13 @@ namespace zmq
|
||||
atomic_counter_t (const atomic_counter_t &);
|
||||
const atomic_counter_t &operator= (const atomic_counter_t &);
|
||||
#endif
|
||||
#if defined (__GNUC__) || defined ( __INTEL_COMPILER) || \
|
||||
(defined (__SUNPRO_C) && __SUNPRO_C >= 0x590) || \
|
||||
(defined (__SUNPRO_CC) && __SUNPRO_CC >= 0x590)
|
||||
#if defined(__GNUC__) || defined(__INTEL_COMPILER) \
|
||||
|| (defined(__SUNPRO_C) && __SUNPRO_C >= 0x590) \
|
||||
|| (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x590)
|
||||
} __attribute__ ((aligned (sizeof (void *))));
|
||||
#else
|
||||
};
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
// Remove macros local to this file.
|
||||
|
@@ -44,7 +44,8 @@
|
||||
#define ZMQ_ATOMIC_PTR_TILE
|
||||
#elif defined ZMQ_HAVE_WINDOWS
|
||||
#define ZMQ_ATOMIC_PTR_WINDOWS
|
||||
#elif (defined ZMQ_HAVE_SOLARIS || defined ZMQ_HAVE_NETBSD || defined ZMQ_HAVE_GNU)
|
||||
#elif (defined ZMQ_HAVE_SOLARIS || defined ZMQ_HAVE_NETBSD \
|
||||
|| defined ZMQ_HAVE_GNU)
|
||||
#define ZMQ_ATOMIC_PTR_ATOMIC_H
|
||||
#else
|
||||
#define ZMQ_ATOMIC_PTR_MUTEX
|
||||
@@ -64,31 +65,21 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
// This class encapsulates several atomic operations on pointers.
|
||||
|
||||
template <typename T> class atomic_ptr_t
|
||||
{
|
||||
public:
|
||||
|
||||
// Initialise atomic pointer
|
||||
inline atomic_ptr_t ()
|
||||
{
|
||||
ptr = NULL;
|
||||
}
|
||||
inline atomic_ptr_t () { ptr = NULL; }
|
||||
|
||||
// Destroy atomic pointer
|
||||
inline ~atomic_ptr_t ()
|
||||
{
|
||||
}
|
||||
inline ~atomic_ptr_t () {}
|
||||
|
||||
// Set value of atomic pointer in a non-threadsafe way
|
||||
// Use this function only when you are sure that at most one
|
||||
// thread is accessing the pointer at the moment.
|
||||
inline void set (T *ptr_)
|
||||
{
|
||||
this->ptr = ptr_;
|
||||
}
|
||||
inline void set (T *ptr_) { this->ptr = ptr_; }
|
||||
|
||||
// Perform atomic 'exchange pointers' operation. Pointer is set
|
||||
// to the 'val' value. Old value is returned.
|
||||
@@ -106,16 +97,14 @@ namespace zmq
|
||||
return (T *) arch_atomic_exchange (&ptr, val_);
|
||||
#elif defined ZMQ_ATOMIC_PTR_X86
|
||||
T *old;
|
||||
__asm__ volatile (
|
||||
"lock; xchg %0, %2"
|
||||
__asm__ volatile("lock; xchg %0, %2"
|
||||
: "=r"(old), "=m"(ptr)
|
||||
: "m"(ptr), "0"(val_));
|
||||
return old;
|
||||
#elif defined ZMQ_ATOMIC_PTR_ARM
|
||||
T *old;
|
||||
unsigned int flag;
|
||||
__asm__ volatile (
|
||||
" dmb sy\n\t"
|
||||
__asm__ volatile(" dmb sy\n\t"
|
||||
"1: ldrex %1, [%3]\n\t"
|
||||
" strex %0, %4, [%3]\n\t"
|
||||
" teq %0, #0\n\t"
|
||||
@@ -143,8 +132,8 @@ namespace zmq
|
||||
inline T *cas (T *cmp_, T *val_)
|
||||
{
|
||||
#if defined ZMQ_ATOMIC_PTR_WINDOWS
|
||||
return (T*) InterlockedCompareExchangePointer (
|
||||
(volatile PVOID*) &ptr, val_, cmp_);
|
||||
return (T *) InterlockedCompareExchangePointer ((volatile PVOID *) &ptr,
|
||||
val_, cmp_);
|
||||
#elif defined ZMQ_ATOMIC_PTR_INTRINSIC
|
||||
T *old = cmp_;
|
||||
__atomic_compare_exchange_n (&ptr, (volatile T **) &old, val_, false,
|
||||
@@ -159,8 +148,7 @@ namespace zmq
|
||||
return (T *) arch_atomic_val_compare_and_exchange (&ptr, cmp_, val_);
|
||||
#elif defined ZMQ_ATOMIC_PTR_X86
|
||||
T *old;
|
||||
__asm__ volatile (
|
||||
"lock; cmpxchg %2, %3"
|
||||
__asm__ volatile("lock; cmpxchg %2, %3"
|
||||
: "=a"(old), "=m"(ptr)
|
||||
: "r"(val_), "m"(ptr), "0"(cmp_)
|
||||
: "cc");
|
||||
@@ -168,8 +156,7 @@ namespace zmq
|
||||
#elif defined ZMQ_ATOMIC_PTR_ARM
|
||||
T *old;
|
||||
unsigned int flag;
|
||||
__asm__ volatile (
|
||||
" dmb sy\n\t"
|
||||
__asm__ volatile(" dmb sy\n\t"
|
||||
"1: ldrex %1, [%3]\n\t"
|
||||
" mov %0, #0\n\t"
|
||||
" teq %1, %4\n\t"
|
||||
@@ -195,7 +182,6 @@ namespace zmq
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
#if defined ZMQ_ATOMIC_PTR_CXX11
|
||||
std::atomic<T *> ptr;
|
||||
#else
|
||||
@@ -211,7 +197,6 @@ namespace zmq
|
||||
const atomic_ptr_t &operator= (const atomic_ptr_t &);
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
// Remove macros local to this file.
|
||||
|
80
src/blob.hpp
80
src/blob.hpp
@@ -47,7 +47,9 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
struct reference_tag_t {};
|
||||
struct reference_tag_t
|
||||
{
|
||||
};
|
||||
|
||||
// Object to hold dynamically allocated opaque binary data.
|
||||
// On modern compilers, it will be movable but not copyable. Copies
|
||||
@@ -59,19 +61,19 @@ namespace zmq
|
||||
blob_t () : data_ (0), size_ (0), owned_ (true) {}
|
||||
|
||||
// Creates a blob_t of a given size, with uninitialized content.
|
||||
blob_t (const size_t size)
|
||||
: data_ ((unsigned char*)malloc (size))
|
||||
, size_ (size)
|
||||
, owned_ (true)
|
||||
blob_t (const size_t size) :
|
||||
data_ ((unsigned char *) malloc (size)),
|
||||
size_ (size),
|
||||
owned_ (true)
|
||||
{
|
||||
}
|
||||
|
||||
// Creates a blob_t of a given size, an initializes content by copying
|
||||
// from another buffer.
|
||||
blob_t(const unsigned char * const data, const size_t size)
|
||||
: data_ ((unsigned char*)malloc (size))
|
||||
, size_ (size)
|
||||
, owned_ (true)
|
||||
blob_t (const unsigned char *const data, const size_t size) :
|
||||
data_ ((unsigned char *) malloc (size)),
|
||||
size_ (size),
|
||||
owned_ (true)
|
||||
{
|
||||
memcpy (data_, data, size_);
|
||||
}
|
||||
@@ -80,10 +82,10 @@ namespace zmq
|
||||
// pre-allocated block of data.
|
||||
// Use with caution and ensure that the blob_t will not outlive
|
||||
// the referenced data.
|
||||
blob_t (unsigned char * const data, const size_t size, reference_tag_t)
|
||||
: data_ (data)
|
||||
, size_ (size)
|
||||
, owned_ (false)
|
||||
blob_t (unsigned char *const data, const size_t size, reference_tag_t) :
|
||||
data_ (data),
|
||||
size_ (size),
|
||||
owned_ (false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -91,17 +93,14 @@ namespace zmq
|
||||
size_t size () const { return size_; }
|
||||
|
||||
// Returns a pointer to the data of the blob_t.
|
||||
const unsigned char *data() const {
|
||||
return data_;
|
||||
}
|
||||
const unsigned char *data () const { return data_; }
|
||||
|
||||
// Returns a pointer to the data of the blob_t.
|
||||
unsigned char *data() {
|
||||
return data_;
|
||||
}
|
||||
unsigned char *data () { return data_; }
|
||||
|
||||
// Defines an order relationship on blob_t.
|
||||
bool operator< (blob_t const &other) const {
|
||||
bool operator< (blob_t const &other) const
|
||||
{
|
||||
int cmpres = memcmp (data_, other.data_, std::min (size_, other.size_));
|
||||
return cmpres < 0 || (cmpres == 0 && size_ < other.size_);
|
||||
}
|
||||
@@ -127,29 +126,36 @@ namespace zmq
|
||||
}
|
||||
|
||||
// Empties a blob_t.
|
||||
void clear () {
|
||||
if (owned_) { free (data_); }
|
||||
data_ = 0; size_ = 0;
|
||||
void clear ()
|
||||
{
|
||||
if (owned_) {
|
||||
free (data_);
|
||||
}
|
||||
data_ = 0;
|
||||
size_ = 0;
|
||||
}
|
||||
|
||||
~blob_t () {
|
||||
if (owned_) { free (data_); }
|
||||
~blob_t ()
|
||||
{
|
||||
if (owned_) {
|
||||
free (data_);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ZMQ_HAS_MOVE_SEMANTICS
|
||||
blob_t (const blob_t &) = delete;
|
||||
blob_t &operator= (const blob_t &) = delete;
|
||||
|
||||
blob_t (blob_t&& other)
|
||||
: data_ (other.data_)
|
||||
, size_ (other.size_)
|
||||
, owned_ (other.owned_)
|
||||
blob_t (blob_t &&other) :
|
||||
data_ (other.data_),
|
||||
size_ (other.size_),
|
||||
owned_ (other.owned_)
|
||||
{
|
||||
other.owned_ = false;
|
||||
}
|
||||
blob_t &operator= (blob_t&& other) {
|
||||
if (this != &other)
|
||||
blob_t &operator= (blob_t &&other)
|
||||
{
|
||||
if (this != &other) {
|
||||
clear ();
|
||||
data_ = other.data_;
|
||||
size_ = other.size_;
|
||||
@@ -159,14 +165,10 @@ namespace zmq
|
||||
return *this;
|
||||
}
|
||||
#else
|
||||
blob_t (const blob_t &other)
|
||||
: owned_(false)
|
||||
{
|
||||
set_deep_copy (other);
|
||||
}
|
||||
blob_t &operator= (const blob_t &other) {
|
||||
if (this != &other)
|
||||
blob_t (const blob_t &other) : owned_ (false) { set_deep_copy (other); }
|
||||
blob_t &operator= (const blob_t &other)
|
||||
{
|
||||
if (this != &other) {
|
||||
clear ();
|
||||
set_deep_copy (other);
|
||||
}
|
||||
@@ -179,8 +181,6 @@ namespace zmq
|
||||
size_t size_;
|
||||
bool owned_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -69,7 +69,6 @@ int zmq::client_t::xrecv (msg_t *msg_)
|
||||
|
||||
// Drop any messages with more flag
|
||||
while (rc == 0 && msg_->flags () & msg_t::more) {
|
||||
|
||||
// drop all frames of the current multi-frame message
|
||||
rc = fq.recvpipe (msg_, NULL);
|
||||
|
||||
|
@@ -37,23 +37,19 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
class ctx_t;
|
||||
class msg_t;
|
||||
class pipe_t;
|
||||
class io_thread_t;
|
||||
class socket_base_t;
|
||||
|
||||
class client_t :
|
||||
public socket_base_t
|
||||
class client_t : public socket_base_t
|
||||
{
|
||||
public:
|
||||
|
||||
client_t (zmq::ctx_t *parent_, uint32_t tid_, int sid);
|
||||
~client_t ();
|
||||
|
||||
protected:
|
||||
|
||||
// Overrides of functions from socket_base_t.
|
||||
void xattach_pipe (zmq::pipe_t *pipe_, bool subscribe_to_all_);
|
||||
int xsend (zmq::msg_t *msg_);
|
||||
@@ -66,7 +62,6 @@ namespace zmq
|
||||
void xpipe_terminated (zmq::pipe_t *pipe_);
|
||||
|
||||
private:
|
||||
|
||||
// Messages are fair-queued from inbound pipes. And load-balanced to
|
||||
// the outbound pipes.
|
||||
fq_t fq;
|
||||
@@ -75,7 +70,6 @@ namespace zmq
|
||||
client_t (const client_t &);
|
||||
const client_t &operator= (const client_t &);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -92,7 +92,8 @@ ULONGLONG compatible_get_tick_count64()
|
||||
++s_wrap;
|
||||
|
||||
s_last_tick = current_tick;
|
||||
const ULONGLONG result = (static_cast<ULONGLONG>(s_wrap) << 32) + static_cast<ULONGLONG>(current_tick);
|
||||
const ULONGLONG result = (static_cast<ULONGLONG> (s_wrap) << 32)
|
||||
+ static_cast<ULONGLONG> (current_tick);
|
||||
|
||||
return result;
|
||||
#endif
|
||||
@@ -105,7 +106,8 @@ f_compatible_get_tick_count64 init_compatible_get_tick_count64()
|
||||
|
||||
HMODULE module = ::LoadLibraryA ("Kernel32.dll");
|
||||
if (module != NULL)
|
||||
func = reinterpret_cast<f_compatible_get_tick_count64>(::GetProcAddress(module, "GetTickCount64"));
|
||||
func = reinterpret_cast<f_compatible_get_tick_count64> (
|
||||
::GetProcAddress (module, "GetTickCount64"));
|
||||
#endif
|
||||
if (func == NULL)
|
||||
func = compatible_get_tick_count64;
|
||||
@@ -117,7 +119,8 @@ f_compatible_get_tick_count64 init_compatible_get_tick_count64()
|
||||
return func;
|
||||
}
|
||||
|
||||
static f_compatible_get_tick_count64 my_get_tick_count64 = init_compatible_get_tick_count64();
|
||||
static f_compatible_get_tick_count64 my_get_tick_count64 =
|
||||
init_compatible_get_tick_count64 ();
|
||||
#endif
|
||||
|
||||
zmq::clock_t::clock_t () :
|
||||
@@ -156,7 +159,8 @@ uint64_t zmq::clock_t::now_us ()
|
||||
// Use POSIX clock_gettime function to get precise monotonic time.
|
||||
struct timespec tv;
|
||||
|
||||
#if defined ZMQ_HAVE_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED < 101200 // less than macOS 10.12
|
||||
#if defined ZMQ_HAVE_OSX \
|
||||
&& __MAC_OS_X_VERSION_MIN_REQUIRED < 101200 // less than macOS 10.12
|
||||
int rc = alt_clock_gettime (SYSTEM_CLOCK, &tv);
|
||||
#else
|
||||
int rc = clock_gettime (CLOCK_MONOTONIC, &tv);
|
||||
@@ -193,8 +197,7 @@ uint64_t zmq::clock_t::now_ms ()
|
||||
uint64_t tsc = rdtsc ();
|
||||
|
||||
// If TSC is not supported, get precise time and chop off the microseconds.
|
||||
if (!tsc)
|
||||
{
|
||||
if (!tsc) {
|
||||
#ifdef ZMQ_HAVE_WINDOWS
|
||||
// Under Windows, now_us is not so reliable since QueryPerformanceCounter
|
||||
// does not guarantee that it will use a hardware that offers a monotonic timer.
|
||||
@@ -229,9 +232,10 @@ uint64_t zmq::clock_t::rdtsc ()
|
||||
uint32_t low, high;
|
||||
__asm__ volatile("rdtsc" : "=a"(low), "=d"(high));
|
||||
return (uint64_t) high << 32 | low;
|
||||
#elif (defined __SUNPRO_CC && (__SUNPRO_CC >= 0x5100) && (defined __i386 || \
|
||||
defined __amd64 || defined __x86_64))
|
||||
union {
|
||||
#elif (defined __SUNPRO_CC && (__SUNPRO_CC >= 0x5100) \
|
||||
&& (defined __i386 || defined __amd64 || defined __x86_64))
|
||||
union
|
||||
{
|
||||
uint64_t u64val;
|
||||
uint32_t u32val[2];
|
||||
} tsc;
|
||||
@@ -243,7 +247,8 @@ uint64_t zmq::clock_t::rdtsc ()
|
||||
return (tsc);
|
||||
#else
|
||||
struct timespec ts;
|
||||
#if defined ZMQ_HAVE_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED < 101200 // less than macOS 10.12
|
||||
#if defined ZMQ_HAVE_OSX \
|
||||
&& __MAC_OS_X_VERSION_MIN_REQUIRED < 101200 // less than macOS 10.12
|
||||
alt_clock_gettime (SYSTEM_CLOCK, &ts);
|
||||
#else
|
||||
clock_gettime (CLOCK_MONOTONIC, &ts);
|
||||
|
@@ -48,11 +48,9 @@ int alt_clock_gettime (int clock_id, timespec *ts);
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
class clock_t
|
||||
{
|
||||
public:
|
||||
|
||||
clock_t ();
|
||||
~clock_t ();
|
||||
|
||||
@@ -67,7 +65,6 @@ namespace zmq
|
||||
uint64_t now_ms ();
|
||||
|
||||
private:
|
||||
|
||||
// TSC timestamp of when last time measurement was made.
|
||||
uint64_t last_tsc;
|
||||
|
||||
@@ -77,7 +74,6 @@ namespace zmq
|
||||
clock_t (const clock_t &);
|
||||
const clock_t &operator= (const clock_t &);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -35,7 +35,6 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
class object_t;
|
||||
class own_t;
|
||||
struct i_engine;
|
||||
@@ -79,101 +78,118 @@ namespace zmq
|
||||
|
||||
union args_t
|
||||
{
|
||||
|
||||
// Sent to I/O thread to let it know that it should
|
||||
// terminate itself.
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
} stop;
|
||||
|
||||
// Sent to I/O object to make it register with its I/O thread.
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
} plug;
|
||||
|
||||
// Sent to socket to let it know about the newly created object.
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
zmq::own_t *object;
|
||||
} own;
|
||||
|
||||
// Attach the engine to the session. If engine is NULL, it informs
|
||||
// session that the connection have failed.
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
struct i_engine *engine;
|
||||
} attach;
|
||||
|
||||
// Sent from session to socket to establish pipe(s) between them.
|
||||
// Caller have used inc_seqnum beforehand sending the command.
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
zmq::pipe_t *pipe;
|
||||
} bind;
|
||||
|
||||
// Sent by pipe writer to inform dormant pipe reader that there
|
||||
// are messages in the pipe.
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
} activate_read;
|
||||
|
||||
// Sent by pipe reader to inform pipe writer about how many
|
||||
// messages it has read so far.
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
uint64_t msgs_read;
|
||||
} activate_write;
|
||||
|
||||
// Sent by pipe reader to writer after creating a new inpipe.
|
||||
// The parameter is actually of type pipe_t::upipe_t, however,
|
||||
// its definition is private so we'll have to do with void*.
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
void *pipe;
|
||||
} hiccup;
|
||||
|
||||
// Sent by pipe reader to pipe writer to ask it to terminate
|
||||
// its end of the pipe.
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
} pipe_term;
|
||||
|
||||
// Pipe writer acknowledges pipe_term command.
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
} pipe_term_ack;
|
||||
|
||||
// Sent by one of pipe to another part for modify hwm
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
int inhwm;
|
||||
int outhwm;
|
||||
} pipe_hwm;
|
||||
|
||||
// Sent by I/O object ot the socket to request the shutdown of
|
||||
// the I/O object.
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
zmq::own_t *object;
|
||||
} term_req;
|
||||
|
||||
// Sent by socket to I/O object to start its shutdown.
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
int linger;
|
||||
} term;
|
||||
|
||||
// Sent by I/O object to the socket to acknowledge it has
|
||||
// shut down.
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
} term_ack;
|
||||
|
||||
// Sent by session_base (I/O thread) to socket (application thread)
|
||||
// to ask to disconnect the endpoint.
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
std::string *endpoint;
|
||||
} term_endpoint;
|
||||
|
||||
// Transfers the ownership of the closed socket
|
||||
// to the reaper thread.
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
zmq::socket_base_t *socket;
|
||||
} reap;
|
||||
|
||||
// Closed socket notifies the reaper that it's already deallocated.
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
} reaped;
|
||||
|
||||
// Sent by reaper thread to the term thread when all the sockets
|
||||
// are successfully deallocated.
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
} done;
|
||||
|
||||
} args;
|
||||
|
@@ -58,19 +58,12 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
class condition_variable_t
|
||||
{
|
||||
public:
|
||||
inline condition_variable_t ()
|
||||
{
|
||||
zmq_assert(false);
|
||||
}
|
||||
inline condition_variable_t () { zmq_assert (false); }
|
||||
|
||||
inline ~condition_variable_t ()
|
||||
{
|
||||
|
||||
}
|
||||
inline ~condition_variable_t () {}
|
||||
|
||||
inline int wait (mutex_t *mutex_, int timeout_)
|
||||
{
|
||||
@@ -78,18 +71,13 @@ namespace zmq
|
||||
return -1;
|
||||
}
|
||||
|
||||
inline void broadcast ()
|
||||
{
|
||||
zmq_assert(false);
|
||||
}
|
||||
inline void broadcast () { zmq_assert (false); }
|
||||
|
||||
private:
|
||||
|
||||
// Disable copy construction and assignment.
|
||||
condition_variable_t (const condition_variable_t &);
|
||||
void operator= (const condition_variable_t &);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
@@ -106,15 +94,9 @@ namespace zmq
|
||||
class condition_variable_t
|
||||
{
|
||||
public:
|
||||
inline condition_variable_t ()
|
||||
{
|
||||
InitializeConditionVariable (&cv);
|
||||
}
|
||||
inline condition_variable_t () { InitializeConditionVariable (&cv); }
|
||||
|
||||
inline ~condition_variable_t ()
|
||||
{
|
||||
|
||||
}
|
||||
inline ~condition_variable_t () {}
|
||||
|
||||
inline int wait (mutex_t *mutex_, int timeout_)
|
||||
{
|
||||
@@ -132,13 +114,9 @@ namespace zmq
|
||||
return -1;
|
||||
}
|
||||
|
||||
inline void broadcast ()
|
||||
{
|
||||
WakeAllConditionVariable(&cv);
|
||||
}
|
||||
inline void broadcast () { WakeAllConditionVariable (&cv); }
|
||||
|
||||
private:
|
||||
|
||||
CONDITION_VARIABLE cv;
|
||||
|
||||
// Disable copy construction and assignment.
|
||||
@@ -149,15 +127,9 @@ namespace zmq
|
||||
class condition_variable_t
|
||||
{
|
||||
public:
|
||||
inline condition_variable_t()
|
||||
{
|
||||
inline condition_variable_t () {}
|
||||
|
||||
}
|
||||
|
||||
inline ~condition_variable_t()
|
||||
{
|
||||
|
||||
}
|
||||
inline ~condition_variable_t () {}
|
||||
|
||||
inline int wait (mutex_t *mutex_, int timeout_)
|
||||
{
|
||||
@@ -165,8 +137,10 @@ namespace zmq
|
||||
mutex_->unlock (); // unlock mutex_
|
||||
int res = 0;
|
||||
if (timeout_ == -1) {
|
||||
cv.wait(lck); // unlock mtx and wait cv.notify_all(), lock mtx after cv.notify_all()
|
||||
} else if (cv.wait_for(lck, std::chrono::milliseconds(timeout_)) == std::cv_status::timeout) {
|
||||
cv.wait (
|
||||
lck); // unlock mtx and wait cv.notify_all(), lock mtx after cv.notify_all()
|
||||
} else if (cv.wait_for (lck, std::chrono::milliseconds (timeout_))
|
||||
== std::cv_status::timeout) {
|
||||
// time expired
|
||||
errno = EAGAIN;
|
||||
res = -1;
|
||||
@@ -183,7 +157,6 @@ namespace zmq
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
std::condition_variable cv;
|
||||
std::mutex mtx;
|
||||
|
||||
@@ -203,7 +176,6 @@ namespace zmq
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
class condition_variable_t
|
||||
{
|
||||
public:
|
||||
@@ -226,7 +198,8 @@ namespace zmq
|
||||
if (timeout_ != -1) {
|
||||
struct timespec timeout;
|
||||
|
||||
#if defined ZMQ_HAVE_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED < 101200 // less than macOS 10.12
|
||||
#if defined ZMQ_HAVE_OSX \
|
||||
&& __MAC_OS_X_VERSION_MIN_REQUIRED < 101200 // less than macOS 10.12
|
||||
alt_clock_gettime (SYSTEM_CLOCK, &timeout);
|
||||
#else
|
||||
clock_gettime (CLOCK_MONOTONIC, &timeout);
|
||||
@@ -241,8 +214,7 @@ namespace zmq
|
||||
}
|
||||
|
||||
rc = pthread_cond_timedwait (&cond, mutex_->get_mutex (), &timeout);
|
||||
}
|
||||
else
|
||||
} else
|
||||
rc = pthread_cond_wait (&cond, mutex_->get_mutex ());
|
||||
|
||||
if (rc == 0)
|
||||
@@ -264,7 +236,6 @@ namespace zmq
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
pthread_cond_t cond;
|
||||
|
||||
// Disable copy construction and assignment.
|
||||
|
@@ -32,7 +32,6 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
// Compile-time settings.
|
||||
|
||||
enum
|
||||
@@ -92,7 +91,6 @@ namespace zmq
|
||||
// https://github.com/zeromq/libzmq/issues/1542
|
||||
signaler_port = 0
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
159
src/ctx.cpp
159
src/ctx.cpp
@@ -57,7 +57,8 @@
|
||||
|
||||
int clipped_maxsocket (int max_requested)
|
||||
{
|
||||
if (max_requested >= zmq::poller_t::max_fds () && zmq::poller_t::max_fds () != -1)
|
||||
if (max_requested >= zmq::poller_t::max_fds ()
|
||||
&& zmq::poller_t::max_fds () != -1)
|
||||
// -1 because we need room for the reaper mailbox.
|
||||
max_requested = zmq::poller_t::max_fds () - 1;
|
||||
|
||||
@@ -141,7 +142,8 @@ int zmq::ctx_t::terminate ()
|
||||
|
||||
// Connect up any pending inproc connections, otherwise we will hang
|
||||
pending_connections_t copy = pending_connections;
|
||||
for (pending_connections_t::iterator p = copy.begin (); p != copy.end (); ++p) {
|
||||
for (pending_connections_t::iterator p = copy.begin (); p != copy.end ();
|
||||
++p) {
|
||||
zmq::socket_base_t *s = create_socket (ZMQ_PAIR);
|
||||
// create_socket might fail eg: out of memory/sockets limit reached
|
||||
zmq_assert (s);
|
||||
@@ -229,38 +231,26 @@ int zmq::ctx_t::shutdown ()
|
||||
int zmq::ctx_t::set (int option_, int optval_)
|
||||
{
|
||||
int rc = 0;
|
||||
if (option_ == ZMQ_MAX_SOCKETS
|
||||
&& optval_ >= 1 && optval_ == clipped_maxsocket (optval_)) {
|
||||
if (option_ == ZMQ_MAX_SOCKETS && optval_ >= 1
|
||||
&& optval_ == clipped_maxsocket (optval_)) {
|
||||
scoped_lock_t locker (opt_sync);
|
||||
max_sockets = optval_;
|
||||
}
|
||||
else
|
||||
if (option_ == ZMQ_IO_THREADS && optval_ >= 0) {
|
||||
} else if (option_ == ZMQ_IO_THREADS && optval_ >= 0) {
|
||||
scoped_lock_t locker (opt_sync);
|
||||
io_thread_count = optval_;
|
||||
}
|
||||
else
|
||||
if (option_ == ZMQ_IPV6 && optval_ >= 0) {
|
||||
} else if (option_ == ZMQ_IPV6 && optval_ >= 0) {
|
||||
scoped_lock_t locker (opt_sync);
|
||||
ipv6 = (optval_ != 0);
|
||||
}
|
||||
else
|
||||
if (option_ == ZMQ_THREAD_PRIORITY && optval_ >= 0) {
|
||||
} else if (option_ == ZMQ_THREAD_PRIORITY && optval_ >= 0) {
|
||||
scoped_lock_t locker (opt_sync);
|
||||
thread_priority = optval_;
|
||||
}
|
||||
else
|
||||
if (option_ == ZMQ_THREAD_SCHED_POLICY && optval_ >= 0) {
|
||||
} else if (option_ == ZMQ_THREAD_SCHED_POLICY && optval_ >= 0) {
|
||||
scoped_lock_t locker (opt_sync);
|
||||
thread_sched_policy = optval_;
|
||||
}
|
||||
else
|
||||
if (option_ == ZMQ_THREAD_AFFINITY_CPU_ADD && optval_ >= 0) {
|
||||
} else if (option_ == ZMQ_THREAD_AFFINITY_CPU_ADD && optval_ >= 0) {
|
||||
scoped_lock_t locker (opt_sync);
|
||||
thread_affinity_cpus.insert (optval_);
|
||||
}
|
||||
else
|
||||
if (option_ == ZMQ_THREAD_AFFINITY_CPU_REMOVE && optval_ >= 0) {
|
||||
} else if (option_ == ZMQ_THREAD_AFFINITY_CPU_REMOVE && optval_ >= 0) {
|
||||
scoped_lock_t locker (opt_sync);
|
||||
std::set<int>::iterator it = thread_affinity_cpus.find (optval_);
|
||||
if (it != thread_affinity_cpus.end ()) {
|
||||
@@ -269,25 +259,18 @@ int zmq::ctx_t::set (int option_, int optval_)
|
||||
errno = EINVAL;
|
||||
rc = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
if (option_ == ZMQ_THREAD_NAME_PREFIX && optval_ >= 0) {
|
||||
} else if (option_ == ZMQ_THREAD_NAME_PREFIX && optval_ >= 0) {
|
||||
std::ostringstream s;
|
||||
s << optval_;
|
||||
scoped_lock_t locker (opt_sync);
|
||||
thread_name_prefix = s.str ();
|
||||
}
|
||||
else
|
||||
if (option_ == ZMQ_BLOCKY && optval_ >= 0) {
|
||||
} else if (option_ == ZMQ_BLOCKY && optval_ >= 0) {
|
||||
scoped_lock_t locker (opt_sync);
|
||||
blocky = (optval_ != 0);
|
||||
}
|
||||
else
|
||||
if (option_ == ZMQ_MAX_MSGSZ && optval_ >= 0) {
|
||||
} else if (option_ == ZMQ_MAX_MSGSZ && optval_ >= 0) {
|
||||
scoped_lock_t locker (opt_sync);
|
||||
max_msgsz = optval_ < INT_MAX ? optval_ : INT_MAX;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
errno = EINVAL;
|
||||
rc = -1;
|
||||
}
|
||||
@@ -299,23 +282,17 @@ int zmq::ctx_t::get (int option_)
|
||||
int rc = 0;
|
||||
if (option_ == ZMQ_MAX_SOCKETS)
|
||||
rc = max_sockets;
|
||||
else
|
||||
if (option_ == ZMQ_SOCKET_LIMIT)
|
||||
else if (option_ == ZMQ_SOCKET_LIMIT)
|
||||
rc = clipped_maxsocket (65535);
|
||||
else
|
||||
if (option_ == ZMQ_IO_THREADS)
|
||||
else if (option_ == ZMQ_IO_THREADS)
|
||||
rc = io_thread_count;
|
||||
else
|
||||
if (option_ == ZMQ_IPV6)
|
||||
else if (option_ == ZMQ_IPV6)
|
||||
rc = ipv6;
|
||||
else
|
||||
if (option_ == ZMQ_BLOCKY)
|
||||
else if (option_ == ZMQ_BLOCKY)
|
||||
rc = blocky;
|
||||
else
|
||||
if (option_ == ZMQ_MAX_MSGSZ)
|
||||
else if (option_ == ZMQ_MAX_MSGSZ)
|
||||
rc = max_msgsz;
|
||||
else
|
||||
if (option_ == ZMQ_MSG_T_SIZE)
|
||||
else if (option_ == ZMQ_MSG_T_SIZE)
|
||||
rc = sizeof (zmq_msg_t);
|
||||
else {
|
||||
errno = EINVAL;
|
||||
@@ -457,11 +434,14 @@ zmq::object_t *zmq::ctx_t::get_reaper ()
|
||||
return reaper;
|
||||
}
|
||||
|
||||
void zmq::ctx_t::start_thread (thread_t &thread_, thread_fn *tfn_, void *arg_) const
|
||||
void zmq::ctx_t::start_thread (thread_t &thread_,
|
||||
thread_fn *tfn_,
|
||||
void *arg_) const
|
||||
{
|
||||
static unsigned int nthreads_started = 0;
|
||||
|
||||
thread_.setSchedulingParameters(thread_priority, thread_sched_policy, thread_affinity_cpus);
|
||||
thread_.setSchedulingParameters (thread_priority, thread_sched_policy,
|
||||
thread_affinity_cpus);
|
||||
thread_.start (tfn_, arg_);
|
||||
#ifndef ZMQ_HAVE_ANDROID
|
||||
std::ostringstream s;
|
||||
@@ -503,8 +483,8 @@ int zmq::ctx_t::register_endpoint (const char *addr_,
|
||||
{
|
||||
scoped_lock_t locker (endpoints_sync);
|
||||
|
||||
const bool inserted = endpoints.ZMQ_MAP_INSERT_OR_EMPLACE (addr_,
|
||||
endpoint_).second;
|
||||
const bool inserted =
|
||||
endpoints.ZMQ_MAP_INSERT_OR_EMPLACE (addr_, endpoint_).second;
|
||||
if (!inserted) {
|
||||
errno = EADDRINUSE;
|
||||
return -1;
|
||||
@@ -512,8 +492,8 @@ int zmq::ctx_t::register_endpoint (const char *addr_,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int zmq::ctx_t::unregister_endpoint (
|
||||
const std::string &addr_, socket_base_t *socket_)
|
||||
int zmq::ctx_t::unregister_endpoint (const std::string &addr_,
|
||||
socket_base_t *socket_)
|
||||
{
|
||||
scoped_lock_t locker (endpoints_sync);
|
||||
|
||||
@@ -567,36 +547,47 @@ zmq::endpoint_t zmq::ctx_t::find_endpoint (const char *addr_)
|
||||
}
|
||||
|
||||
void zmq::ctx_t::pend_connection (const std::string &addr_,
|
||||
const endpoint_t &endpoint_, pipe_t **pipes_)
|
||||
const endpoint_t &endpoint_,
|
||||
pipe_t **pipes_)
|
||||
{
|
||||
scoped_lock_t locker (endpoints_sync);
|
||||
|
||||
const pending_connection_t pending_connection = {endpoint_, pipes_ [0], pipes_ [1]};
|
||||
const pending_connection_t pending_connection = {endpoint_, pipes_[0],
|
||||
pipes_[1]};
|
||||
|
||||
endpoints_t::iterator it = endpoints.find (addr_);
|
||||
if (it == endpoints.end ()) {
|
||||
// Still no bind.
|
||||
endpoint_.socket->inc_seqnum ();
|
||||
pending_connections.ZMQ_MAP_INSERT_OR_EMPLACE (addr_, pending_connection);
|
||||
pending_connections.ZMQ_MAP_INSERT_OR_EMPLACE (addr_,
|
||||
pending_connection);
|
||||
} else {
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
void zmq::ctx_t::connect_pending (const char *addr_, zmq::socket_base_t *bind_socket_)
|
||||
void zmq::ctx_t::connect_pending (const char *addr_,
|
||||
zmq::socket_base_t *bind_socket_)
|
||||
{
|
||||
scoped_lock_t locker (endpoints_sync);
|
||||
|
||||
std::pair<pending_connections_t::iterator, pending_connections_t::iterator> pending = pending_connections.equal_range(addr_);
|
||||
for (pending_connections_t::iterator p = pending.first; p != pending.second; ++p)
|
||||
connect_inproc_sockets(bind_socket_, endpoints[addr_].options, p->second, bind_side);
|
||||
std::pair<pending_connections_t::iterator, pending_connections_t::iterator>
|
||||
pending = pending_connections.equal_range (addr_);
|
||||
for (pending_connections_t::iterator p = pending.first; p != pending.second;
|
||||
++p)
|
||||
connect_inproc_sockets (bind_socket_, endpoints[addr_].options,
|
||||
p->second, bind_side);
|
||||
|
||||
pending_connections.erase (pending.first, pending.second);
|
||||
}
|
||||
|
||||
void zmq::ctx_t::connect_inproc_sockets (zmq::socket_base_t *bind_socket_,
|
||||
options_t& bind_options, const pending_connection_t &pending_connection_, side side_)
|
||||
void zmq::ctx_t::connect_inproc_sockets (
|
||||
zmq::socket_base_t *bind_socket_,
|
||||
options_t &bind_options,
|
||||
const pending_connection_t &pending_connection_,
|
||||
side side_)
|
||||
{
|
||||
bind_socket_->inc_seqnum ();
|
||||
pending_connection_.bind_pipe->set_tid (bind_socket_->get_tid ());
|
||||
@@ -609,21 +600,27 @@ void zmq::ctx_t::connect_inproc_sockets (zmq::socket_base_t *bind_socket_,
|
||||
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);
|
||||
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) {
|
||||
pending_connection_.connect_pipe->set_hwms_boost(bind_options.sndhwm, bind_options.rcvhwm);
|
||||
pending_connection_.bind_pipe->set_hwms_boost(pending_connection_.endpoint.options.sndhwm, pending_connection_.endpoint.options.rcvhwm);
|
||||
pending_connection_.connect_pipe->set_hwms_boost (bind_options.sndhwm,
|
||||
bind_options.rcvhwm);
|
||||
pending_connection_.bind_pipe->set_hwms_boost (
|
||||
pending_connection_.endpoint.options.sndhwm,
|
||||
pending_connection_.endpoint.options.rcvhwm);
|
||||
|
||||
pending_connection_.connect_pipe->set_hwms(pending_connection_.endpoint.options.rcvhwm, pending_connection_.endpoint.options.sndhwm);
|
||||
pending_connection_.bind_pipe->set_hwms(bind_options.rcvhwm, bind_options.sndhwm);
|
||||
}
|
||||
else {
|
||||
pending_connection_.connect_pipe->set_hwms (
|
||||
pending_connection_.endpoint.options.rcvhwm,
|
||||
pending_connection_.endpoint.options.sndhwm);
|
||||
pending_connection_.bind_pipe->set_hwms (bind_options.rcvhwm,
|
||||
bind_options.sndhwm);
|
||||
} else {
|
||||
pending_connection_.connect_pipe->set_hwms (-1, -1);
|
||||
pending_connection_.bind_pipe->set_hwms (-1, -1);
|
||||
}
|
||||
@@ -633,22 +630,24 @@ void zmq::ctx_t::connect_inproc_sockets (zmq::socket_base_t *bind_socket_,
|
||||
cmd.type = command_t::bind;
|
||||
cmd.args.bind.pipe = pending_connection_.bind_pipe;
|
||||
bind_socket_->process_command (cmd);
|
||||
bind_socket_->send_inproc_connected (pending_connection_.endpoint.socket);
|
||||
}
|
||||
else
|
||||
pending_connection_.connect_pipe->send_bind (bind_socket_, pending_connection_.bind_pipe, false);
|
||||
bind_socket_->send_inproc_connected (
|
||||
pending_connection_.endpoint.socket);
|
||||
} else
|
||||
pending_connection_.connect_pipe->send_bind (
|
||||
bind_socket_, pending_connection_.bind_pipe, false);
|
||||
|
||||
// When a ctx is terminated all pending inproc connection will be
|
||||
// connected, but the socket will already be closed and the pipe will be
|
||||
// in waiting_for_delimiter state, which means no more writes can be done
|
||||
// and the routing id write fails and causes an assert. Check if the socket
|
||||
// is open before sending.
|
||||
if (pending_connection_.endpoint.options.recv_routing_id &&
|
||||
pending_connection_.endpoint.socket->check_tag ()) {
|
||||
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);
|
||||
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);
|
||||
|
24
src/ctx.hpp
24
src/ctx.hpp
@@ -46,7 +46,6 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
class object_t;
|
||||
class io_thread_t;
|
||||
class socket_base_t;
|
||||
@@ -68,7 +67,6 @@ namespace zmq
|
||||
class ctx_t
|
||||
{
|
||||
public:
|
||||
|
||||
// Create the context object.
|
||||
ctx_t ();
|
||||
|
||||
@@ -118,7 +116,8 @@ namespace zmq
|
||||
void unregister_endpoints (zmq::socket_base_t *socket_);
|
||||
endpoint_t find_endpoint (const char *addr_);
|
||||
void pend_connection (const std::string &addr_,
|
||||
const endpoint_t &endpoint_, pipe_t **pipes_);
|
||||
const endpoint_t &endpoint_,
|
||||
pipe_t **pipes_);
|
||||
void connect_pending (const char *addr_, zmq::socket_base_t *bind_socket_);
|
||||
|
||||
#ifdef ZMQ_HAVE_VMCI
|
||||
@@ -126,7 +125,8 @@ namespace zmq
|
||||
int get_vmci_socket_family ();
|
||||
#endif
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
term_tid = 0,
|
||||
reaper_tid = 1
|
||||
};
|
||||
@@ -190,7 +190,8 @@ namespace zmq
|
||||
endpoints_t endpoints;
|
||||
|
||||
// List of inproc connection endpoints pending a bind
|
||||
typedef std::multimap <std::string, pending_connection_t> pending_connections_t;
|
||||
typedef std::multimap<std::string, pending_connection_t>
|
||||
pending_connections_t;
|
||||
pending_connections_t pending_connections;
|
||||
|
||||
// Synchronisation of access to the list of inproc endpoints.
|
||||
@@ -230,8 +231,16 @@ namespace zmq
|
||||
// the process that created this context. Used to detect forking.
|
||||
pid_t pid;
|
||||
#endif
|
||||
enum side { connect_side, bind_side };
|
||||
void connect_inproc_sockets(zmq::socket_base_t *bind_socket_, options_t& bind_options, const pending_connection_t &pending_connection_, side side_);
|
||||
enum side
|
||||
{
|
||||
connect_side,
|
||||
bind_side
|
||||
};
|
||||
void
|
||||
connect_inproc_sockets (zmq::socket_base_t *bind_socket_,
|
||||
options_t &bind_options,
|
||||
const pending_connection_t &pending_connection_,
|
||||
side side_);
|
||||
|
||||
#ifdef ZMQ_HAVE_VMCI
|
||||
int vmci_fd;
|
||||
@@ -239,7 +248,6 @@ namespace zmq
|
||||
mutex_t vmci_sync;
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -94,8 +94,7 @@ int zmq::curve_client_t::process_handshake_command (msg_t *msg_)
|
||||
rc = process_error (msg_data, msg_size);
|
||||
else {
|
||||
session->get_socket ()->event_handshake_failed_protocol (
|
||||
session->get_endpoint (),
|
||||
ZMQ_PROTOCOL_ERROR_ZMTP_UNEXPECTED_COMMAND);
|
||||
session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_UNEXPECTED_COMMAND);
|
||||
errno = EPROTO;
|
||||
rc = -1;
|
||||
}
|
||||
@@ -126,8 +125,7 @@ zmq::mechanism_t::status_t zmq::curve_client_t::status () const
|
||||
{
|
||||
if (state == connected)
|
||||
return mechanism_t::ready;
|
||||
else
|
||||
if (state == error_received)
|
||||
else if (state == error_received)
|
||||
return mechanism_t::error;
|
||||
else
|
||||
return mechanism_t::handshaking;
|
||||
@@ -141,8 +139,7 @@ int zmq::curve_client_t::produce_hello (msg_t *msg_)
|
||||
rc = tools.produce_hello (msg_->data (), cn_nonce);
|
||||
if (rc == -1) {
|
||||
session->get_socket ()->event_handshake_failed_protocol (
|
||||
session->get_endpoint (),
|
||||
ZMQ_PROTOCOL_ERROR_ZMTP_CRYPTOGRAPHIC);
|
||||
session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_CRYPTOGRAPHIC);
|
||||
|
||||
// TODO this is somewhat inconsistent: we call init_size, but we may
|
||||
// not close msg_; i.e. we assume that msg_ is initialized but empty
|
||||
@@ -164,8 +161,7 @@ int zmq::curve_client_t::process_welcome (const uint8_t *msg_data,
|
||||
|
||||
if (rc == -1) {
|
||||
session->get_socket ()->event_handshake_failed_protocol (
|
||||
session->get_endpoint (),
|
||||
ZMQ_PROTOCOL_ERROR_ZMTP_CRYPTOGRAPHIC);
|
||||
session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_CRYPTOGRAPHIC);
|
||||
|
||||
errno = EPROTO;
|
||||
return -1;
|
||||
@@ -196,8 +192,7 @@ int zmq::curve_client_t::produce_initiate (msg_t *msg_)
|
||||
|
||||
if (-1 == rc) {
|
||||
session->get_socket ()->event_handshake_failed_protocol (
|
||||
session->get_endpoint (),
|
||||
ZMQ_PROTOCOL_ERROR_ZMTP_CRYPTOGRAPHIC);
|
||||
session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_CRYPTOGRAPHIC);
|
||||
|
||||
// TODO see comment in produce_hello
|
||||
return -1;
|
||||
@@ -208,8 +203,8 @@ int zmq::curve_client_t::produce_initiate (msg_t *msg_)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int zmq::curve_client_t::process_ready (
|
||||
const uint8_t *msg_data, size_t msg_size)
|
||||
int zmq::curve_client_t::process_ready (const uint8_t *msg_data,
|
||||
size_t msg_size)
|
||||
{
|
||||
if (msg_size < 30) {
|
||||
session->get_socket ()->event_handshake_failed_protocol (
|
||||
@@ -229,21 +224,20 @@ int zmq::curve_client_t::process_ready (
|
||||
alloc_assert (ready_box);
|
||||
|
||||
memset (ready_box, 0, crypto_box_BOXZEROBYTES);
|
||||
memcpy (ready_box + crypto_box_BOXZEROBYTES,
|
||||
msg_data + 14, clen - crypto_box_BOXZEROBYTES);
|
||||
memcpy (ready_box + crypto_box_BOXZEROBYTES, msg_data + 14,
|
||||
clen - crypto_box_BOXZEROBYTES);
|
||||
|
||||
memcpy (ready_nonce, "CurveZMQREADY---", 16);
|
||||
memcpy (ready_nonce + 16, msg_data + 6, 8);
|
||||
cn_peer_nonce = get_uint64 (msg_data + 6);
|
||||
|
||||
int rc = crypto_box_open_afternm (ready_plaintext, ready_box,
|
||||
clen, ready_nonce, cn_precom);
|
||||
int rc = crypto_box_open_afternm (ready_plaintext, ready_box, clen,
|
||||
ready_nonce, cn_precom);
|
||||
free (ready_box);
|
||||
|
||||
if (rc != 0) {
|
||||
session->get_socket ()->event_handshake_failed_protocol (
|
||||
session->get_endpoint (),
|
||||
ZMQ_PROTOCOL_ERROR_ZMTP_CRYPTOGRAPHIC);
|
||||
session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_CRYPTOGRAPHIC);
|
||||
errno = EPROTO;
|
||||
return -1;
|
||||
}
|
||||
@@ -254,8 +248,7 @@ int zmq::curve_client_t::process_ready (
|
||||
|
||||
if (rc == 0)
|
||||
state = connected;
|
||||
else
|
||||
{
|
||||
else {
|
||||
session->get_socket ()->event_handshake_failed_protocol (
|
||||
session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_INVALID_METADATA);
|
||||
errno = EPROTO;
|
||||
@@ -264,8 +257,8 @@ int zmq::curve_client_t::process_ready (
|
||||
return rc;
|
||||
}
|
||||
|
||||
int zmq::curve_client_t::process_error (
|
||||
const uint8_t *msg_data, size_t msg_size)
|
||||
int zmq::curve_client_t::process_error (const uint8_t *msg_data,
|
||||
size_t msg_size)
|
||||
{
|
||||
if (state != expect_welcome && state != expect_ready) {
|
||||
session->get_socket ()->event_handshake_failed_protocol (
|
||||
|
@@ -38,14 +38,12 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
class msg_t;
|
||||
class session_base_t;
|
||||
|
||||
class curve_client_t : public curve_mechanism_base_t
|
||||
{
|
||||
public:
|
||||
|
||||
curve_client_t (session_base_t *session_, const options_t &options_);
|
||||
virtual ~curve_client_t ();
|
||||
|
||||
@@ -57,8 +55,8 @@ namespace zmq
|
||||
virtual status_t status () const;
|
||||
|
||||
private:
|
||||
|
||||
enum state_t {
|
||||
enum state_t
|
||||
{
|
||||
send_hello,
|
||||
expect_welcome,
|
||||
send_initiate,
|
||||
@@ -79,7 +77,6 @@ namespace zmq
|
||||
int process_ready (const uint8_t *cmd_data, size_t data_size);
|
||||
int process_error (const uint8_t *cmd_data, size_t data_size);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -153,8 +153,7 @@ struct curve_client_tools_t
|
||||
// Create vouch = Box [C',S](C->S')
|
||||
memset (vouch_plaintext, 0, crypto_box_ZEROBYTES);
|
||||
memcpy (vouch_plaintext + crypto_box_ZEROBYTES, cn_public, 32);
|
||||
memcpy (vouch_plaintext + crypto_box_ZEROBYTES + 32, server_key,
|
||||
32);
|
||||
memcpy (vouch_plaintext + crypto_box_ZEROBYTES + 32, server_key, 32);
|
||||
|
||||
memcpy (vouch_nonce, "VOUCH---", 8);
|
||||
randombytes (vouch_nonce + 8, 16);
|
||||
@@ -165,8 +164,8 @@ struct curve_client_tools_t
|
||||
return -1;
|
||||
|
||||
uint8_t initiate_nonce[crypto_box_NONCEBYTES];
|
||||
uint8_t *initiate_box = (uint8_t *) malloc (
|
||||
crypto_box_BOXZEROBYTES + 144 + metadata_length);
|
||||
uint8_t *initiate_box =
|
||||
(uint8_t *) malloc (crypto_box_BOXZEROBYTES + 144 + metadata_length);
|
||||
alloc_assert (initiate_box);
|
||||
uint8_t *initiate_plaintext =
|
||||
(uint8_t *) malloc (crypto_box_ZEROBYTES + 128 + metadata_length);
|
||||
@@ -174,8 +173,7 @@ struct curve_client_tools_t
|
||||
|
||||
// Create Box [C + vouch + metadata](C'->S')
|
||||
memset (initiate_plaintext, 0, crypto_box_ZEROBYTES);
|
||||
memcpy (initiate_plaintext + crypto_box_ZEROBYTES, public_key,
|
||||
32);
|
||||
memcpy (initiate_plaintext + crypto_box_ZEROBYTES, public_key, 32);
|
||||
memcpy (initiate_plaintext + crypto_box_ZEROBYTES + 32, vouch_nonce + 8,
|
||||
16);
|
||||
memcpy (initiate_plaintext + crypto_box_ZEROBYTES + 48,
|
||||
|
@@ -68,14 +68,14 @@ int zmq::curve_mechanism_base_t::encode (msg_t *msg_)
|
||||
|
||||
memset (message_plaintext, 0, crypto_box_ZEROBYTES);
|
||||
message_plaintext[crypto_box_ZEROBYTES] = flags;
|
||||
memcpy (message_plaintext + crypto_box_ZEROBYTES + 1,
|
||||
msg_->data (), msg_->size ());
|
||||
memcpy (message_plaintext + crypto_box_ZEROBYTES + 1, msg_->data (),
|
||||
msg_->size ());
|
||||
|
||||
uint8_t *message_box = static_cast<uint8_t *> (malloc (mlen));
|
||||
alloc_assert (message_box);
|
||||
|
||||
int rc = crypto_box_afternm (message_box, message_plaintext,
|
||||
mlen, message_nonce, cn_precom);
|
||||
int rc = crypto_box_afternm (message_box, message_plaintext, mlen,
|
||||
message_nonce, cn_precom);
|
||||
zmq_assert (rc == 0);
|
||||
|
||||
rc = msg_->close ();
|
||||
@@ -144,8 +144,8 @@ int zmq::curve_mechanism_base_t::decode (msg_t *msg_)
|
||||
alloc_assert (message_box);
|
||||
|
||||
memset (message_box, 0, crypto_box_BOXZEROBYTES);
|
||||
memcpy (message_box + crypto_box_BOXZEROBYTES,
|
||||
message + 16, msg_->size () - 16);
|
||||
memcpy (message_box + crypto_box_BOXZEROBYTES, message + 16,
|
||||
msg_->size () - 16);
|
||||
|
||||
rc = crypto_box_open_afternm (message_plaintext, message_box, clen,
|
||||
message_nonce, cn_precom);
|
||||
@@ -162,11 +162,9 @@ int zmq::curve_mechanism_base_t::decode (msg_t *msg_)
|
||||
if (flags & 0x02)
|
||||
msg_->set_flags (msg_t::command);
|
||||
|
||||
memcpy (msg_->data (),
|
||||
message_plaintext + crypto_box_ZEROBYTES + 1,
|
||||
memcpy (msg_->data (), message_plaintext + crypto_box_ZEROBYTES + 1,
|
||||
msg_->size ());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// CURVE I : connection key used for MESSAGE is wrong
|
||||
session->get_socket ()->event_handshake_failed_protocol (
|
||||
session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_CRYPTOGRAPHIC);
|
||||
|
@@ -152,7 +152,8 @@ int zmq::curve_server_t::process_hello (msg_t *msg_)
|
||||
|
||||
if (size != 200) {
|
||||
session->get_socket ()->event_handshake_failed_protocol (
|
||||
session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_HELLO);
|
||||
session->get_endpoint (),
|
||||
ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_HELLO);
|
||||
errno = EPROTO;
|
||||
return -1;
|
||||
}
|
||||
@@ -163,7 +164,8 @@ int zmq::curve_server_t::process_hello (msg_t *msg_)
|
||||
if (major != 1 || minor != 0) {
|
||||
// CURVE I: client HELLO has unknown version number
|
||||
session->get_socket ()->event_handshake_failed_protocol (
|
||||
session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_HELLO);
|
||||
session->get_endpoint (),
|
||||
ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_HELLO);
|
||||
errno = EPROTO;
|
||||
return -1;
|
||||
}
|
||||
@@ -210,18 +212,16 @@ int zmq::curve_server_t::produce_welcome (msg_t *msg_)
|
||||
|
||||
// Generate cookie = Box [C' + s'](t)
|
||||
memset (cookie_plaintext, 0, crypto_secretbox_ZEROBYTES);
|
||||
memcpy (cookie_plaintext + crypto_secretbox_ZEROBYTES,
|
||||
cn_client, 32);
|
||||
memcpy (cookie_plaintext + crypto_secretbox_ZEROBYTES + 32,
|
||||
cn_secret, 32);
|
||||
memcpy (cookie_plaintext + crypto_secretbox_ZEROBYTES, cn_client, 32);
|
||||
memcpy (cookie_plaintext + crypto_secretbox_ZEROBYTES + 32, cn_secret, 32);
|
||||
|
||||
// Generate fresh cookie key
|
||||
randombytes (cookie_key, crypto_secretbox_KEYBYTES);
|
||||
|
||||
// Encrypt using symmetric cookie key
|
||||
int rc = crypto_secretbox (cookie_ciphertext, cookie_plaintext,
|
||||
sizeof cookie_plaintext,
|
||||
cookie_nonce, cookie_key);
|
||||
int rc =
|
||||
crypto_secretbox (cookie_ciphertext, cookie_plaintext,
|
||||
sizeof cookie_plaintext, cookie_nonce, cookie_key);
|
||||
zmq_assert (rc == 0);
|
||||
|
||||
uint8_t welcome_nonce[crypto_box_NONCEBYTES];
|
||||
@@ -236,8 +236,8 @@ int zmq::curve_server_t::produce_welcome (msg_t *msg_)
|
||||
// Create 144-byte Box [S' + cookie](S->C')
|
||||
memset (welcome_plaintext, 0, crypto_box_ZEROBYTES);
|
||||
memcpy (welcome_plaintext + crypto_box_ZEROBYTES, cn_public, 32);
|
||||
memcpy (welcome_plaintext + crypto_box_ZEROBYTES + 32,
|
||||
cookie_nonce + 8, 16);
|
||||
memcpy (welcome_plaintext + crypto_box_ZEROBYTES + 32, cookie_nonce + 8,
|
||||
16);
|
||||
memcpy (welcome_plaintext + crypto_box_ZEROBYTES + 48,
|
||||
cookie_ciphertext + crypto_secretbox_BOXZEROBYTES, 80);
|
||||
|
||||
@@ -312,7 +312,8 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_)
|
||||
|
||||
// Check cookie plain text is as expected [C' + s']
|
||||
if (memcmp (cookie_plaintext + crypto_secretbox_ZEROBYTES, cn_client, 32)
|
||||
|| memcmp (cookie_plaintext + crypto_secretbox_ZEROBYTES + 32, cn_secret, 32)) {
|
||||
|| memcmp (cookie_plaintext + crypto_secretbox_ZEROBYTES + 32,
|
||||
cn_secret, 32)) {
|
||||
// TODO this case is very hard to test, as it would require a modified
|
||||
// client that knows the server's secret temporary cookie key
|
||||
|
||||
@@ -331,15 +332,15 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_)
|
||||
|
||||
// Open Box [C + vouch + metadata](C'->S')
|
||||
memset (initiate_box, 0, crypto_box_BOXZEROBYTES);
|
||||
memcpy (initiate_box + crypto_box_BOXZEROBYTES,
|
||||
initiate + 113, clen - crypto_box_BOXZEROBYTES);
|
||||
memcpy (initiate_box + crypto_box_BOXZEROBYTES, initiate + 113,
|
||||
clen - crypto_box_BOXZEROBYTES);
|
||||
|
||||
memcpy (initiate_nonce, "CurveZMQINITIATE", 16);
|
||||
memcpy (initiate_nonce + 16, initiate + 105, 8);
|
||||
cn_peer_nonce = get_uint64 (initiate + 105);
|
||||
|
||||
rc = crypto_box_open (initiate_plaintext, initiate_box,
|
||||
clen, initiate_nonce, cn_client, cn_secret);
|
||||
rc = crypto_box_open (initiate_plaintext, initiate_box, clen,
|
||||
initiate_nonce, cn_client, cn_secret);
|
||||
if (rc != 0) {
|
||||
// CURVE I: cannot open client INITIATE
|
||||
session->get_socket ()->event_handshake_failed_protocol (
|
||||
@@ -360,11 +361,10 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_)
|
||||
initiate_plaintext + crypto_box_ZEROBYTES + 48, 80);
|
||||
|
||||
memcpy (vouch_nonce, "VOUCH---", 8);
|
||||
memcpy (vouch_nonce + 8,
|
||||
initiate_plaintext + crypto_box_ZEROBYTES + 32, 16);
|
||||
memcpy (vouch_nonce + 8, initiate_plaintext + crypto_box_ZEROBYTES + 32,
|
||||
16);
|
||||
|
||||
rc = crypto_box_open (vouch_plaintext, vouch_box,
|
||||
sizeof vouch_box,
|
||||
rc = crypto_box_open (vouch_plaintext, vouch_box, sizeof vouch_box,
|
||||
vouch_nonce, client_key, cn_secret);
|
||||
if (rc != 0) {
|
||||
// CURVE I: cannot open client INITIATE vouch
|
||||
|
@@ -46,7 +46,6 @@ namespace zmq
|
||||
public curve_mechanism_base_t
|
||||
{
|
||||
public:
|
||||
|
||||
curve_server_t (session_base_t *session_,
|
||||
const std::string &peer_address_,
|
||||
const options_t &options_);
|
||||
@@ -59,7 +58,6 @@ namespace zmq
|
||||
virtual int decode (msg_t *msg_);
|
||||
|
||||
private:
|
||||
|
||||
// Our secret key (s)
|
||||
uint8_t secret_key[crypto_box_SECRETKEYBYTES];
|
||||
|
||||
@@ -86,7 +84,6 @@ namespace zmq
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -39,7 +39,6 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
// dbuffer is a single-producer single-consumer double-buffer
|
||||
// implementation.
|
||||
//
|
||||
@@ -59,11 +58,10 @@ namespace zmq
|
||||
template <> class dbuffer_t<msg_t>
|
||||
{
|
||||
public:
|
||||
|
||||
inline dbuffer_t ()
|
||||
: back (&storage[0])
|
||||
, front (&storage[1])
|
||||
, has_msg (false)
|
||||
inline dbuffer_t () :
|
||||
back (&storage[0]),
|
||||
front (&storage[1]),
|
||||
has_msg (false)
|
||||
{
|
||||
back->init ();
|
||||
front->init ();
|
||||
@@ -84,8 +82,7 @@ namespace zmq
|
||||
|
||||
zmq_assert (back->check ());
|
||||
|
||||
if (sync.try_lock ())
|
||||
{
|
||||
if (sync.try_lock ()) {
|
||||
std::swap (back, front);
|
||||
has_msg = true;
|
||||
|
||||
|
@@ -67,12 +67,14 @@ void zmq::dealer_t::xattach_pipe (pipe_t *pipe_, bool subscribe_to_all_)
|
||||
lb.attach (pipe_);
|
||||
}
|
||||
|
||||
int zmq::dealer_t::xsetsockopt (int option_, const void *optval_,
|
||||
int zmq::dealer_t::xsetsockopt (int option_,
|
||||
const void *optval_,
|
||||
size_t optvallen_)
|
||||
{
|
||||
bool is_int = (optvallen_ == sizeof (int));
|
||||
int value = 0;
|
||||
if (is_int) memcpy(&value, optval_, sizeof (int));
|
||||
if (is_int)
|
||||
memcpy (&value, optval_, sizeof (int));
|
||||
|
||||
switch (option_) {
|
||||
case ZMQ_PROBE_ROUTER:
|
||||
|
@@ -37,23 +37,19 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
class ctx_t;
|
||||
class msg_t;
|
||||
class pipe_t;
|
||||
class io_thread_t;
|
||||
class socket_base_t;
|
||||
|
||||
class dealer_t :
|
||||
public socket_base_t
|
||||
class dealer_t : public socket_base_t
|
||||
{
|
||||
public:
|
||||
|
||||
dealer_t (zmq::ctx_t *parent_, uint32_t tid_, int sid);
|
||||
~dealer_t ();
|
||||
|
||||
protected:
|
||||
|
||||
// Overrides of functions from socket_base_t.
|
||||
void xattach_pipe (zmq::pipe_t *pipe_, bool subscribe_to_all_);
|
||||
int xsetsockopt (int option_, const void *optval_, size_t optvallen_);
|
||||
@@ -71,7 +67,6 @@ namespace zmq
|
||||
int recvpipe (zmq::msg_t *msg_, zmq::pipe_t **pipe_);
|
||||
|
||||
private:
|
||||
|
||||
// Messages are fair-queued from inbound pipes. And load-balanced to
|
||||
// the outbound pipes.
|
||||
fq_t fq;
|
||||
@@ -83,7 +78,6 @@ namespace zmq
|
||||
dealer_t (const dealer_t &);
|
||||
const dealer_t &operator= (const dealer_t &);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -58,7 +58,6 @@ namespace zmq
|
||||
class decoder_base_t : public i_decoder
|
||||
{
|
||||
public:
|
||||
|
||||
explicit decoder_base_t (A *allocator_) :
|
||||
next (NULL),
|
||||
read_pos (NULL),
|
||||
@@ -70,10 +69,7 @@ namespace zmq
|
||||
|
||||
// The destructor doesn't have to be virtual. It is made virtual
|
||||
// just to keep ICC and code checking tools from complaining.
|
||||
virtual ~decoder_base_t ()
|
||||
{
|
||||
allocator->deallocate ();
|
||||
}
|
||||
virtual ~decoder_base_t () { allocator->deallocate (); }
|
||||
|
||||
// Returns a buffer to be filled with binary data.
|
||||
void get_buffer (unsigned char **data_, std::size_t *size_)
|
||||
@@ -104,7 +100,8 @@ namespace zmq
|
||||
// whole message was decoded or 0 when more data is required.
|
||||
// On error, -1 is returned and errno set accordingly.
|
||||
// Number of bytes processed is returned in bytes_used_.
|
||||
int decode (const unsigned char *data_, std::size_t size_,
|
||||
int decode (const unsigned char *data_,
|
||||
std::size_t size_,
|
||||
std::size_t &bytes_used_)
|
||||
{
|
||||
bytes_used_ = 0;
|
||||
@@ -159,7 +156,6 @@ namespace zmq
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
// Prototype of state machine action. Action should return false if
|
||||
// it is unable to push the data to the system.
|
||||
typedef int (T::*step_t) (unsigned char const *);
|
||||
@@ -174,7 +170,6 @@ namespace zmq
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// Next step. If set to NULL, it means that associated data stream
|
||||
// is dead. Note that there can be still data in the process in such
|
||||
// case.
|
||||
|
@@ -34,16 +34,20 @@
|
||||
|
||||
#include "msg.hpp"
|
||||
|
||||
zmq::shared_message_memory_allocator::shared_message_memory_allocator (std::size_t bufsize_) :
|
||||
zmq::shared_message_memory_allocator::shared_message_memory_allocator (
|
||||
std::size_t bufsize_) :
|
||||
buf (NULL),
|
||||
bufsize (0),
|
||||
max_size (bufsize_),
|
||||
msg_content (NULL),
|
||||
maxCounters (static_cast <size_t> (std::ceil (static_cast <double> (max_size) / static_cast <double> (msg_t::max_vsm_size))))
|
||||
maxCounters (static_cast<size_t> (
|
||||
std::ceil (static_cast<double> (max_size)
|
||||
/ static_cast<double> (msg_t::max_vsm_size))))
|
||||
{
|
||||
}
|
||||
|
||||
zmq::shared_message_memory_allocator::shared_message_memory_allocator (std::size_t bufsize_, std::size_t maxMessages) :
|
||||
zmq::shared_message_memory_allocator::shared_message_memory_allocator (
|
||||
std::size_t bufsize_, std::size_t maxMessages) :
|
||||
buf (NULL),
|
||||
bufsize (0),
|
||||
max_size (bufsize_),
|
||||
@@ -61,7 +65,8 @@ unsigned char* zmq::shared_message_memory_allocator::allocate ()
|
||||
{
|
||||
if (buf) {
|
||||
// release reference count to couple lifetime to messages
|
||||
zmq::atomic_counter_t* c = reinterpret_cast<zmq::atomic_counter_t* >(buf);
|
||||
zmq::atomic_counter_t *c =
|
||||
reinterpret_cast<zmq::atomic_counter_t *> (buf);
|
||||
|
||||
// if refcnt drops to 0, there are no message using the buffer
|
||||
// because either all messages have been closed or only vsm-messages
|
||||
@@ -77,8 +82,8 @@ unsigned char* zmq::shared_message_memory_allocator::allocate ()
|
||||
if (!buf) {
|
||||
// allocate memory for reference counters together with reception buffer
|
||||
std::size_t const allocationsize =
|
||||
max_size + sizeof (zmq::atomic_counter_t) +
|
||||
maxCounters * sizeof (zmq::msg_t::content_t);
|
||||
max_size + sizeof (zmq::atomic_counter_t)
|
||||
+ maxCounters * sizeof (zmq::msg_t::content_t);
|
||||
|
||||
buf = static_cast<unsigned char *> (std::malloc (allocationsize));
|
||||
alloc_assert (buf);
|
||||
@@ -86,12 +91,14 @@ unsigned char* zmq::shared_message_memory_allocator::allocate ()
|
||||
new (buf) atomic_counter_t (1);
|
||||
} else {
|
||||
// release reference count to couple lifetime to messages
|
||||
zmq::atomic_counter_t *c = reinterpret_cast <zmq::atomic_counter_t *> (buf);
|
||||
zmq::atomic_counter_t *c =
|
||||
reinterpret_cast<zmq::atomic_counter_t *> (buf);
|
||||
c->set (1);
|
||||
}
|
||||
|
||||
bufsize = max_size;
|
||||
msg_content = reinterpret_cast <zmq::msg_t::content_t*> (buf + sizeof (atomic_counter_t) + max_size);
|
||||
msg_content = reinterpret_cast<zmq::msg_t::content_t *> (
|
||||
buf + sizeof (atomic_counter_t) + max_size);
|
||||
return buf + sizeof (zmq::atomic_counter_t);
|
||||
}
|
||||
|
||||
|
@@ -50,29 +50,16 @@ namespace zmq
|
||||
alloc_assert (buf);
|
||||
}
|
||||
|
||||
~c_single_allocator ()
|
||||
{
|
||||
std::free (buf);
|
||||
}
|
||||
~c_single_allocator () { std::free (buf); }
|
||||
|
||||
unsigned char* allocate ()
|
||||
{
|
||||
return buf;
|
||||
}
|
||||
unsigned char *allocate () { return buf; }
|
||||
|
||||
void deallocate ()
|
||||
{
|
||||
}
|
||||
void deallocate () {}
|
||||
|
||||
std::size_t size () const
|
||||
{
|
||||
return bufsize;
|
||||
}
|
||||
std::size_t size () const { return bufsize; }
|
||||
|
||||
void resize (std::size_t new_size) { bufsize = new_size; }
|
||||
|
||||
void resize (std::size_t new_size)
|
||||
{
|
||||
bufsize = new_size;
|
||||
}
|
||||
private:
|
||||
std::size_t bufsize;
|
||||
unsigned char *buf;
|
||||
@@ -96,7 +83,8 @@ namespace zmq
|
||||
explicit shared_message_memory_allocator (std::size_t bufsize_);
|
||||
|
||||
// Create an allocator for a maximum number of messages
|
||||
shared_message_memory_allocator (std::size_t bufsize_, std::size_t maxMessages);
|
||||
shared_message_memory_allocator (std::size_t bufsize_,
|
||||
std::size_t maxMessages);
|
||||
|
||||
~shared_message_memory_allocator ();
|
||||
|
||||
@@ -123,25 +111,13 @@ namespace zmq
|
||||
unsigned char *data ();
|
||||
|
||||
// Return pointer to the first byte of the buffer.
|
||||
unsigned char* buffer ()
|
||||
{
|
||||
return buf;
|
||||
}
|
||||
unsigned char *buffer () { return buf; }
|
||||
|
||||
void resize (std::size_t new_size)
|
||||
{
|
||||
bufsize = new_size;
|
||||
}
|
||||
void resize (std::size_t new_size) { bufsize = new_size; }
|
||||
|
||||
zmq::msg_t::content_t* provide_content ()
|
||||
{
|
||||
return msg_content;
|
||||
}
|
||||
zmq::msg_t::content_t *provide_content () { return msg_content; }
|
||||
|
||||
void advance_content ()
|
||||
{
|
||||
msg_content++;
|
||||
}
|
||||
void advance_content () { msg_content++; }
|
||||
|
||||
private:
|
||||
unsigned char *buf;
|
||||
|
@@ -153,7 +153,6 @@ int zmq::devpoll_t::max_fds ()
|
||||
void zmq::devpoll_t::loop ()
|
||||
{
|
||||
while (!stopping) {
|
||||
|
||||
struct pollfd ev_buf[max_io_events];
|
||||
struct dvpoll poll_req;
|
||||
|
||||
@@ -179,7 +178,6 @@ void zmq::devpoll_t::loop ()
|
||||
errno_assert (n != -1);
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
|
||||
fd_entry_t *fd_ptr = &fd_table[ev_buf[i].fd];
|
||||
if (!fd_ptr->valid || !fd_ptr->accepted)
|
||||
continue;
|
||||
|
@@ -43,7 +43,6 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
struct i_poll_events;
|
||||
|
||||
// Implements socket polling mechanism using the "/dev/poll" interface.
|
||||
@@ -51,7 +50,6 @@ namespace zmq
|
||||
class devpoll_t : public poller_base_t
|
||||
{
|
||||
public:
|
||||
|
||||
typedef fd_t handle_t;
|
||||
|
||||
devpoll_t (const ctx_t &ctx_);
|
||||
@@ -70,7 +68,6 @@ namespace zmq
|
||||
static int max_fds ();
|
||||
|
||||
private:
|
||||
|
||||
// Main worker thread routine.
|
||||
static void worker_routine (void *arg_);
|
||||
|
||||
@@ -111,7 +108,6 @@ namespace zmq
|
||||
};
|
||||
|
||||
typedef devpoll_t poller_t;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -107,9 +107,7 @@ int zmq::dgram_t::xsend (msg_t *msg_)
|
||||
|
||||
// Expect one more message frame.
|
||||
more_out = true;
|
||||
}
|
||||
else {
|
||||
|
||||
} else {
|
||||
// dgram messages are two part only, reject part if more is set
|
||||
if (msg_->flags () & msg_t::more) {
|
||||
errno = EINVAL;
|
||||
|
@@ -36,17 +36,14 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
class ctx_t;
|
||||
class msg_t;
|
||||
class pipe_t;
|
||||
class io_thread_t;
|
||||
|
||||
class dgram_t :
|
||||
public socket_base_t
|
||||
class dgram_t : public socket_base_t
|
||||
{
|
||||
public:
|
||||
|
||||
dgram_t (zmq::ctx_t *parent_, uint32_t tid_, int sid);
|
||||
~dgram_t ();
|
||||
|
||||
@@ -62,7 +59,6 @@ namespace zmq
|
||||
void xpipe_terminated (zmq::pipe_t *pipe_);
|
||||
|
||||
private:
|
||||
|
||||
zmq::pipe_t *pipe;
|
||||
|
||||
zmq::pipe_t *last_in;
|
||||
@@ -75,7 +71,6 @@ namespace zmq
|
||||
dgram_t (const dgram_t &);
|
||||
const dgram_t &operator= (const dgram_t &);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
25
src/dish.cpp
25
src/dish.cpp
@@ -134,7 +134,8 @@ int zmq::dish_t::xleave (const char* group_)
|
||||
return -1;
|
||||
}
|
||||
|
||||
subscriptions_t::iterator it = std::find (subscriptions.begin (), subscriptions.end (), group);
|
||||
subscriptions_t::iterator it =
|
||||
std::find (subscriptions.begin (), subscriptions.end (), group);
|
||||
|
||||
if (it == subscriptions.end ()) {
|
||||
errno = EINVAL;
|
||||
@@ -186,7 +187,6 @@ int zmq::dish_t::xrecv (msg_t *msg_)
|
||||
}
|
||||
|
||||
while (true) {
|
||||
|
||||
// Get a message using fair queueing algorithm.
|
||||
int rc = fq.recv (msg_);
|
||||
|
||||
@@ -196,7 +196,8 @@ int zmq::dish_t::xrecv (msg_t *msg_)
|
||||
return -1;
|
||||
|
||||
// Filtering non matching messages
|
||||
subscriptions_t::iterator it = subscriptions.find (std::string(msg_->group ()));
|
||||
subscriptions_t::iterator it =
|
||||
subscriptions.find (std::string (msg_->group ()));
|
||||
if (it != subscriptions.end ())
|
||||
return 0;
|
||||
}
|
||||
@@ -221,7 +222,8 @@ bool zmq::dish_t::xhas_in ()
|
||||
}
|
||||
|
||||
// Filtering non matching messages
|
||||
subscriptions_t::iterator it = subscriptions.find (std::string(message.group ()));
|
||||
subscriptions_t::iterator it =
|
||||
subscriptions.find (std::string (message.group ()));
|
||||
if (it != subscriptions.end ()) {
|
||||
has_message = true;
|
||||
return true;
|
||||
@@ -236,7 +238,8 @@ const zmq::blob_t &zmq::dish_t::get_credential () const
|
||||
|
||||
void zmq::dish_t::send_subscriptions (pipe_t *pipe_)
|
||||
{
|
||||
for (subscriptions_t::iterator it = subscriptions.begin (); it != subscriptions.end (); ++it) {
|
||||
for (subscriptions_t::iterator it = subscriptions.begin ();
|
||||
it != subscriptions.end (); ++it) {
|
||||
msg_t msg;
|
||||
int rc = msg.init_join ();
|
||||
errno_assert (rc == 0);
|
||||
@@ -252,8 +255,10 @@ void zmq::dish_t::send_subscriptions (pipe_t *pipe_)
|
||||
pipe_->flush ();
|
||||
}
|
||||
|
||||
zmq::dish_session_t::dish_session_t (io_thread_t *io_thread_, bool connect_,
|
||||
socket_base_t *socket_, const options_t &options_,
|
||||
zmq::dish_session_t::dish_session_t (io_thread_t *io_thread_,
|
||||
bool connect_,
|
||||
socket_base_t *socket_,
|
||||
const options_t &options_,
|
||||
address_t *addr_) :
|
||||
session_base_t (io_thread_, connect_, socket_, options_, addr_),
|
||||
state (group)
|
||||
@@ -283,8 +288,7 @@ int zmq::dish_session_t::push_msg (msg_t *msg_)
|
||||
int rc = msg_->init ();
|
||||
errno_assert (rc == 0);
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
const char *group_setting = msg_->group ();
|
||||
int rc;
|
||||
if (group_setting[0] != 0)
|
||||
@@ -334,8 +338,7 @@ int zmq::dish_session_t::pull_msg (msg_t *msg_)
|
||||
errno_assert (rc == 0);
|
||||
offset = 5;
|
||||
memcpy (command.data (), "\4JOIN", 5);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
rc = command.init_size (group_length + 6);
|
||||
errno_assert (rc == 0);
|
||||
offset = 6;
|
||||
|
20
src/dish.hpp
20
src/dish.hpp
@@ -41,21 +41,17 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
class ctx_t;
|
||||
class pipe_t;
|
||||
class io_thread_t;
|
||||
|
||||
class dish_t :
|
||||
public socket_base_t
|
||||
class dish_t : public socket_base_t
|
||||
{
|
||||
public:
|
||||
|
||||
dish_t (zmq::ctx_t *parent_, uint32_t tid_, int sid_);
|
||||
~dish_t ();
|
||||
|
||||
protected:
|
||||
|
||||
// Overrides of functions from socket_base_t.
|
||||
void xattach_pipe (zmq::pipe_t *pipe_, bool subscribe_to_all_);
|
||||
int xsend (zmq::msg_t *msg_);
|
||||
@@ -69,8 +65,8 @@ namespace zmq
|
||||
void xpipe_terminated (zmq::pipe_t *pipe_);
|
||||
int xjoin (const char *group_);
|
||||
int xleave (const char *group_);
|
||||
private:
|
||||
|
||||
private:
|
||||
// Send subscriptions to a pipe
|
||||
void send_subscriptions (pipe_t *pipe_);
|
||||
|
||||
@@ -96,9 +92,10 @@ namespace zmq
|
||||
class dish_session_t : public session_base_t
|
||||
{
|
||||
public:
|
||||
|
||||
dish_session_t (zmq::io_thread_t *io_thread_, bool connect_,
|
||||
zmq::socket_base_t *socket_, const options_t &options_,
|
||||
dish_session_t (zmq::io_thread_t *io_thread_,
|
||||
bool connect_,
|
||||
zmq::socket_base_t *socket_,
|
||||
const options_t &options_,
|
||||
address_t *addr_);
|
||||
~dish_session_t ();
|
||||
|
||||
@@ -108,8 +105,8 @@ namespace zmq
|
||||
void reset ();
|
||||
|
||||
private:
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
group,
|
||||
body
|
||||
} state;
|
||||
@@ -119,7 +116,6 @@ namespace zmq
|
||||
dish_session_t (const dish_session_t &);
|
||||
const dish_session_t &operator= (const dish_session_t &);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
11
src/dist.cpp
11
src/dist.cpp
@@ -34,11 +34,7 @@
|
||||
#include "msg.hpp"
|
||||
#include "likely.hpp"
|
||||
|
||||
zmq::dist_t::dist_t () :
|
||||
matching (0),
|
||||
active (0),
|
||||
eligible (0),
|
||||
more (false)
|
||||
zmq::dist_t::dist_t () : matching (0), active (0), eligible (0), more (false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -56,8 +52,7 @@ void zmq::dist_t::attach (pipe_t *pipe_)
|
||||
pipes.push_back (pipe_);
|
||||
pipes.swap (eligible, pipes.size () - 1);
|
||||
eligible++;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
pipes.push_back (pipe_);
|
||||
pipes.swap (active, pipes.size () - 1);
|
||||
active++;
|
||||
@@ -231,5 +226,3 @@ bool zmq::dist_t::check_hwm ()
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -37,7 +37,6 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
class pipe_t;
|
||||
class msg_t;
|
||||
|
||||
@@ -46,7 +45,6 @@ namespace zmq
|
||||
class dist_t
|
||||
{
|
||||
public:
|
||||
|
||||
dist_t ();
|
||||
~dist_t ();
|
||||
|
||||
@@ -81,7 +79,6 @@ namespace zmq
|
||||
bool check_hwm ();
|
||||
|
||||
private:
|
||||
|
||||
// Write the message to the pipe. Make the pipe inactive if writing
|
||||
// fails. In such a case false is returned.
|
||||
bool write (zmq::pipe_t *pipe_, zmq::msg_t *msg_);
|
||||
@@ -114,7 +111,6 @@ namespace zmq
|
||||
dist_t (const dist_t &);
|
||||
const dist_t &operator= (const dist_t &);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -47,7 +47,6 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
// Helper base class for encoders. It implements the state machine that
|
||||
// fills the outgoing buffer. Derived classes should implement individual
|
||||
// state machine actions.
|
||||
@@ -55,7 +54,6 @@ namespace zmq
|
||||
template <typename T> class encoder_base_t : public i_encoder
|
||||
{
|
||||
public:
|
||||
|
||||
inline encoder_base_t (size_t bufsize_) :
|
||||
write_pos (0),
|
||||
to_write (0),
|
||||
@@ -70,10 +68,7 @@ namespace zmq
|
||||
|
||||
// The destructor doesn't have to be virtual. It is made virtual
|
||||
// just to keep ICC and code checking tools from complaining.
|
||||
inline virtual ~encoder_base_t ()
|
||||
{
|
||||
free (buf);
|
||||
}
|
||||
inline virtual ~encoder_base_t () { free (buf); }
|
||||
|
||||
// The function returns a batch of binary data. The data
|
||||
// are filled to a supplied buffer. If no buffer is supplied (data_
|
||||
@@ -88,7 +83,6 @@ namespace zmq
|
||||
|
||||
size_t pos = 0;
|
||||
while (pos < buffersize) {
|
||||
|
||||
// If there are no more data to return, run the state machine.
|
||||
// If there are still no data, return what we already have
|
||||
// in the buffer.
|
||||
@@ -142,14 +136,15 @@ namespace zmq
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
// Prototype of state machine action.
|
||||
typedef void (T::*step_t) ();
|
||||
|
||||
// This function should be called from derived class to write the data
|
||||
// to the buffer and schedule next state machine action.
|
||||
inline void next_step (void *write_pos_, size_t to_write_,
|
||||
step_t next_, bool new_msg_flag_)
|
||||
inline void next_step (void *write_pos_,
|
||||
size_t to_write_,
|
||||
step_t next_,
|
||||
bool new_msg_flag_)
|
||||
{
|
||||
write_pos = (unsigned char *) write_pos_;
|
||||
to_write = to_write_;
|
||||
@@ -158,7 +153,6 @@ namespace zmq
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// Where to get the data to write from.
|
||||
unsigned char *write_pos;
|
||||
|
||||
@@ -179,11 +173,8 @@ namespace zmq
|
||||
void operator= (const encoder_base_t &);
|
||||
|
||||
protected:
|
||||
|
||||
msg_t *in_progress;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -44,9 +44,7 @@
|
||||
#include "config.hpp"
|
||||
#include "i_poll_events.hpp"
|
||||
|
||||
zmq::epoll_t::epoll_t (const zmq::ctx_t &ctx_) :
|
||||
ctx(ctx_),
|
||||
stopping (false)
|
||||
zmq::epoll_t::epoll_t (const zmq::ctx_t &ctx_) : ctx (ctx_), stopping (false)
|
||||
{
|
||||
#ifdef ZMQ_USE_EPOLL_CLOEXEC
|
||||
// Setting this option result in sane behaviour when exec() functions
|
||||
@@ -65,7 +63,8 @@ zmq::epoll_t::~epoll_t ()
|
||||
worker.stop ();
|
||||
|
||||
close (epoll_fd);
|
||||
for (retired_t::iterator it = retired.begin (); it != retired.end (); ++it) {
|
||||
for (retired_t::iterator it = retired.begin (); it != retired.end ();
|
||||
++it) {
|
||||
LIBZMQ_DELETE (*it);
|
||||
}
|
||||
}
|
||||
@@ -159,7 +158,6 @@ void zmq::epoll_t::loop ()
|
||||
epoll_event ev_buf[max_io_events];
|
||||
|
||||
while (!stopping) {
|
||||
|
||||
// Execute any due timers.
|
||||
int timeout = (int) execute_timers ();
|
||||
|
||||
@@ -190,7 +188,8 @@ void zmq::epoll_t::loop ()
|
||||
|
||||
// Destroy retired event sources.
|
||||
retired_sync.lock ();
|
||||
for (retired_t::iterator it = retired.begin (); it != retired.end (); ++it) {
|
||||
for (retired_t::iterator it = retired.begin (); it != retired.end ();
|
||||
++it) {
|
||||
LIBZMQ_DELETE (*it);
|
||||
}
|
||||
retired.clear ();
|
||||
|
@@ -45,7 +45,6 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
struct i_poll_events;
|
||||
|
||||
// This class implements socket polling mechanism using the Linux-specific
|
||||
@@ -54,7 +53,6 @@ namespace zmq
|
||||
class epoll_t : public poller_base_t
|
||||
{
|
||||
public:
|
||||
|
||||
typedef void *handle_t;
|
||||
|
||||
epoll_t (const ctx_t &ctx_);
|
||||
@@ -73,7 +71,6 @@ namespace zmq
|
||||
static int max_fds ();
|
||||
|
||||
private:
|
||||
|
||||
// Main worker thread routine.
|
||||
static void worker_routine (void *arg_);
|
||||
|
||||
@@ -111,7 +108,6 @@ namespace zmq
|
||||
};
|
||||
|
||||
typedef epoll_t poller_t;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
240
src/err.cpp
240
src/err.cpp
@@ -100,123 +100,143 @@ const char *zmq::wsa_error_no (int no_, const char * wsae_wouldblock_string)
|
||||
// TODO: It seems that list of Windows socket errors is longer than this.
|
||||
// Investigate whether there's a way to convert it into the string
|
||||
// automatically (wsaError->HRESULT->string?).
|
||||
return
|
||||
(no_ == WSABASEERR) ?
|
||||
"No Error" :
|
||||
(no_ == WSAEINTR) ?
|
||||
"Interrupted system call" :
|
||||
(no_ == WSAEBADF) ?
|
||||
"Bad file number" :
|
||||
(no_ == WSAEACCES) ?
|
||||
"Permission denied" :
|
||||
(no_ == WSAEFAULT) ?
|
||||
"Bad address" :
|
||||
(no_ == WSAEINVAL) ?
|
||||
"Invalid argument" :
|
||||
(no_ == WSAEMFILE) ?
|
||||
"Too many open files" :
|
||||
(no_ == WSAEWOULDBLOCK) ?
|
||||
wsae_wouldblock_string :
|
||||
(no_ == WSAEINPROGRESS) ?
|
||||
"Operation now in progress" :
|
||||
(no_ == WSAEALREADY) ?
|
||||
"Operation already in progress" :
|
||||
(no_ == WSAENOTSOCK) ?
|
||||
"Socket operation on non-socket" :
|
||||
(no_ == WSAEDESTADDRREQ) ?
|
||||
"Destination address required" :
|
||||
(no_ == WSAEMSGSIZE) ?
|
||||
"Message too long" :
|
||||
(no_ == WSAEPROTOTYPE) ?
|
||||
"Protocol wrong type for socket" :
|
||||
(no_ == WSAENOPROTOOPT) ?
|
||||
"Bad protocol option" :
|
||||
(no_ == WSAEPROTONOSUPPORT) ?
|
||||
"Protocol not supported" :
|
||||
(no_ == WSAESOCKTNOSUPPORT) ?
|
||||
"Socket type not supported" :
|
||||
(no_ == WSAEOPNOTSUPP) ?
|
||||
"Operation not supported on socket" :
|
||||
(no_ == WSAEPFNOSUPPORT) ?
|
||||
"Protocol family not supported" :
|
||||
(no_ == WSAEAFNOSUPPORT) ?
|
||||
"Address family not supported by protocol family" :
|
||||
(no_ == WSAEADDRINUSE) ?
|
||||
"Address already in use" :
|
||||
(no_ == WSAEADDRNOTAVAIL) ?
|
||||
"Can't assign requested address" :
|
||||
(no_ == WSAENETDOWN) ?
|
||||
"Network is down" :
|
||||
(no_ == WSAENETUNREACH) ?
|
||||
"Network is unreachable" :
|
||||
(no_ == WSAENETRESET) ?
|
||||
"Net dropped connection or reset" :
|
||||
(no_ == WSAECONNABORTED) ?
|
||||
"Software caused connection abort" :
|
||||
(no_ == WSAECONNRESET) ?
|
||||
"Connection reset by peer" :
|
||||
(no_ == WSAENOBUFS) ?
|
||||
"No buffer space available" :
|
||||
(no_ == WSAEISCONN) ?
|
||||
"Socket is already connected" :
|
||||
(no_ == WSAENOTCONN) ?
|
||||
"Socket is not connected" :
|
||||
(no_ == WSAESHUTDOWN) ?
|
||||
"Can't send after socket shutdown" :
|
||||
(no_ == WSAETOOMANYREFS) ?
|
||||
"Too many references can't splice" :
|
||||
(no_ == WSAETIMEDOUT) ?
|
||||
"Connection timed out" :
|
||||
(no_ == WSAECONNREFUSED) ?
|
||||
"Connection refused" :
|
||||
(no_ == WSAELOOP) ?
|
||||
"Too many levels of symbolic links" :
|
||||
(no_ == WSAENAMETOOLONG) ?
|
||||
"File name too long" :
|
||||
(no_ == WSAEHOSTDOWN) ?
|
||||
"Host is down" :
|
||||
(no_ == WSAEHOSTUNREACH) ?
|
||||
"No Route to Host" :
|
||||
(no_ == WSAENOTEMPTY) ?
|
||||
"Directory not empty" :
|
||||
(no_ == WSAEPROCLIM) ?
|
||||
"Too many processes" :
|
||||
(no_ == WSAEUSERS) ?
|
||||
"Too many users" :
|
||||
(no_ == WSAEDQUOT) ?
|
||||
"Disc Quota Exceeded" :
|
||||
(no_ == WSAESTALE) ?
|
||||
"Stale NFS file handle" :
|
||||
(no_ == WSAEREMOTE) ?
|
||||
"Too many levels of remote in path" :
|
||||
(no_ == WSASYSNOTREADY) ?
|
||||
"Network SubSystem is unavailable" :
|
||||
(no_ == WSAVERNOTSUPPORTED) ?
|
||||
"WINSOCK DLL Version out of range" :
|
||||
(no_ == WSANOTINITIALISED) ?
|
||||
"Successful WSASTARTUP not yet performed" :
|
||||
(no_ == WSAHOST_NOT_FOUND) ?
|
||||
"Host not found" :
|
||||
(no_ == WSATRY_AGAIN) ?
|
||||
"Non-Authoritative Host not found" :
|
||||
(no_ == WSANO_RECOVERY) ?
|
||||
"Non-Recoverable errors: FORMERR REFUSED NOTIMP" :
|
||||
(no_ == WSANO_DATA) ?
|
||||
"Valid name no data record of requested" :
|
||||
"error not defined";
|
||||
return (no_ == WSABASEERR)
|
||||
? "No Error"
|
||||
: (no_ == WSAEINTR)
|
||||
? "Interrupted system call"
|
||||
: (no_ == WSAEBADF)
|
||||
? "Bad file number"
|
||||
: (no_ == WSAEACCES)
|
||||
? "Permission denied"
|
||||
: (no_ == WSAEFAULT)
|
||||
? "Bad address"
|
||||
: (no_ == WSAEINVAL)
|
||||
? "Invalid argument"
|
||||
: (no_ == WSAEMFILE)
|
||||
? "Too many open files"
|
||||
: (no_ == WSAEWOULDBLOCK)
|
||||
? wsae_wouldblock_string
|
||||
: (no_ == WSAEINPROGRESS)
|
||||
? "Operation now in progress"
|
||||
: (no_ == WSAEALREADY)
|
||||
? "Operation already in "
|
||||
"progress"
|
||||
: (no_ == WSAENOTSOCK)
|
||||
? "Socket operation on "
|
||||
"non-socket"
|
||||
: (no_ == WSAEDESTADDRREQ)
|
||||
? "Destination "
|
||||
"address required"
|
||||
: (no_ == WSAEMSGSIZE)
|
||||
? "Message too "
|
||||
"long"
|
||||
: (no_
|
||||
== WSAEPROTOTYPE)
|
||||
? "Protocol "
|
||||
"wrong type "
|
||||
"for socket"
|
||||
: (no_
|
||||
== WSAENOPROTOOPT)
|
||||
? "Bad "
|
||||
"protoco"
|
||||
"l "
|
||||
"option"
|
||||
: (no_
|
||||
== WSAEPROTONOSUPPORT)
|
||||
? "Pro"
|
||||
"toc"
|
||||
"ol "
|
||||
"not"
|
||||
" su"
|
||||
"ppo"
|
||||
"rte"
|
||||
"d"
|
||||
: (no_
|
||||
== WSAESOCKTNOSUPPORT)
|
||||
? "Socket type not supported"
|
||||
: (no_
|
||||
== WSAEOPNOTSUPP)
|
||||
? "Operation not supported on socket"
|
||||
: (no_
|
||||
== WSAEPFNOSUPPORT)
|
||||
? "Protocol family not supported"
|
||||
: (no_
|
||||
== WSAEAFNOSUPPORT)
|
||||
? "Address family not supported by protocol family"
|
||||
: (no_ == WSAEADDRINUSE) ? "Address already in use"
|
||||
: (no_ == WSAEADDRNOTAVAIL) ? "Can't assign requested address"
|
||||
: (no_ == WSAENETDOWN) ? "Network is down"
|
||||
: (no_ == WSAENETUNREACH) ? "Network is unreachable"
|
||||
: (no_ == WSAENETRESET) ? "Net dropped connection or reset"
|
||||
: (no_ == WSAECONNABORTED) ? "Software caused connection abort"
|
||||
: (no_ == WSAECONNRESET) ? "Connection reset by peer"
|
||||
: (no_
|
||||
== WSAENOBUFS)
|
||||
? "No buffer space available"
|
||||
: (no_ == WSAEISCONN) ? "Socket is already connected"
|
||||
: (no_
|
||||
== WSAENOTCONN)
|
||||
? "Socket is not connected"
|
||||
: (no_ == WSAESHUTDOWN) ? "Can't send after socket shutdown"
|
||||
: (no_ == WSAETOOMANYREFS) ? "Too many references can't splice"
|
||||
: (no_ == WSAETIMEDOUT) ? "Connection timed out"
|
||||
: (no_
|
||||
== WSAECONNREFUSED)
|
||||
? "Connection refused"
|
||||
: (no_
|
||||
== WSAELOOP)
|
||||
? "Too many levels of symbolic links"
|
||||
: (no_
|
||||
== WSAENAMETOOLONG)
|
||||
? "File name too long"
|
||||
: (no_ == WSAEHOSTDOWN) ? "Host is down"
|
||||
: (no_
|
||||
== WSAEHOSTUNREACH)
|
||||
? "No Route to Host"
|
||||
: (no_ == WSAENOTEMPTY) ? "Directory not empty"
|
||||
: (no_ == WSAEPROCLIM) ? "Too many processes"
|
||||
: (
|
||||
no_
|
||||
== WSAEUSERS)
|
||||
? "Too many users"
|
||||
: (no_
|
||||
== WSAEDQUOT)
|
||||
? "Disc Quota Exceeded"
|
||||
: (no_
|
||||
== WSAESTALE)
|
||||
? "Stale NFS file handle"
|
||||
: (no_ == WSAEREMOTE) ? "Too many levels of remote in path"
|
||||
: (no_
|
||||
== WSASYSNOTREADY)
|
||||
? "Network SubSystem is unavailable"
|
||||
: (no_ == WSAVERNOTSUPPORTED) ? "WINSOCK DLL Version out of range"
|
||||
: (no_
|
||||
== WSANOTINITIALISED)
|
||||
? "Successful WSASTARTUP not yet performed"
|
||||
: (no_ == WSAHOST_NOT_FOUND) ? "Host not found"
|
||||
: (no_
|
||||
== WSATRY_AGAIN)
|
||||
? "Non-Authoritative Host not found"
|
||||
: (no_ == WSANO_RECOVERY) ? "Non-Recoverable errors: FORMERR REFUSED NOTIMP"
|
||||
: (no_
|
||||
== WSANO_DATA)
|
||||
? "Valid name no data record of requested"
|
||||
: "error not defined";
|
||||
}
|
||||
|
||||
void zmq::win_error (char *buffer_, size_t buffer_size_)
|
||||
{
|
||||
DWORD errcode = GetLastError ();
|
||||
#if defined _WIN32_WCE
|
||||
DWORD rc = FormatMessageW (FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errcode, MAKELANGID(LANG_NEUTRAL,
|
||||
SUBLANG_DEFAULT), (LPWSTR)buffer_, buffer_size_ / sizeof(wchar_t), NULL);
|
||||
DWORD rc = FormatMessageW (
|
||||
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errcode,
|
||||
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR) buffer_,
|
||||
buffer_size_ / sizeof (wchar_t), NULL);
|
||||
#else
|
||||
DWORD rc = FormatMessageA (FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errcode, MAKELANGID(LANG_NEUTRAL,
|
||||
SUBLANG_DEFAULT), buffer_, (DWORD) buffer_size_, NULL);
|
||||
DWORD rc = FormatMessageA (
|
||||
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errcode,
|
||||
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), buffer_, (DWORD) buffer_size_,
|
||||
NULL);
|
||||
#endif
|
||||
zmq_assert (rc);
|
||||
}
|
||||
|
14
src/err.hpp
14
src/err.hpp
@@ -65,7 +65,9 @@ namespace zmq
|
||||
namespace zmq
|
||||
{
|
||||
const char *wsa_error ();
|
||||
const char *wsa_error_no (int no_, const char * wsae_wouldblock_string = "Operation would block");
|
||||
const char *
|
||||
wsa_error_no (int no_,
|
||||
const char *wsae_wouldblock_string = "Operation would block");
|
||||
void win_error (char *buffer_, size_t buffer_size_);
|
||||
int wsa_error_to_errno (int errcode);
|
||||
}
|
||||
@@ -117,8 +119,8 @@ namespace zmq
|
||||
#define zmq_assert(x) \
|
||||
do { \
|
||||
if (unlikely (!(x))) { \
|
||||
fprintf (stderr, "Assertion failed: %s (%s:%d)\n", #x, \
|
||||
__FILE__, __LINE__);\
|
||||
fprintf (stderr, "Assertion failed: %s (%s:%d)\n", #x, __FILE__, \
|
||||
__LINE__); \
|
||||
fflush (stderr); \
|
||||
zmq::zmq_abort (#x); \
|
||||
} \
|
||||
@@ -161,13 +163,11 @@ namespace zmq
|
||||
#define alloc_assert(x) \
|
||||
do { \
|
||||
if (unlikely (!x)) { \
|
||||
fprintf (stderr, "FATAL ERROR: OUT OF MEMORY (%s:%d)\n",\
|
||||
__FILE__, __LINE__);\
|
||||
fprintf (stderr, "FATAL ERROR: OUT OF MEMORY (%s:%d)\n", __FILE__, \
|
||||
__LINE__); \
|
||||
fflush (stderr); \
|
||||
zmq::zmq_abort ("FATAL ERROR: OUT OF MEMORY"); \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
15
src/fd.hpp
15
src/fd.hpp
@@ -39,14 +39,23 @@ namespace zmq
|
||||
#ifdef ZMQ_HAVE_WINDOWS
|
||||
#if defined _MSC_VER && _MSC_VER <= 1400
|
||||
typedef UINT_PTR fd_t;
|
||||
enum {retired_fd = (fd_t)(~0)};
|
||||
enum
|
||||
{
|
||||
retired_fd = (fd_t) (~0)
|
||||
};
|
||||
#else
|
||||
typedef SOCKET fd_t;
|
||||
enum {retired_fd = (fd_t)INVALID_SOCKET};
|
||||
enum
|
||||
{
|
||||
retired_fd = (fd_t) INVALID_SOCKET
|
||||
};
|
||||
#endif
|
||||
#else
|
||||
typedef int fd_t;
|
||||
enum {retired_fd = -1};
|
||||
enum
|
||||
{
|
||||
retired_fd = -1
|
||||
};
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
11
src/fq.cpp
11
src/fq.cpp
@@ -33,11 +33,7 @@
|
||||
#include "err.hpp"
|
||||
#include "msg.hpp"
|
||||
|
||||
zmq::fq_t::fq_t () :
|
||||
active (0),
|
||||
last_in (NULL),
|
||||
current (0),
|
||||
more (false)
|
||||
zmq::fq_t::fq_t () : active (0), last_in (NULL), current (0), more (false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -93,7 +89,6 @@ int zmq::fq_t::recvpipe (msg_t *msg_, pipe_t **pipe_)
|
||||
|
||||
// Round-robin over the pipes to get the next message.
|
||||
while (active > 0) {
|
||||
|
||||
// Try to fetch new message. If we've already read part of the message
|
||||
// subsequent part should be immediately available.
|
||||
bool fetched = pipes[current]->read (msg_);
|
||||
@@ -157,7 +152,5 @@ bool zmq::fq_t::has_in ()
|
||||
|
||||
const zmq::blob_t &zmq::fq_t::get_credential () const
|
||||
{
|
||||
return last_in?
|
||||
last_in->get_credential (): saved_credential;
|
||||
return last_in ? last_in->get_credential () : saved_credential;
|
||||
}
|
||||
|
||||
|
@@ -37,7 +37,6 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
// Class manages a set of inbound pipes. On receive it performs fair
|
||||
// queueing so that senders gone berserk won't cause denial of
|
||||
// service for decent senders.
|
||||
@@ -45,7 +44,6 @@ namespace zmq
|
||||
class fq_t
|
||||
{
|
||||
public:
|
||||
|
||||
fq_t ();
|
||||
~fq_t ();
|
||||
|
||||
@@ -59,7 +57,6 @@ namespace zmq
|
||||
const blob_t &get_credential () const;
|
||||
|
||||
private:
|
||||
|
||||
// Inbound pipes.
|
||||
typedef array_t<pipe_t, 1> pipes_t;
|
||||
pipes_t pipes;
|
||||
@@ -86,7 +83,6 @@ namespace zmq
|
||||
fq_t (const fq_t &);
|
||||
const fq_t &operator= (const fq_t &);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -68,7 +68,6 @@ int zmq::gather_t::xrecv (msg_t *msg_)
|
||||
|
||||
// Drop any messages with more flag
|
||||
while (rc == 0 && msg_->flags () & msg_t::more) {
|
||||
|
||||
// drop all frames of the current multi-frame message
|
||||
rc = fq.recvpipe (msg_, NULL);
|
||||
|
||||
|
@@ -36,22 +36,18 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
class ctx_t;
|
||||
class pipe_t;
|
||||
class msg_t;
|
||||
class io_thread_t;
|
||||
|
||||
class gather_t :
|
||||
public socket_base_t
|
||||
class gather_t : public socket_base_t
|
||||
{
|
||||
public:
|
||||
|
||||
gather_t (zmq::ctx_t *parent_, uint32_t tid_, int sid_);
|
||||
~gather_t ();
|
||||
|
||||
protected:
|
||||
|
||||
// Overrides of functions from socket_base_t.
|
||||
void xattach_pipe (zmq::pipe_t *pipe_, bool subscribe_to_all_);
|
||||
int xrecv (zmq::msg_t *msg_);
|
||||
@@ -61,15 +57,12 @@ namespace zmq
|
||||
void xpipe_terminated (zmq::pipe_t *pipe_);
|
||||
|
||||
private:
|
||||
|
||||
// Fair queueing object for inbound pipes.
|
||||
fq_t fq;
|
||||
|
||||
gather_t (const gather_t &);
|
||||
const gather_t &operator= (const gather_t &);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -49,19 +49,22 @@ zmq::gssapi_client_t::gssapi_client_t (session_base_t *session_,
|
||||
mechs (),
|
||||
security_context_established (false)
|
||||
{
|
||||
const std::string::size_type service_size = options_.gss_service_principal.size();
|
||||
const std::string::size_type service_size =
|
||||
options_.gss_service_principal.size ();
|
||||
service_name = static_cast<char *> (malloc (service_size + 1));
|
||||
assert (service_name);
|
||||
memcpy(service_name, options_.gss_service_principal.c_str(), service_size+1 );
|
||||
memcpy (service_name, options_.gss_service_principal.c_str (),
|
||||
service_size + 1);
|
||||
|
||||
service_name_type = convert_nametype (options_.gss_service_principal_nt);
|
||||
maj_stat = GSS_S_COMPLETE;
|
||||
if(!options_.gss_principal.empty())
|
||||
{
|
||||
const std::string::size_type principal_size = options_.gss_principal.size();
|
||||
if (!options_.gss_principal.empty ()) {
|
||||
const std::string::size_type principal_size =
|
||||
options_.gss_principal.size ();
|
||||
principal_name = static_cast<char *> (malloc (principal_size + 1));
|
||||
assert (principal_name);
|
||||
memcpy(principal_name, options_.gss_principal.c_str(), principal_size+1 );
|
||||
memcpy (principal_name, options_.gss_principal.c_str (),
|
||||
principal_size + 1);
|
||||
|
||||
gss_OID name_type = convert_nametype (options_.gss_principal_nt);
|
||||
if (acquire_credentials (principal_name, &cred, name_type) != 0)
|
||||
@@ -107,8 +110,7 @@ int zmq::gssapi_client_t::next_handshake_command (msg_t *msg_)
|
||||
if (maj_stat == GSS_S_COMPLETE) {
|
||||
security_context_established = true;
|
||||
state = recv_ready;
|
||||
}
|
||||
else
|
||||
} else
|
||||
state = recv_next_token;
|
||||
|
||||
return 0;
|
||||
@@ -126,8 +128,7 @@ int zmq::gssapi_client_t::process_handshake_command (msg_t *msg_)
|
||||
|
||||
if (state != recv_next_token) {
|
||||
session->get_socket ()->event_handshake_failed_protocol (
|
||||
session->get_endpoint (),
|
||||
ZMQ_PROTOCOL_ERROR_ZMTP_UNEXPECTED_COMMAND);
|
||||
session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_UNEXPECTED_COMMAND);
|
||||
errno = EPROTO;
|
||||
return -1;
|
||||
}
|
||||
@@ -182,17 +183,15 @@ int zmq::gssapi_client_t::initialize_context ()
|
||||
send_tok.value = service_name;
|
||||
send_tok.length = strlen (service_name) + 1;
|
||||
OM_uint32 maj = gss_import_name (&min_stat, &send_tok,
|
||||
service_name_type,
|
||||
&target_name);
|
||||
service_name_type, &target_name);
|
||||
|
||||
if (maj != GSS_S_COMPLETE)
|
||||
return -1;
|
||||
}
|
||||
|
||||
maj_stat = gss_init_sec_context(&init_sec_min_stat, cred, &context,
|
||||
target_name, mechs.elements,
|
||||
gss_flags, 0, NULL, token_ptr, NULL,
|
||||
&send_tok, &ret_flags, NULL);
|
||||
maj_stat = gss_init_sec_context (
|
||||
&init_sec_min_stat, cred, &context, target_name, mechs.elements,
|
||||
gss_flags, 0, NULL, token_ptr, NULL, &send_tok, &ret_flags, NULL);
|
||||
|
||||
if (token_ptr != GSS_C_NO_BUFFER)
|
||||
free (recv_tok.value);
|
||||
|
@@ -36,7 +36,6 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
class msg_t;
|
||||
class session_base_t;
|
||||
|
||||
@@ -54,8 +53,8 @@ namespace zmq
|
||||
virtual status_t status () const;
|
||||
|
||||
private:
|
||||
|
||||
enum state_t {
|
||||
enum state_t
|
||||
{
|
||||
call_next_init,
|
||||
send_next_token,
|
||||
recv_next_token,
|
||||
@@ -86,7 +85,6 @@ namespace zmq
|
||||
int produce_next_token (msg_t *msg_);
|
||||
int process_next_token (msg_t *msg_);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -41,8 +41,7 @@
|
||||
#include "wire.hpp"
|
||||
|
||||
zmq::gssapi_mechanism_base_t::gssapi_mechanism_base_t (
|
||||
session_base_t *session_,
|
||||
const options_t &options_) :
|
||||
session_base_t *session_, const options_t &options_) :
|
||||
mechanism_base_t (session_, options_),
|
||||
send_tok (),
|
||||
recv_tok (),
|
||||
@@ -81,7 +80,8 @@ int zmq::gssapi_mechanism_base_t::encode_message (msg_t *msg_)
|
||||
if (msg_->flags () & msg_t::command)
|
||||
flags |= 0x02;
|
||||
|
||||
uint8_t *plaintext_buffer = static_cast <uint8_t *>(malloc(msg_->size ()+1));
|
||||
uint8_t *plaintext_buffer =
|
||||
static_cast<uint8_t *> (malloc (msg_->size () + 1));
|
||||
alloc_assert (plaintext_buffer);
|
||||
|
||||
plaintext_buffer[0] = flags;
|
||||
@@ -90,8 +90,8 @@ int zmq::gssapi_mechanism_base_t::encode_message (msg_t *msg_)
|
||||
plaintext.value = plaintext_buffer;
|
||||
plaintext.length = msg_->size () + 1;
|
||||
|
||||
maj_stat = gss_wrap(&min_stat, context, 1, GSS_C_QOP_DEFAULT,
|
||||
&plaintext, &state, &wrapped);
|
||||
maj_stat = gss_wrap (&min_stat, context, 1, GSS_C_QOP_DEFAULT, &plaintext,
|
||||
&state, &wrapped);
|
||||
|
||||
zmq_assert (maj_stat == GSS_S_COMPLETE);
|
||||
zmq_assert (state);
|
||||
@@ -134,8 +134,7 @@ int zmq::gssapi_mechanism_base_t::decode_message (msg_t *msg_)
|
||||
// Get command string
|
||||
if (bytes_left < 8 || memcmp (ptr, "\x07MESSAGE", 8)) {
|
||||
session->get_socket ()->event_handshake_failed_protocol (
|
||||
session->get_endpoint (),
|
||||
ZMQ_PROTOCOL_ERROR_ZMTP_UNEXPECTED_COMMAND);
|
||||
session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_UNEXPECTED_COMMAND);
|
||||
errno = EPROTO;
|
||||
return -1;
|
||||
}
|
||||
@@ -177,16 +176,14 @@ int zmq::gssapi_mechanism_base_t::decode_message (msg_t *msg_)
|
||||
// Unwrap the token value
|
||||
int state;
|
||||
gss_buffer_desc plaintext;
|
||||
maj_stat = gss_unwrap(&min_stat, context, &wrapped, &plaintext,
|
||||
&state, (gss_qop_t *) NULL);
|
||||
maj_stat = gss_unwrap (&min_stat, context, &wrapped, &plaintext, &state,
|
||||
(gss_qop_t *) NULL);
|
||||
|
||||
if (maj_stat != GSS_S_COMPLETE)
|
||||
{
|
||||
if (maj_stat != GSS_S_COMPLETE) {
|
||||
gss_release_buffer (&min_stat, &plaintext);
|
||||
free (wrapped.value);
|
||||
session->get_socket ()->event_handshake_failed_protocol (
|
||||
session->get_endpoint (),
|
||||
ZMQ_PROTOCOL_ERROR_ZMTP_CRYPTOGRAPHIC);
|
||||
session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_CRYPTOGRAPHIC);
|
||||
errno = EPROTO;
|
||||
return -1;
|
||||
}
|
||||
@@ -205,7 +202,8 @@ int zmq::gssapi_mechanism_base_t::decode_message (msg_t *msg_)
|
||||
if (flags & 0x02)
|
||||
msg_->set_flags (msg_t::command);
|
||||
|
||||
memcpy (msg_->data (), static_cast <char *> (plaintext.value)+1, plaintext.length-1);
|
||||
memcpy (msg_->data (), static_cast<char *> (plaintext.value) + 1,
|
||||
plaintext.length - 1);
|
||||
|
||||
gss_release_buffer (&min_stat, &plaintext);
|
||||
free (wrapped.value);
|
||||
@@ -221,7 +219,9 @@ int zmq::gssapi_mechanism_base_t::decode_message (msg_t *msg_)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int zmq::gssapi_mechanism_base_t::produce_initiate (msg_t *msg_, void *token_value_, size_t token_length_)
|
||||
int zmq::gssapi_mechanism_base_t::produce_initiate (msg_t *msg_,
|
||||
void *token_value_,
|
||||
size_t token_length_)
|
||||
{
|
||||
zmq_assert (token_value_);
|
||||
zmq_assert (token_length_ <= 0xFFFFFFFFUL);
|
||||
@@ -248,7 +248,9 @@ int zmq::gssapi_mechanism_base_t::produce_initiate (msg_t *msg_, void *token_val
|
||||
return 0;
|
||||
}
|
||||
|
||||
int zmq::gssapi_mechanism_base_t::process_initiate (msg_t *msg_, void **token_value_, size_t &token_length_)
|
||||
int zmq::gssapi_mechanism_base_t::process_initiate (msg_t *msg_,
|
||||
void **token_value_,
|
||||
size_t &token_length_)
|
||||
{
|
||||
zmq_assert (token_value_);
|
||||
|
||||
@@ -262,8 +264,7 @@ int zmq::gssapi_mechanism_base_t::process_initiate (msg_t *msg_, void **token_va
|
||||
// Get command string
|
||||
if (bytes_left < 9 || memcmp (ptr, "\x08INITIATE", 9)) {
|
||||
session->get_socket ()->event_handshake_failed_protocol (
|
||||
session->get_endpoint (),
|
||||
ZMQ_PROTOCOL_ERROR_ZMTP_UNEXPECTED_COMMAND);
|
||||
session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_UNEXPECTED_COMMAND);
|
||||
errno = EPROTO;
|
||||
return -1;
|
||||
}
|
||||
@@ -291,7 +292,8 @@ int zmq::gssapi_mechanism_base_t::process_initiate (msg_t *msg_, void **token_va
|
||||
return -1;
|
||||
}
|
||||
|
||||
*token_value_ = static_cast <char *> (malloc (token_length_ ? token_length_ : 1));
|
||||
*token_value_ =
|
||||
static_cast<char *> (malloc (token_length_ ? token_length_ : 1));
|
||||
alloc_assert (*token_value_);
|
||||
|
||||
if (token_length_) {
|
||||
@@ -338,8 +340,7 @@ int zmq::gssapi_mechanism_base_t::process_ready (msg_t *msg_)
|
||||
|
||||
if (bytes_left < 6 || memcmp (ptr, "\x05READY", 6)) {
|
||||
session->get_socket ()->event_handshake_failed_protocol (
|
||||
session->get_endpoint (),
|
||||
ZMQ_PROTOCOL_ERROR_ZMTP_UNEXPECTED_COMMAND);
|
||||
session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_UNEXPECTED_COMMAND);
|
||||
errno = EPROTO;
|
||||
return -1;
|
||||
}
|
||||
@@ -348,8 +349,7 @@ int zmq::gssapi_mechanism_base_t::process_ready (msg_t *msg_)
|
||||
rc = parse_metadata (ptr, bytes_left);
|
||||
if (rc == -1)
|
||||
session->get_socket ()->event_handshake_failed_protocol (
|
||||
session->get_endpoint (),
|
||||
ZMQ_PROTOCOL_ERROR_ZMTP_INVALID_METADATA);
|
||||
session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_INVALID_METADATA);
|
||||
|
||||
return rc;
|
||||
}
|
||||
@@ -371,7 +371,9 @@ const gss_OID zmq::gssapi_mechanism_base_t::convert_nametype (int zmq_nametype)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int zmq::gssapi_mechanism_base_t::acquire_credentials (char * service_name_, gss_cred_id_t * cred_, gss_OID name_type_)
|
||||
int zmq::gssapi_mechanism_base_t::acquire_credentials (char *service_name_,
|
||||
gss_cred_id_t *cred_,
|
||||
gss_OID name_type_)
|
||||
{
|
||||
OM_uint32 maj_stat;
|
||||
OM_uint32 min_stat;
|
||||
@@ -381,15 +383,13 @@ int zmq::gssapi_mechanism_base_t::acquire_credentials (char * service_name_, gss
|
||||
name_buf.value = service_name_;
|
||||
name_buf.length = strlen ((char *) name_buf.value) + 1;
|
||||
|
||||
maj_stat = gss_import_name (&min_stat, &name_buf,
|
||||
name_type_, &server_name);
|
||||
maj_stat = gss_import_name (&min_stat, &name_buf, name_type_, &server_name);
|
||||
|
||||
if (maj_stat != GSS_S_COMPLETE)
|
||||
return -1;
|
||||
|
||||
maj_stat = gss_acquire_cred (&min_stat, server_name, 0,
|
||||
GSS_C_NO_OID_SET, GSS_C_BOTH,
|
||||
cred_, NULL, NULL);
|
||||
maj_stat = gss_acquire_cred (&min_stat, server_name, 0, GSS_C_NO_OID_SET,
|
||||
GSS_C_BOTH, cred_, NULL, NULL);
|
||||
|
||||
if (maj_stat != GSS_S_COMPLETE)
|
||||
return -1;
|
||||
|
@@ -42,7 +42,6 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
class msg_t;
|
||||
|
||||
/// Commonalities between clients and servers are captured here.
|
||||
@@ -126,7 +125,6 @@ namespace zmq
|
||||
// If true, use gss to encrypt messages. If false, only utilize gss for auth.
|
||||
bool do_encryption;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -54,12 +54,13 @@ zmq::gssapi_server_t::gssapi_server_t (session_base_t *session_,
|
||||
security_context_established (false)
|
||||
{
|
||||
maj_stat = GSS_S_CONTINUE_NEEDED;
|
||||
if(!options_.gss_principal.empty())
|
||||
{
|
||||
const std::string::size_type principal_size = options_.gss_principal.size();
|
||||
if (!options_.gss_principal.empty ()) {
|
||||
const std::string::size_type principal_size =
|
||||
options_.gss_principal.size ();
|
||||
principal_name = static_cast<char *> (malloc (principal_size + 1));
|
||||
assert (principal_name);
|
||||
memcpy(principal_name, options_.gss_principal.c_str(), principal_size+1 );
|
||||
memcpy (principal_name, options_.gss_principal.c_str (),
|
||||
principal_size + 1);
|
||||
gss_OID name_type = convert_nametype (options_.gss_principal_nt);
|
||||
if (acquire_credentials (principal_name, &cred, name_type) != 0)
|
||||
maj_stat = GSS_S_FAILURE;
|
||||
@@ -117,8 +118,7 @@ int zmq::gssapi_server_t::process_handshake_command (msg_t *msg_)
|
||||
|
||||
if (state != recv_next_token) {
|
||||
session->get_socket ()->event_handshake_failed_protocol (
|
||||
session->get_endpoint (),
|
||||
ZMQ_PROTOCOL_ERROR_ZMTP_UNEXPECTED_COMMAND);
|
||||
session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_UNEXPECTED_COMMAND);
|
||||
errno = EPROTO;
|
||||
return -1;
|
||||
}
|
||||
@@ -158,8 +158,8 @@ void zmq::gssapi_server_t::send_zap_request ()
|
||||
{
|
||||
gss_buffer_desc principal;
|
||||
gss_display_name (&min_stat, target_name, &principal, NULL);
|
||||
zap_client_t::send_zap_request ("GSSAPI", 6,
|
||||
reinterpret_cast<const uint8_t *> (principal.value),
|
||||
zap_client_t::send_zap_request (
|
||||
"GSSAPI", 6, reinterpret_cast<const uint8_t *> (principal.value),
|
||||
principal.length);
|
||||
|
||||
gss_release_buffer (&min_stat, &principal);
|
||||
@@ -235,10 +235,9 @@ int zmq::gssapi_server_t::process_next_token (msg_t *msg_)
|
||||
|
||||
void zmq::gssapi_server_t::accept_context ()
|
||||
{
|
||||
maj_stat = gss_accept_sec_context(&init_sec_min_stat, &context, cred,
|
||||
&recv_tok, GSS_C_NO_CHANNEL_BINDINGS,
|
||||
&target_name, &doid, &send_tok,
|
||||
&ret_flags, NULL, NULL);
|
||||
maj_stat = gss_accept_sec_context (
|
||||
&init_sec_min_stat, &context, cred, &recv_tok, GSS_C_NO_CHANNEL_BINDINGS,
|
||||
&target_name, &doid, &send_tok, &ret_flags, NULL, NULL);
|
||||
|
||||
if (recv_tok.value) {
|
||||
free (recv_tok.value);
|
||||
|
@@ -37,12 +37,10 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
class msg_t;
|
||||
class session_base_t;
|
||||
|
||||
class gssapi_server_t
|
||||
: public gssapi_mechanism_base_t, public zap_client_t
|
||||
class gssapi_server_t : public gssapi_mechanism_base_t, public zap_client_t
|
||||
{
|
||||
public:
|
||||
gssapi_server_t (session_base_t *session_,
|
||||
@@ -59,8 +57,8 @@ namespace zmq
|
||||
virtual status_t status () const;
|
||||
|
||||
private:
|
||||
|
||||
enum state_t {
|
||||
enum state_t
|
||||
{
|
||||
send_next_token,
|
||||
recv_next_token,
|
||||
expect_zap_reply,
|
||||
@@ -87,7 +85,6 @@ namespace zmq
|
||||
int process_next_token (msg_t *msg_);
|
||||
void send_zap_request ();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -34,7 +34,6 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
class msg_t;
|
||||
|
||||
// Interface to be implemented by message decoder.
|
||||
@@ -51,14 +50,11 @@ namespace zmq
|
||||
// When a message is decoded, 1 is returned.
|
||||
// When the decoder needs more data, 0 is returned.
|
||||
// On error, -1 is returned and errno is set accordingly.
|
||||
virtual int decode (const unsigned char *data_, size_t size_,
|
||||
size_t &processed) = 0;
|
||||
virtual int
|
||||
decode (const unsigned char *data_, size_t size_, size_t &processed) = 0;
|
||||
|
||||
virtual msg_t *msg () = 0;
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -34,7 +34,6 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
// Forward declaration
|
||||
class msg_t;
|
||||
|
||||
@@ -52,9 +51,7 @@ namespace zmq
|
||||
|
||||
// Load a new message into encoder.
|
||||
virtual void load_msg (msg_t *msg_) = 0;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -32,7 +32,6 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
class io_thread_t;
|
||||
|
||||
// Abstract interface to be implemented by various engines.
|
||||
@@ -60,9 +59,7 @@ namespace zmq
|
||||
virtual void zap_msg_available () = 0;
|
||||
|
||||
virtual const char *get_endpoint () const = 0;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -51,10 +51,7 @@ namespace zmq
|
||||
// with the context in the parent process.
|
||||
virtual void forked () = 0;
|
||||
#endif
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -32,7 +32,6 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
// Virtual interface to be exposed by object that want to be notified
|
||||
// about events on file descriptors.
|
||||
|
||||
@@ -49,7 +48,6 @@ namespace zmq
|
||||
// Called when timer expires.
|
||||
virtual void timer_event (int id_) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -32,8 +32,7 @@
|
||||
#include "io_thread.hpp"
|
||||
#include "err.hpp"
|
||||
|
||||
zmq::io_object_t::io_object_t (io_thread_t *io_thread_) :
|
||||
poller (NULL)
|
||||
zmq::io_object_t::io_object_t (io_thread_t *io_thread_) : poller (NULL)
|
||||
{
|
||||
if (io_thread_)
|
||||
plug (io_thread_);
|
||||
|
@@ -38,7 +38,6 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
class io_thread_t;
|
||||
|
||||
// Simple base class for objects that live in I/O threads.
|
||||
@@ -48,7 +47,6 @@ namespace zmq
|
||||
class io_object_t : public i_poll_events
|
||||
{
|
||||
public:
|
||||
|
||||
io_object_t (zmq::io_thread_t *io_thread_ = NULL);
|
||||
~io_object_t ();
|
||||
|
||||
@@ -58,7 +56,6 @@ namespace zmq
|
||||
void unplug ();
|
||||
|
||||
protected:
|
||||
|
||||
typedef poller_t::handle_t handle_t;
|
||||
|
||||
// Methods to access underlying poller object.
|
||||
@@ -77,13 +74,11 @@ namespace zmq
|
||||
void timer_event (int id_);
|
||||
|
||||
private:
|
||||
|
||||
poller_t *poller;
|
||||
|
||||
io_object_t (const io_object_t &);
|
||||
const io_object_t &operator= (const io_object_t &);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -40,7 +40,6 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
class ctx_t;
|
||||
|
||||
// Generic part of the I/O thread. Polling-mechanism-specific features
|
||||
@@ -49,7 +48,6 @@ namespace zmq
|
||||
class io_thread_t : public object_t, public i_poll_events
|
||||
{
|
||||
public:
|
||||
|
||||
io_thread_t (zmq::ctx_t *ctx_, uint32_t tid_);
|
||||
|
||||
// Clean-up. If the thread was started, it's necessary to call 'stop'
|
||||
@@ -80,7 +78,6 @@ namespace zmq
|
||||
int get_load ();
|
||||
|
||||
private:
|
||||
|
||||
// I/O thread accesses incoming commands via this mailbox.
|
||||
mailbox_t mailbox;
|
||||
|
||||
@@ -93,7 +90,6 @@ namespace zmq
|
||||
io_thread_t (const io_thread_t &);
|
||||
const io_thread_t &operator= (const io_thread_t &);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
36
src/ip.cpp
36
src/ip.cpp
@@ -138,30 +138,28 @@ int zmq::get_peer_ip_address (fd_t sockfd_, std::string &ip_addr_)
|
||||
#ifdef ZMQ_HAVE_WINDOWS
|
||||
if (rc == SOCKET_ERROR) {
|
||||
const int last_error = WSAGetLastError ();
|
||||
wsa_assert (last_error != WSANOTINITIALISED &&
|
||||
last_error != WSAEFAULT &&
|
||||
last_error != WSAEINPROGRESS &&
|
||||
last_error != WSAENOTSOCK);
|
||||
wsa_assert (last_error != WSANOTINITIALISED && last_error != WSAEFAULT
|
||||
&& last_error != WSAEINPROGRESS
|
||||
&& last_error != WSAENOTSOCK);
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
if (rc == -1) {
|
||||
errno_assert (errno != EBADF &&
|
||||
errno != EFAULT &&
|
||||
errno != ENOTSOCK);
|
||||
errno_assert (errno != EBADF && errno != EFAULT && errno != ENOTSOCK);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
char host[NI_MAXHOST];
|
||||
rc = getnameinfo ((struct sockaddr*) &ss, addrlen, host, sizeof host,
|
||||
NULL, 0, NI_NUMERICHOST);
|
||||
rc = getnameinfo ((struct sockaddr *) &ss, addrlen, host, sizeof host, NULL,
|
||||
0, NI_NUMERICHOST);
|
||||
if (rc != 0)
|
||||
return 0;
|
||||
|
||||
ip_addr_ = host;
|
||||
|
||||
union {
|
||||
union
|
||||
{
|
||||
struct sockaddr sa;
|
||||
struct sockaddr_storage sa_stor;
|
||||
} u;
|
||||
@@ -172,7 +170,9 @@ int zmq::get_peer_ip_address (fd_t sockfd_, std::string &ip_addr_)
|
||||
|
||||
void zmq::set_ip_type_of_service (fd_t s_, int iptos)
|
||||
{
|
||||
int rc = setsockopt(s_, IPPROTO_IP, IP_TOS, reinterpret_cast<const char*>(&iptos), sizeof(iptos));
|
||||
int rc =
|
||||
setsockopt (s_, IPPROTO_IP, IP_TOS,
|
||||
reinterpret_cast<const char *> (&iptos), sizeof (iptos));
|
||||
|
||||
#ifdef ZMQ_HAVE_WINDOWS
|
||||
wsa_assert (rc != SOCKET_ERROR);
|
||||
@@ -182,18 +182,13 @@ void zmq::set_ip_type_of_service (fd_t s_, int iptos)
|
||||
|
||||
// Windows and Hurd do not support IPV6_TCLASS
|
||||
#if !defined(ZMQ_HAVE_WINDOWS) && defined(IPV6_TCLASS)
|
||||
rc = setsockopt(
|
||||
s_,
|
||||
IPPROTO_IPV6,
|
||||
IPV6_TCLASS,
|
||||
reinterpret_cast<const char*>(&iptos),
|
||||
sizeof(iptos));
|
||||
rc = setsockopt (s_, IPPROTO_IPV6, IPV6_TCLASS,
|
||||
reinterpret_cast<const char *> (&iptos), sizeof (iptos));
|
||||
|
||||
// If IPv6 is not enabled ENOPROTOOPT will be returned on Linux and
|
||||
// EINVAL on OSX
|
||||
if (rc == -1) {
|
||||
errno_assert (errno == ENOPROTOOPT ||
|
||||
errno == EINVAL);
|
||||
errno_assert (errno == ENOPROTOOPT || errno == EINVAL);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -221,7 +216,8 @@ int zmq::set_nosigpipe (fd_t s_)
|
||||
void zmq::bind_to_device (fd_t s_, std::string &bound_device_)
|
||||
{
|
||||
#ifdef ZMQ_HAVE_SO_BINDTODEVICE
|
||||
int rc = setsockopt(s_, SOL_SOCKET, SO_BINDTODEVICE, bound_device_.c_str (), bound_device_.length ());
|
||||
int rc = setsockopt (s_, SOL_SOCKET, SO_BINDTODEVICE,
|
||||
bound_device_.c_str (), bound_device_.length ());
|
||||
|
||||
#ifdef ZMQ_HAVE_WINDOWS
|
||||
wsa_assert (rc != SOCKET_ERROR);
|
||||
|
@@ -35,7 +35,6 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
// Same as socket(2), but allows for transparent tweaking the options.
|
||||
fd_t open_socket (int domain_, int type_, int protocol_);
|
||||
|
||||
@@ -58,7 +57,6 @@ namespace zmq
|
||||
|
||||
// Binds the underlying socket to the given device, eg. VRF or interface
|
||||
void bind_to_device (fd_t s_, std::string &bound_device_);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -99,7 +99,8 @@ const sockaddr *zmq::ipc_address_t::addr () const
|
||||
socklen_t zmq::ipc_address_t::addrlen () const
|
||||
{
|
||||
if (!address.sun_path[0] && address.sun_path[1])
|
||||
return (socklen_t) strlen (address.sun_path + 1) + sizeof (sa_family_t) + 1;
|
||||
return (socklen_t) strlen (address.sun_path + 1) + sizeof (sa_family_t)
|
||||
+ 1;
|
||||
return (socklen_t) sizeof address;
|
||||
}
|
||||
|
||||
|
@@ -39,11 +39,9 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
class ipc_address_t
|
||||
{
|
||||
public:
|
||||
|
||||
ipc_address_t ();
|
||||
ipc_address_t (const sockaddr *sa, socklen_t sa_len);
|
||||
~ipc_address_t ();
|
||||
@@ -58,17 +56,13 @@ namespace zmq
|
||||
socklen_t addrlen () const;
|
||||
|
||||
private:
|
||||
|
||||
struct sockaddr_un address;
|
||||
|
||||
ipc_address_t (const ipc_address_t &);
|
||||
const ipc_address_t &operator= (const ipc_address_t &);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
@@ -50,8 +50,10 @@
|
||||
#include <sys/un.h>
|
||||
|
||||
zmq::ipc_connecter_t::ipc_connecter_t (class io_thread_t *io_thread_,
|
||||
class session_base_t *session_, const options_t &options_,
|
||||
const address_t *addr_, bool delayed_start_) :
|
||||
class session_base_t *session_,
|
||||
const options_t &options_,
|
||||
const address_t *addr_,
|
||||
bool delayed_start_) :
|
||||
own_t (io_thread_, options_),
|
||||
io_object_t (io_thread_),
|
||||
addr (addr_),
|
||||
@@ -122,8 +124,8 @@ void zmq::ipc_connecter_t::out_event ()
|
||||
return;
|
||||
}
|
||||
// Create the engine object for this connection.
|
||||
stream_engine_t *engine = new (std::nothrow)
|
||||
stream_engine_t (fd, options, endpoint);
|
||||
stream_engine_t *engine =
|
||||
new (std::nothrow) stream_engine_t (fd, options, endpoint);
|
||||
alloc_assert (engine);
|
||||
|
||||
// Attach the engine to the corresponding session object.
|
||||
@@ -155,8 +157,7 @@ void zmq::ipc_connecter_t::start_connecting ()
|
||||
}
|
||||
|
||||
// Connection establishment may be delayed. Poll for its completion.
|
||||
else
|
||||
if (rc == -1 && errno == EINPROGRESS) {
|
||||
else if (rc == -1 && errno == EINPROGRESS) {
|
||||
handle = add_fd (s);
|
||||
handle_valid = true;
|
||||
set_pollout (handle);
|
||||
@@ -182,14 +183,13 @@ void zmq::ipc_connecter_t::add_reconnect_timer()
|
||||
int zmq::ipc_connecter_t::get_new_reconnect_ivl ()
|
||||
{
|
||||
// The new interval is the current interval + random value.
|
||||
int this_interval = current_reconnect_ivl +
|
||||
(generate_random () % options.reconnect_ivl);
|
||||
int this_interval =
|
||||
current_reconnect_ivl + (generate_random () % options.reconnect_ivl);
|
||||
|
||||
// Only change the current reconnect interval if the maximum reconnect
|
||||
// interval was set and if it's larger than the reconnect interval.
|
||||
if (options.reconnect_ivl_max > 0 &&
|
||||
options.reconnect_ivl_max > options.reconnect_ivl) {
|
||||
|
||||
if (options.reconnect_ivl_max > 0
|
||||
&& options.reconnect_ivl_max > options.reconnect_ivl) {
|
||||
// Calculate the next interval
|
||||
current_reconnect_ivl = current_reconnect_ivl * 2;
|
||||
if (current_reconnect_ivl >= options.reconnect_ivl_max) {
|
||||
@@ -212,8 +212,7 @@ int zmq::ipc_connecter_t::open ()
|
||||
unblock_socket (s);
|
||||
|
||||
// Connect to the remote peer.
|
||||
int rc = ::connect (
|
||||
s, addr->resolved.ipc_addr->addr (),
|
||||
int rc = ::connect (s, addr->resolved.ipc_addr->addr (),
|
||||
addr->resolved.ipc_addr->addrlen ());
|
||||
|
||||
// Connect was successful immediately.
|
||||
@@ -258,13 +257,12 @@ zmq::fd_t zmq::ipc_connecter_t::connect ()
|
||||
err = errno;
|
||||
}
|
||||
if (err != 0) {
|
||||
|
||||
// Assert if the error was caused by 0MQ bug.
|
||||
// Networking problems are OK. No need to assert.
|
||||
errno = err;
|
||||
errno_assert (errno == ECONNREFUSED || errno == ECONNRESET ||
|
||||
errno == ETIMEDOUT || errno == EHOSTUNREACH ||
|
||||
errno == ENETUNREACH || errno == ENETDOWN);
|
||||
errno_assert (errno == ECONNREFUSED || errno == ECONNRESET
|
||||
|| errno == ETIMEDOUT || errno == EHOSTUNREACH
|
||||
|| errno == ENETUNREACH || errno == ENETDOWN);
|
||||
|
||||
return retired_fd;
|
||||
}
|
||||
@@ -275,4 +273,3 @@ zmq::fd_t zmq::ipc_connecter_t::connect ()
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -39,7 +39,6 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
class io_thread_t;
|
||||
class session_base_t;
|
||||
struct address_t;
|
||||
@@ -47,18 +46,21 @@ namespace zmq
|
||||
class ipc_connecter_t : public own_t, public io_object_t
|
||||
{
|
||||
public:
|
||||
|
||||
// If 'delayed_start' is true connecter first waits for a while,
|
||||
// then starts connection process.
|
||||
ipc_connecter_t (zmq::io_thread_t *io_thread_,
|
||||
zmq::session_base_t *session_, const options_t &options_,
|
||||
const address_t *addr_, bool delayed_start_);
|
||||
zmq::session_base_t *session_,
|
||||
const options_t &options_,
|
||||
const address_t *addr_,
|
||||
bool delayed_start_);
|
||||
~ipc_connecter_t ();
|
||||
|
||||
private:
|
||||
|
||||
// ID of the timer used to delay the reconnection.
|
||||
enum {reconnect_timer_id = 1};
|
||||
enum
|
||||
{
|
||||
reconnect_timer_id = 1
|
||||
};
|
||||
|
||||
// Handlers for incoming commands.
|
||||
void process_plug ();
|
||||
@@ -126,10 +128,8 @@ namespace zmq
|
||||
ipc_connecter_t (const ipc_connecter_t &);
|
||||
const ipc_connecter_t &operator= (const ipc_connecter_t &);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -65,9 +65,7 @@
|
||||
#endif
|
||||
|
||||
const char *zmq::ipc_listener_t::tmp_env_vars[] = {
|
||||
"TMPDIR",
|
||||
"TEMPDIR",
|
||||
"TMP",
|
||||
"TMPDIR", "TEMPDIR", "TMP",
|
||||
0 // Sentinel
|
||||
};
|
||||
|
||||
@@ -84,7 +82,8 @@ int zmq::ipc_listener_t::create_wildcard_address(std::string& path_,
|
||||
struct stat statbuf;
|
||||
|
||||
// Confirm it is actually a directory before trying to use
|
||||
if ( tmpdir != 0 && ::stat(tmpdir, &statbuf) == 0 && S_ISDIR(statbuf.st_mode) ) {
|
||||
if (tmpdir != 0 && ::stat (tmpdir, &statbuf) == 0
|
||||
&& S_ISDIR (statbuf.st_mode)) {
|
||||
tmp_path.assign (tmpdir);
|
||||
if (*(tmp_path.rbegin ()) != '/') {
|
||||
tmp_path.push_back ('/');
|
||||
@@ -131,7 +130,8 @@ int zmq::ipc_listener_t::create_wildcard_address(std::string& path_,
|
||||
}
|
||||
|
||||
zmq::ipc_listener_t::ipc_listener_t (io_thread_t *io_thread_,
|
||||
socket_base_t *socket_, const options_t &options_) :
|
||||
socket_base_t *socket_,
|
||||
const options_t &options_) :
|
||||
own_t (io_thread_, options_),
|
||||
io_object_t (io_thread_),
|
||||
has_file (false),
|
||||
@@ -171,8 +171,8 @@ void zmq::ipc_listener_t::in_event ()
|
||||
}
|
||||
|
||||
// Create the engine object for this connection.
|
||||
stream_engine_t *engine = new (std::nothrow)
|
||||
stream_engine_t (fd, options, endpoint);
|
||||
stream_engine_t *engine =
|
||||
new (std::nothrow) stream_engine_t (fd, options, endpoint);
|
||||
alloc_assert (engine);
|
||||
|
||||
// Choose I/O thread to run connecter in. Given that we are already
|
||||
@@ -181,8 +181,8 @@ void zmq::ipc_listener_t::in_event ()
|
||||
zmq_assert (io_thread);
|
||||
|
||||
// Create and launch a session object.
|
||||
session_base_t *session = session_base_t::create (io_thread, false, socket,
|
||||
options, NULL);
|
||||
session_base_t *session =
|
||||
session_base_t::create (io_thread, false, socket, options, NULL);
|
||||
errno_assert (session);
|
||||
session->inc_seqnum ();
|
||||
launch_child (session);
|
||||
@@ -317,9 +317,9 @@ int zmq::ipc_listener_t::close ()
|
||||
|
||||
bool zmq::ipc_listener_t::filter (fd_t sock)
|
||||
{
|
||||
if (options.ipc_uid_accept_filters.empty () &&
|
||||
options.ipc_pid_accept_filters.empty () &&
|
||||
options.ipc_gid_accept_filters.empty ())
|
||||
if (options.ipc_uid_accept_filters.empty ()
|
||||
&& options.ipc_pid_accept_filters.empty ()
|
||||
&& options.ipc_gid_accept_filters.empty ())
|
||||
return true;
|
||||
|
||||
struct ucred cred;
|
||||
@@ -327,9 +327,12 @@ bool zmq::ipc_listener_t::filter (fd_t sock)
|
||||
|
||||
if (getsockopt (sock, SOL_SOCKET, SO_PEERCRED, &cred, &size))
|
||||
return false;
|
||||
if (options.ipc_uid_accept_filters.find (cred.uid) != options.ipc_uid_accept_filters.end () ||
|
||||
options.ipc_gid_accept_filters.find (cred.gid) != options.ipc_gid_accept_filters.end () ||
|
||||
options.ipc_pid_accept_filters.find (cred.pid) != options.ipc_pid_accept_filters.end ())
|
||||
if (options.ipc_uid_accept_filters.find (cred.uid)
|
||||
!= options.ipc_uid_accept_filters.end ()
|
||||
|| options.ipc_gid_accept_filters.find (cred.gid)
|
||||
!= options.ipc_gid_accept_filters.end ()
|
||||
|| options.ipc_pid_accept_filters.find (cred.pid)
|
||||
!= options.ipc_pid_accept_filters.end ())
|
||||
return true;
|
||||
|
||||
struct passwd *pw;
|
||||
@@ -337,7 +340,8 @@ bool zmq::ipc_listener_t::filter (fd_t sock)
|
||||
|
||||
if (!(pw = getpwuid (cred.uid)))
|
||||
return false;
|
||||
for (options_t::ipc_gid_accept_filters_t::const_iterator it = options.ipc_gid_accept_filters.begin ();
|
||||
for (options_t::ipc_gid_accept_filters_t::const_iterator it =
|
||||
options.ipc_gid_accept_filters.begin ();
|
||||
it != options.ipc_gid_accept_filters.end (); it++) {
|
||||
if (!(gr = getgrgid (*it)))
|
||||
continue;
|
||||
@@ -353,8 +357,8 @@ bool zmq::ipc_listener_t::filter (fd_t sock)
|
||||
|
||||
bool zmq::ipc_listener_t::filter (fd_t sock)
|
||||
{
|
||||
if (options.ipc_uid_accept_filters.empty () &&
|
||||
options.ipc_gid_accept_filters.empty ())
|
||||
if (options.ipc_uid_accept_filters.empty ()
|
||||
&& options.ipc_gid_accept_filters.empty ())
|
||||
return true;
|
||||
|
||||
struct xucred cred;
|
||||
@@ -364,10 +368,12 @@ bool zmq::ipc_listener_t::filter (fd_t sock)
|
||||
return false;
|
||||
if (cred.cr_version != XUCRED_VERSION)
|
||||
return false;
|
||||
if (options.ipc_uid_accept_filters.find (cred.cr_uid) != options.ipc_uid_accept_filters.end ())
|
||||
if (options.ipc_uid_accept_filters.find (cred.cr_uid)
|
||||
!= options.ipc_uid_accept_filters.end ())
|
||||
return true;
|
||||
for (int i = 0; i < cred.cr_ngroups; i++) {
|
||||
if (options.ipc_gid_accept_filters.find (cred.cr_groups[i]) != options.ipc_gid_accept_filters.end ())
|
||||
if (options.ipc_gid_accept_filters.find (cred.cr_groups[i])
|
||||
!= options.ipc_gid_accept_filters.end ())
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -388,13 +394,14 @@ zmq::fd_t zmq::ipc_listener_t::accept ()
|
||||
fd_t sock = ::accept (s, NULL, NULL);
|
||||
#endif
|
||||
if (sock == -1) {
|
||||
errno_assert (errno == EAGAIN || errno == EWOULDBLOCK ||
|
||||
errno == EINTR || errno == ECONNABORTED || errno == EPROTO ||
|
||||
errno == ENFILE);
|
||||
errno_assert (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR
|
||||
|| errno == ECONNABORTED || errno == EPROTO
|
||||
|| errno == ENFILE);
|
||||
return retired_fd;
|
||||
}
|
||||
|
||||
#if (!defined ZMQ_HAVE_SOCK_CLOEXEC || !defined HAVE_ACCEPT4) && defined FD_CLOEXEC
|
||||
#if (!defined ZMQ_HAVE_SOCK_CLOEXEC || !defined HAVE_ACCEPT4) \
|
||||
&& defined FD_CLOEXEC
|
||||
// Race condition can cause socket not to be closed (if fork happens
|
||||
// between accept and this point).
|
||||
int rc = fcntl (sock, F_SETFD, FD_CLOEXEC);
|
||||
|
@@ -41,16 +41,15 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
class io_thread_t;
|
||||
class socket_base_t;
|
||||
|
||||
class ipc_listener_t : public own_t, public io_object_t
|
||||
{
|
||||
public:
|
||||
|
||||
ipc_listener_t (zmq::io_thread_t *io_thread_,
|
||||
zmq::socket_base_t *socket_, const options_t &options_);
|
||||
zmq::socket_base_t *socket_,
|
||||
const options_t &options_);
|
||||
~ipc_listener_t ();
|
||||
|
||||
// Set address to listen on.
|
||||
@@ -60,7 +59,6 @@ namespace zmq
|
||||
int get_address (std::string &addr_);
|
||||
|
||||
private:
|
||||
|
||||
// Handlers for incoming commands.
|
||||
void process_plug ();
|
||||
void process_term (int linger_);
|
||||
@@ -72,8 +70,7 @@ namespace zmq
|
||||
int close ();
|
||||
|
||||
// Create wildcard path address
|
||||
static int create_wildcard_address(std::string& path_,
|
||||
std::string& file_);
|
||||
static int create_wildcard_address (std::string &path_, std::string &file_);
|
||||
|
||||
// Filter new connections if the OS provides a mechanism to get
|
||||
// the credentials of the peer process. Called from accept().
|
||||
@@ -114,10 +111,8 @@ namespace zmq
|
||||
ipc_listener_t (const ipc_listener_t &);
|
||||
const ipc_listener_t &operator= (const ipc_listener_t &);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -54,9 +54,7 @@
|
||||
#define kevent_udata_t void *
|
||||
#endif
|
||||
|
||||
zmq::kqueue_t::kqueue_t (const zmq::ctx_t &ctx_) :
|
||||
ctx(ctx_),
|
||||
stopping (false)
|
||||
zmq::kqueue_t::kqueue_t (const zmq::ctx_t &ctx_) : ctx (ctx_), stopping (false)
|
||||
{
|
||||
// Create event queue
|
||||
kqueue_fd = kqueue ();
|
||||
@@ -173,7 +171,6 @@ int zmq::kqueue_t::max_fds ()
|
||||
void zmq::kqueue_t::loop ()
|
||||
{
|
||||
while (!stopping) {
|
||||
|
||||
// Execute any due timers.
|
||||
int timeout = (int) execute_timers ();
|
||||
|
||||
@@ -212,7 +209,8 @@ void zmq::kqueue_t::loop ()
|
||||
}
|
||||
|
||||
// Destroy retired event sources.
|
||||
for (retired_t::iterator it = retired.begin (); it != retired.end (); ++it) {
|
||||
for (retired_t::iterator it = retired.begin (); it != retired.end ();
|
||||
++it) {
|
||||
LIBZMQ_DELETE (*it);
|
||||
}
|
||||
retired.clear ();
|
||||
|
@@ -44,7 +44,6 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
struct i_poll_events;
|
||||
|
||||
// Implements socket polling mechanism using the BSD-specific
|
||||
@@ -53,7 +52,6 @@ namespace zmq
|
||||
class kqueue_t : public poller_base_t
|
||||
{
|
||||
public:
|
||||
|
||||
typedef void *handle_t;
|
||||
|
||||
kqueue_t (const ctx_t &ctx_);
|
||||
@@ -72,7 +70,6 @@ namespace zmq
|
||||
static int max_fds ();
|
||||
|
||||
private:
|
||||
|
||||
// Main worker thread routine.
|
||||
static void worker_routine (void *arg_);
|
||||
|
||||
@@ -119,7 +116,6 @@ namespace zmq
|
||||
};
|
||||
|
||||
typedef kqueue_t poller_t;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
14
src/lb.cpp
14
src/lb.cpp
@@ -33,11 +33,7 @@
|
||||
#include "err.hpp"
|
||||
#include "msg.hpp"
|
||||
|
||||
zmq::lb_t::lb_t () :
|
||||
active (0),
|
||||
current (0),
|
||||
more (false),
|
||||
dropping (false)
|
||||
zmq::lb_t::lb_t () : active (0), current (0), more (false), dropping (false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -89,7 +85,6 @@ int zmq::lb_t::sendpipe (msg_t *msg_, pipe_t **pipe_)
|
||||
// Drop the message if required. If we are at the end of the message
|
||||
// switch back to non-dropping mode.
|
||||
if (dropping) {
|
||||
|
||||
more = msg_->flags () & msg_t::more ? true : false;
|
||||
dropping = more;
|
||||
|
||||
@@ -101,8 +96,7 @@ int zmq::lb_t::sendpipe (msg_t *msg_, pipe_t **pipe_)
|
||||
}
|
||||
|
||||
while (active > 0) {
|
||||
if (pipes [current]->write (msg_))
|
||||
{
|
||||
if (pipes[current]->write (msg_)) {
|
||||
if (pipe_)
|
||||
*pipe_ = pipes[current];
|
||||
break;
|
||||
@@ -111,8 +105,7 @@ int zmq::lb_t::sendpipe (msg_t *msg_, pipe_t **pipe_)
|
||||
// If send fails for multi-part msg rollback other
|
||||
// parts sent earlier and return EAGAIN.
|
||||
// Application should handle this as suitable
|
||||
if (more)
|
||||
{
|
||||
if (more) {
|
||||
pipes[current]->rollback ();
|
||||
more = 0;
|
||||
errno = EAGAIN;
|
||||
@@ -157,7 +150,6 @@ bool zmq::lb_t::has_out ()
|
||||
return true;
|
||||
|
||||
while (active > 0) {
|
||||
|
||||
// Check whether a pipe has room for another message.
|
||||
if (pipes[current]->check_write ())
|
||||
return true;
|
||||
|
@@ -35,14 +35,12 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
// This class manages a set of outbound pipes. On send it load balances
|
||||
// messages fairly among the pipes.
|
||||
|
||||
class lb_t
|
||||
{
|
||||
public:
|
||||
|
||||
lb_t ();
|
||||
~lb_t ();
|
||||
|
||||
@@ -61,7 +59,6 @@ namespace zmq
|
||||
bool has_out ();
|
||||
|
||||
private:
|
||||
|
||||
// List of outbound pipes.
|
||||
typedef array_t<pipe_t, 2> pipes_t;
|
||||
pipes_t pipes;
|
||||
@@ -82,7 +79,6 @@ namespace zmq
|
||||
lb_t (const lb_t &);
|
||||
const lb_t &operator= (const lb_t &);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -4,7 +4,8 @@
|
||||
/******************************************************************************/
|
||||
|
||||
#define LIBZMQ_UNUSED(object) (void) object
|
||||
#define LIBZMQ_DELETE(p_object) {\
|
||||
#define LIBZMQ_DELETE(p_object) \
|
||||
{ \
|
||||
delete p_object; \
|
||||
p_object = 0; \
|
||||
}
|
||||
|
@@ -42,11 +42,9 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
class mailbox_t : public i_mailbox
|
||||
{
|
||||
public:
|
||||
|
||||
mailbox_t ();
|
||||
~mailbox_t ();
|
||||
|
||||
@@ -64,7 +62,6 @@ namespace zmq
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
// The pipe to store actual commands.
|
||||
typedef ypipe_t<command_t, command_pipe_granularity> cpipe_t;
|
||||
cpipe_t cpipe;
|
||||
@@ -86,7 +83,6 @@ namespace zmq
|
||||
mailbox_t (const mailbox_t &);
|
||||
const mailbox_t &operator= (const mailbox_t &);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -32,8 +32,7 @@
|
||||
#include "clock.hpp"
|
||||
#include "err.hpp"
|
||||
|
||||
zmq::mailbox_safe_t::mailbox_safe_t (mutex_t* sync_) :
|
||||
sync (sync_)
|
||||
zmq::mailbox_safe_t::mailbox_safe_t (mutex_t *sync_) : sync (sync_)
|
||||
{
|
||||
// Get the pipe into passive state. That way, if the users starts by
|
||||
// polling on the associated file descriptor it will get woken up when
|
||||
@@ -84,7 +83,8 @@ void zmq::mailbox_safe_t::send (const command_t &cmd_)
|
||||
|
||||
if (!ok) {
|
||||
cond_var.broadcast ();
|
||||
for (std::vector<signaler_t*>::iterator it = signalers.begin(); it != signalers.end(); ++it){
|
||||
for (std::vector<signaler_t *>::iterator it = signalers.begin ();
|
||||
it != signalers.end (); ++it) {
|
||||
(*it)->send ();
|
||||
}
|
||||
}
|
||||
|
@@ -44,11 +44,9 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
class mailbox_safe_t : public i_mailbox
|
||||
{
|
||||
public:
|
||||
|
||||
mailbox_safe_t (mutex_t *sync_);
|
||||
~mailbox_safe_t ();
|
||||
|
||||
@@ -71,7 +69,6 @@ namespace zmq
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
// The pipe to store actual commands.
|
||||
typedef ypipe_t<command_t, command_pipe_granularity> cpipe_t;
|
||||
cpipe_t cpipe;
|
||||
@@ -88,7 +85,6 @@ namespace zmq
|
||||
mailbox_safe_t (const mailbox_safe_t &);
|
||||
const mailbox_safe_t &operator= (const mailbox_safe_t &);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -37,8 +37,7 @@
|
||||
#include "wire.hpp"
|
||||
#include "session_base.hpp"
|
||||
|
||||
zmq::mechanism_t::mechanism_t (const options_t &options_) :
|
||||
options (options_)
|
||||
zmq::mechanism_t::mechanism_t (const options_t &options_) : options (options_)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -73,12 +72,10 @@ const zmq::blob_t &zmq::mechanism_t::get_user_id () const
|
||||
|
||||
const char *zmq::mechanism_t::socket_type_string (int socket_type) const
|
||||
{
|
||||
static const char *names [] = {"PAIR", "PUB", "SUB", "REQ", "REP",
|
||||
"DEALER", "ROUTER", "PULL", "PUSH",
|
||||
"XPUB", "XSUB", "STREAM",
|
||||
"SERVER", "CLIENT",
|
||||
"RADIO", "DISH",
|
||||
"GATHER", "SCATTER", "DGRAM"};
|
||||
static const char *names[] = {
|
||||
"PAIR", "PUB", "SUB", "REQ", "REP", "DEALER", "ROUTER",
|
||||
"PULL", "PUSH", "XPUB", "XSUB", "STREAM", "SERVER", "CLIENT",
|
||||
"RADIO", "DISH", "GATHER", "SCATTER", "DGRAM"};
|
||||
zmq_assert (socket_type >= 0 && socket_type <= 18);
|
||||
return names[socket_type];
|
||||
}
|
||||
@@ -131,16 +128,15 @@ size_t zmq::mechanism_t::add_basic_properties (unsigned char *buf,
|
||||
|
||||
// Add socket type property
|
||||
const char *socket_type = socket_type_string (options.type);
|
||||
ptr += add_property (ptr, buf_capacity,
|
||||
ZMTP_PROPERTY_SOCKET_TYPE, socket_type,
|
||||
strlen (socket_type));
|
||||
ptr += add_property (ptr, buf_capacity, ZMTP_PROPERTY_SOCKET_TYPE,
|
||||
socket_type, strlen (socket_type));
|
||||
|
||||
// Add identity (aka routing id) property
|
||||
if (options.type == ZMQ_REQ || options.type == ZMQ_DEALER
|
||||
|| options.type == ZMQ_ROUTER)
|
||||
ptr += add_property (ptr, buf_capacity - (ptr - buf),
|
||||
ZMTP_PROPERTY_IDENTITY, options.routing_id,
|
||||
options.routing_id_size);
|
||||
ptr +=
|
||||
add_property (ptr, buf_capacity - (ptr - buf), ZMTP_PROPERTY_IDENTITY,
|
||||
options.routing_id, options.routing_id_size);
|
||||
|
||||
return ptr - buf;
|
||||
}
|
||||
@@ -151,8 +147,7 @@ size_t zmq::mechanism_t::basic_properties_len() const
|
||||
return property_len (ZMTP_PROPERTY_SOCKET_TYPE, strlen (socket_type))
|
||||
+ ((options.type == ZMQ_REQ || options.type == ZMQ_DEALER
|
||||
|| options.type == ZMQ_ROUTER)
|
||||
? property_len (ZMTP_PROPERTY_IDENTITY,
|
||||
options.routing_id_size)
|
||||
? property_len (ZMTP_PROPERTY_IDENTITY, options.routing_id_size)
|
||||
: 0);
|
||||
}
|
||||
|
||||
@@ -169,8 +164,8 @@ void zmq::mechanism_t::make_command_with_basic_properties (
|
||||
memcpy (ptr, prefix, prefix_len);
|
||||
ptr += prefix_len;
|
||||
|
||||
add_basic_properties (
|
||||
ptr, command_size - (ptr - (unsigned char *) msg_->data ()));
|
||||
add_basic_properties (ptr, command_size
|
||||
- (ptr - (unsigned char *) msg_->data ()));
|
||||
}
|
||||
|
||||
int zmq::mechanism_t::parse_metadata (const unsigned char *ptr_,
|
||||
@@ -204,15 +199,13 @@ int zmq::mechanism_t::parse_metadata (const unsigned char *ptr_,
|
||||
|
||||
if (name == ZMTP_PROPERTY_IDENTITY && options.recv_routing_id)
|
||||
set_peer_routing_id (value, value_length);
|
||||
else
|
||||
if (name == ZMTP_PROPERTY_SOCKET_TYPE) {
|
||||
else if (name == ZMTP_PROPERTY_SOCKET_TYPE) {
|
||||
const std::string socket_type ((char *) value, value_length);
|
||||
if (!check_socket_type (socket_type)) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
const int rc = property (name, value, value_length);
|
||||
if (rc == -1)
|
||||
return -1;
|
||||
@@ -232,7 +225,8 @@ int zmq::mechanism_t::parse_metadata (const unsigned char *ptr_,
|
||||
}
|
||||
|
||||
int zmq::mechanism_t::property (const std::string & /* name_ */,
|
||||
const void * /* value_ */, size_t /* length_ */)
|
||||
const void * /* value_ */,
|
||||
size_t /* length_ */)
|
||||
{
|
||||
// Default implementation does not check
|
||||
// property values and returns 0 to signal success.
|
||||
|
@@ -37,7 +37,6 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
class msg_t;
|
||||
class session_base_t;
|
||||
|
||||
@@ -47,8 +46,8 @@ namespace zmq
|
||||
class mechanism_t
|
||||
{
|
||||
public:
|
||||
|
||||
enum status_t {
|
||||
enum status_t
|
||||
{
|
||||
handshaking,
|
||||
ready,
|
||||
error
|
||||
@@ -82,16 +81,11 @@ namespace zmq
|
||||
|
||||
const blob_t &get_user_id () const;
|
||||
|
||||
const metadata_t::dict_t& get_zmtp_properties () {
|
||||
return zmtp_properties;
|
||||
}
|
||||
const metadata_t::dict_t &get_zmtp_properties () { return zmtp_properties; }
|
||||
|
||||
const metadata_t::dict_t& get_zap_properties () {
|
||||
return zap_properties;
|
||||
}
|
||||
const metadata_t::dict_t &get_zap_properties () { return zap_properties; }
|
||||
|
||||
protected:
|
||||
|
||||
// Only used to identify the socket for the Socket-Type
|
||||
// property in the wire protocol.
|
||||
const char *socket_type_string (int socket_type) const;
|
||||
@@ -101,8 +95,7 @@ namespace zmq
|
||||
const char *name,
|
||||
const void *value,
|
||||
size_t value_len);
|
||||
static size_t property_len (const char *name,
|
||||
size_t value_len);
|
||||
static size_t property_len (const char *name, size_t value_len);
|
||||
|
||||
size_t add_basic_properties (unsigned char *ptr, size_t ptr_capacity) const;
|
||||
size_t basic_properties_len () const;
|
||||
@@ -115,8 +108,9 @@ namespace zmq
|
||||
// Metadata consists of a list of properties consisting of
|
||||
// name and value as size-specified strings.
|
||||
// Returns 0 on success and -1 on error, in which case errno is set.
|
||||
int parse_metadata (
|
||||
const unsigned char *ptr_, size_t length, bool zap_flag = false);
|
||||
int parse_metadata (const unsigned char *ptr_,
|
||||
size_t length,
|
||||
bool zap_flag = false);
|
||||
|
||||
// This is called by parse_property method whenever it
|
||||
// parses a new property. The function should return 0
|
||||
@@ -125,8 +119,8 @@ namespace zmq
|
||||
// parsing remaining data.
|
||||
// Derived classes are supposed to override this
|
||||
// method to handle custom processing.
|
||||
virtual int property (const std::string& name_,
|
||||
const void *value_, size_t length_);
|
||||
virtual int
|
||||
property (const std::string &name_, const void *value_, size_t length_);
|
||||
|
||||
// Properties received from ZMTP peer.
|
||||
metadata_t::dict_t zmtp_properties;
|
||||
@@ -137,7 +131,6 @@ namespace zmq
|
||||
options_t options;
|
||||
|
||||
private:
|
||||
|
||||
blob_t routing_id;
|
||||
|
||||
blob_t user_id;
|
||||
@@ -146,7 +139,6 @@ namespace zmq
|
||||
// is compatible with a given socket type 'type_'.
|
||||
bool check_socket_type (const std::string &type_) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -37,7 +37,6 @@ zmq::mechanism_base_t::mechanism_base_t (session_base_t *const session_,
|
||||
mechanism_t (options_),
|
||||
session (session_)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int zmq::mechanism_base_t::check_basic_command_structure (msg_t *msg_)
|
||||
|
@@ -44,7 +44,8 @@ class mechanism_base_t : public mechanism_t
|
||||
|
||||
int check_basic_command_structure (msg_t *msg_);
|
||||
|
||||
void handle_error_reason (const char *error_reason, size_t error_reason_len);
|
||||
void handle_error_reason (const char *error_reason,
|
||||
size_t error_reason_len);
|
||||
|
||||
bool zap_required () const;
|
||||
};
|
||||
|
@@ -30,24 +30,20 @@
|
||||
#include "precompiled.hpp"
|
||||
#include "metadata.hpp"
|
||||
|
||||
zmq::metadata_t::metadata_t (const dict_t &dict) :
|
||||
ref_cnt (1),
|
||||
dict (dict)
|
||||
zmq::metadata_t::metadata_t (const dict_t &dict) : ref_cnt (1), dict (dict)
|
||||
{
|
||||
}
|
||||
|
||||
const char *zmq::metadata_t::get (const std::string &property) const
|
||||
{
|
||||
dict_t::const_iterator it = dict.find (property);
|
||||
if (it == dict.end())
|
||||
{
|
||||
if (it == dict.end ()) {
|
||||
/** \todo remove this when support for the deprecated name "Identity" is dropped */
|
||||
if (property == "Identity")
|
||||
return get (ZMQ_MSG_PROPERTY_ROUTING_ID);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
} else
|
||||
return it->second.c_str ();
|
||||
}
|
||||
|
||||
|
@@ -64,7 +64,6 @@ namespace zmq
|
||||
// Dictionary holding metadata.
|
||||
dict_t dict;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
74
src/msg.cpp
74
src/msg.cpp
@@ -43,37 +43,30 @@
|
||||
// Check whether the sizes of public representation of the message (zmq_msg_t)
|
||||
// and private representation of the message (zmq::msg_t) match.
|
||||
|
||||
typedef char zmq_msg_size_check
|
||||
[2 * ((sizeof (zmq::msg_t) == sizeof (zmq_msg_t)) != 0) - 1];
|
||||
typedef char
|
||||
zmq_msg_size_check[2 * ((sizeof (zmq::msg_t) == sizeof (zmq_msg_t)) != 0)
|
||||
- 1];
|
||||
|
||||
bool zmq::msg_t::check () const
|
||||
{
|
||||
return u.base.type >= type_min && u.base.type <= type_max;
|
||||
}
|
||||
|
||||
int zmq::msg_t::init (void* data_, size_t size_,
|
||||
msg_free_fn* ffn_, void* hint,
|
||||
content_t* content_)
|
||||
int zmq::msg_t::init (
|
||||
void *data_, size_t size_, msg_free_fn *ffn_, void *hint, content_t *content_)
|
||||
{
|
||||
if (size_ < max_vsm_size) {
|
||||
int const rc = init_size (size_);
|
||||
|
||||
if (rc != -1)
|
||||
{
|
||||
if (rc != -1) {
|
||||
memcpy (data (), data_, size_);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if(content_)
|
||||
{
|
||||
} else if (content_) {
|
||||
return init_external_storage (content_, data_, size_, ffn_, hint);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return init_data (data_, size_, ffn_, hint);
|
||||
}
|
||||
}
|
||||
@@ -98,8 +91,7 @@ int zmq::msg_t::init_size (size_t size_)
|
||||
u.vsm.size = (unsigned char) size_;
|
||||
u.vsm.group[0] = '\0';
|
||||
u.vsm.routing_id = 0;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
u.lmsg.metadata = NULL;
|
||||
u.lmsg.type = type_lmsg;
|
||||
u.lmsg.flags = 0;
|
||||
@@ -122,8 +114,11 @@ int zmq::msg_t::init_size (size_t size_)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int zmq::msg_t::init_external_storage(content_t* content_, void* data_, size_t size_,
|
||||
msg_free_fn *ffn_, void* hint_)
|
||||
int zmq::msg_t::init_external_storage (content_t *content_,
|
||||
void *data_,
|
||||
size_t size_,
|
||||
msg_free_fn *ffn_,
|
||||
void *hint_)
|
||||
{
|
||||
zmq_assert (NULL != data_);
|
||||
zmq_assert (NULL != content_);
|
||||
@@ -144,8 +139,10 @@ int zmq::msg_t::init_external_storage(content_t* content_, void* data_, size_t s
|
||||
return 0;
|
||||
}
|
||||
|
||||
int zmq::msg_t::init_data (void *data_, size_t size_,
|
||||
msg_free_fn *ffn_, void *hint_)
|
||||
int zmq::msg_t::init_data (void *data_,
|
||||
size_t size_,
|
||||
msg_free_fn *ffn_,
|
||||
void *hint_)
|
||||
{
|
||||
// If data is NULL and size is not 0, a segfault
|
||||
// would occur once the data is accessed
|
||||
@@ -160,8 +157,7 @@ int zmq::msg_t::init_data (void *data_, size_t size_,
|
||||
u.cmsg.size = size_;
|
||||
u.cmsg.group[0] = '\0';
|
||||
u.cmsg.routing_id = 0;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
u.lmsg.metadata = NULL;
|
||||
u.lmsg.type = type_lmsg;
|
||||
u.lmsg.flags = 0;
|
||||
@@ -180,7 +176,6 @@ int zmq::msg_t::init_data (void *data_, size_t size_,
|
||||
new (&u.lmsg.content->refcnt) zmq::atomic_counter_t ();
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int zmq::msg_t::init_delimiter ()
|
||||
@@ -222,12 +217,10 @@ int zmq::msg_t::close ()
|
||||
}
|
||||
|
||||
if (u.base.type == type_lmsg) {
|
||||
|
||||
// If the content is not shared, or if it is shared and the reference
|
||||
// count has dropped to zero, deallocate it.
|
||||
if (!(u.lmsg.flags & msg_t::shared) ||
|
||||
!u.lmsg.content->refcnt.sub (1)) {
|
||||
|
||||
if (!(u.lmsg.flags & msg_t::shared)
|
||||
|| !u.lmsg.content->refcnt.sub (1)) {
|
||||
// We used "placement new" operator to initialize the reference
|
||||
// counter so we call the destructor explicitly now.
|
||||
u.lmsg.content->refcnt.~atomic_counter_t ();
|
||||
@@ -239,15 +232,13 @@ int zmq::msg_t::close ()
|
||||
}
|
||||
}
|
||||
|
||||
if (is_zcmsg())
|
||||
{
|
||||
if (is_zcmsg ()) {
|
||||
zmq_assert (u.zclmsg.content->ffn);
|
||||
|
||||
// If the content is not shared, or if it is shared and the reference
|
||||
// count has dropped to zero, deallocate it.
|
||||
if (!(u.zclmsg.flags & msg_t::shared) ||
|
||||
!u.zclmsg.content->refcnt.sub (1)) {
|
||||
|
||||
if (!(u.zclmsg.flags & msg_t::shared)
|
||||
|| !u.zclmsg.content->refcnt.sub (1)) {
|
||||
// We used "placement new" operator to initialize the reference
|
||||
// counter so we call the destructor explicitly now.
|
||||
u.zclmsg.content->refcnt.~atomic_counter_t ();
|
||||
@@ -304,7 +295,6 @@ int zmq::msg_t::copy (msg_t &src_)
|
||||
return rc;
|
||||
|
||||
if (src_.u.base.type == type_lmsg) {
|
||||
|
||||
// One reference is added to shared messages. Non-shared messages
|
||||
// are turned into shared messages and reference count is set to 2.
|
||||
if (src_.u.lmsg.flags & msg_t::shared)
|
||||
@@ -316,7 +306,6 @@ int zmq::msg_t::copy (msg_t &src_)
|
||||
}
|
||||
|
||||
if (src_.is_zcmsg ()) {
|
||||
|
||||
// One reference is added to shared messages. Non-shared messages
|
||||
// are turned into shared messages and reference count is set to 2.
|
||||
if (src_.u.zclmsg.flags & msg_t::shared)
|
||||
@@ -332,7 +321,6 @@ int zmq::msg_t::copy (msg_t &src_)
|
||||
*this = src_;
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
void *zmq::msg_t::data ()
|
||||
@@ -488,7 +476,8 @@ bool zmq::msg_t::rm_refs (int refs_)
|
||||
return true;
|
||||
|
||||
// If there's only one reference close the message.
|
||||
if ( (u.base.type != type_zclmsg && u.base.type != type_lmsg) || !(u.base.flags & msg_t::shared)) {
|
||||
if ((u.base.type != type_zclmsg && u.base.type != type_lmsg)
|
||||
|| !(u.base.flags & msg_t::shared)) {
|
||||
close ();
|
||||
return false;
|
||||
}
|
||||
@@ -509,7 +498,8 @@ bool zmq::msg_t::rm_refs (int refs_)
|
||||
if (is_zcmsg () && !u.zclmsg.content->refcnt.sub (refs_)) {
|
||||
// storage for rfcnt is provided externally
|
||||
if (u.zclmsg.content->ffn) {
|
||||
u.zclmsg.content->ffn(u.zclmsg.content->data, u.zclmsg.content->hint);
|
||||
u.zclmsg.content->ffn (u.zclmsg.content->data,
|
||||
u.zclmsg.content->hint);
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -551,8 +541,7 @@ int zmq::msg_t::set_group (const char * group_)
|
||||
|
||||
int zmq::msg_t::set_group (const char *group_, size_t length_)
|
||||
{
|
||||
if (length_> ZMQ_GROUP_MAX_LENGTH)
|
||||
{
|
||||
if (length_ > ZMQ_GROUP_MAX_LENGTH) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
@@ -565,8 +554,7 @@ int zmq::msg_t::set_group (const char * group_, size_t length_)
|
||||
|
||||
zmq::atomic_counter_t *zmq::msg_t::refcnt ()
|
||||
{
|
||||
switch(u.base.type)
|
||||
{
|
||||
switch (u.base.type) {
|
||||
case type_lmsg:
|
||||
return &u.lmsg.content->refcnt;
|
||||
case type_zclmsg:
|
||||
|
95
src/msg.hpp
95
src/msg.hpp
@@ -42,21 +42,18 @@
|
||||
// Signature for free function to deallocate the message content.
|
||||
// Note that it has to be declared as "C" so that it is the same as
|
||||
// zmq_free_fn defined in zmq.h.
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
typedef void(msg_free_fn) (void *data, void *hint);
|
||||
}
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
// Note that this structure needs to be explicitly constructed
|
||||
// (init functions) and destructed (close function).
|
||||
|
||||
class msg_t
|
||||
{
|
||||
public:
|
||||
|
||||
// Shared message buffer. Message data are either allocated in one
|
||||
// continuous block along with this structure - thus avoiding one
|
||||
// malloc/free pair or they are stored in user-supplied memory.
|
||||
@@ -86,15 +83,19 @@ namespace zmq
|
||||
bool check () const;
|
||||
int init ();
|
||||
|
||||
int init (void* data, size_t size_,
|
||||
msg_free_fn* ffn_, void* hint,
|
||||
int init (void *data,
|
||||
size_t size_,
|
||||
msg_free_fn *ffn_,
|
||||
void *hint,
|
||||
content_t *content_ = NULL);
|
||||
|
||||
int init_size (size_t size_);
|
||||
int init_data (void *data_, size_t size_, msg_free_fn *ffn_,
|
||||
int init_data (void *data_, size_t size_, msg_free_fn *ffn_, void *hint_);
|
||||
int init_external_storage (content_t *content_,
|
||||
void *data_,
|
||||
size_t size_,
|
||||
msg_free_fn *ffn_,
|
||||
void *hint_);
|
||||
int init_external_storage(content_t* content_, void *data_, size_t size_,
|
||||
msg_free_fn *ffn_, void *hint_);
|
||||
int init_delimiter ();
|
||||
int init_join ();
|
||||
int init_leave ();
|
||||
@@ -134,11 +135,16 @@ namespace zmq
|
||||
|
||||
// Size in bytes of the largest message that is still copied around
|
||||
// rather than being reference-counted.
|
||||
enum { msg_t_size = 64 };
|
||||
enum { max_vsm_size = msg_t_size - (sizeof (metadata_t *) +
|
||||
3 +
|
||||
16 +
|
||||
sizeof (uint32_t))};
|
||||
enum
|
||||
{
|
||||
msg_t_size = 64
|
||||
};
|
||||
enum
|
||||
{
|
||||
max_vsm_size =
|
||||
msg_t_size - (sizeof (metadata_t *) + 3 + 16 + sizeof (uint32_t))
|
||||
};
|
||||
|
||||
private:
|
||||
zmq::atomic_counter_t *refcnt ();
|
||||
|
||||
@@ -171,19 +177,21 @@ namespace zmq
|
||||
// moved to the parent class (msg_t). This way we get tighter packing
|
||||
// of the data. Shared fields can be accessed via 'base' member of
|
||||
// the union.
|
||||
union {
|
||||
struct {
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
metadata_t *metadata;
|
||||
unsigned char unused [msg_t_size - (sizeof (metadata_t *) +
|
||||
2 +
|
||||
16 +
|
||||
sizeof (uint32_t))];
|
||||
unsigned char
|
||||
unused[msg_t_size
|
||||
- (sizeof (metadata_t *) + 2 + 16 + sizeof (uint32_t))];
|
||||
unsigned char type;
|
||||
unsigned char flags;
|
||||
char group[16];
|
||||
uint32_t routing_id;
|
||||
} base;
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
metadata_t *metadata;
|
||||
unsigned char data[max_vsm_size];
|
||||
unsigned char size;
|
||||
@@ -192,53 +200,50 @@ namespace zmq
|
||||
char group[16];
|
||||
uint32_t routing_id;
|
||||
} vsm;
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
metadata_t *metadata;
|
||||
content_t *content;
|
||||
unsigned char unused [msg_t_size - (sizeof (metadata_t *) +
|
||||
sizeof (content_t*) +
|
||||
2 +
|
||||
16 +
|
||||
sizeof (uint32_t))];
|
||||
unsigned char unused[msg_t_size
|
||||
- (sizeof (metadata_t *) + sizeof (content_t *)
|
||||
+ 2 + 16 + sizeof (uint32_t))];
|
||||
unsigned char type;
|
||||
unsigned char flags;
|
||||
char group[16];
|
||||
uint32_t routing_id;
|
||||
} lmsg;
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
metadata_t *metadata;
|
||||
content_t *content;
|
||||
unsigned char unused [msg_t_size - (sizeof (metadata_t *) +
|
||||
sizeof (content_t*) +
|
||||
2 +
|
||||
16 +
|
||||
sizeof (uint32_t))];
|
||||
unsigned char unused[msg_t_size
|
||||
- (sizeof (metadata_t *) + sizeof (content_t *)
|
||||
+ 2 + 16 + sizeof (uint32_t))];
|
||||
unsigned char type;
|
||||
unsigned char flags;
|
||||
char group[16];
|
||||
uint32_t routing_id;
|
||||
} zclmsg;
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
metadata_t *metadata;
|
||||
void *data;
|
||||
size_t size;
|
||||
unsigned char unused [msg_t_size - (sizeof (metadata_t *) +
|
||||
sizeof (void*) +
|
||||
sizeof (size_t) +
|
||||
2 +
|
||||
16 +
|
||||
sizeof (uint32_t))];
|
||||
unsigned char
|
||||
unused[msg_t_size
|
||||
- (sizeof (metadata_t *) + sizeof (void *)
|
||||
+ sizeof (size_t) + 2 + 16 + sizeof (uint32_t))];
|
||||
unsigned char type;
|
||||
unsigned char flags;
|
||||
char group[16];
|
||||
uint32_t routing_id;
|
||||
} cmsg;
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
metadata_t *metadata;
|
||||
unsigned char unused [msg_t_size - (sizeof (metadata_t *) +
|
||||
2 +
|
||||
16 +
|
||||
sizeof (uint32_t))];
|
||||
unsigned char
|
||||
unused[msg_t_size
|
||||
- (sizeof (metadata_t *) + 2 + 16 + sizeof (uint32_t))];
|
||||
unsigned char type;
|
||||
unsigned char flags;
|
||||
char group[16];
|
||||
|
104
src/mtrie.cpp
104
src/mtrie.cpp
@@ -38,11 +38,7 @@
|
||||
#include "macros.hpp"
|
||||
#include "mtrie.hpp"
|
||||
|
||||
zmq::mtrie_t::mtrie_t () :
|
||||
pipes (0),
|
||||
min (0),
|
||||
count (0),
|
||||
live_nodes (0)
|
||||
zmq::mtrie_t::mtrie_t () : pipes (0), min (0), count (0), live_nodes (0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -53,8 +49,7 @@ zmq::mtrie_t::~mtrie_t ()
|
||||
if (count == 1) {
|
||||
zmq_assert (next.node);
|
||||
LIBZMQ_DELETE (next.node);
|
||||
}
|
||||
else if (count > 1) {
|
||||
} else if (count > 1) {
|
||||
for (unsigned short i = 0; i != count; ++i) {
|
||||
LIBZMQ_DELETE (next.table[i]);
|
||||
}
|
||||
@@ -67,7 +62,8 @@ bool zmq::mtrie_t::add (unsigned char *prefix_, size_t size_, pipe_t *pipe_)
|
||||
return add_helper (prefix_, size_, pipe_);
|
||||
}
|
||||
|
||||
bool zmq::mtrie_t::add_helper (unsigned char *prefix_, size_t size_,
|
||||
bool zmq::mtrie_t::add_helper (unsigned char *prefix_,
|
||||
size_t size_,
|
||||
pipe_t *pipe_)
|
||||
{
|
||||
// We are at the node corresponding to the prefix. We are done.
|
||||
@@ -83,44 +79,37 @@ bool zmq::mtrie_t::add_helper (unsigned char *prefix_, size_t size_,
|
||||
|
||||
unsigned char c = *prefix_;
|
||||
if (c < min || c >= min + count) {
|
||||
|
||||
// The character is out of range of currently handled
|
||||
// characters. We have to extend the table.
|
||||
if (!count) {
|
||||
min = c;
|
||||
count = 1;
|
||||
next.node = NULL;
|
||||
}
|
||||
else
|
||||
if (count == 1) {
|
||||
} else if (count == 1) {
|
||||
unsigned char oldc = min;
|
||||
mtrie_t *oldp = next.node;
|
||||
count = (min < c ? c - min : min - c) + 1;
|
||||
next.table = (mtrie_t**)
|
||||
malloc (sizeof (mtrie_t*) * count);
|
||||
next.table = (mtrie_t **) malloc (sizeof (mtrie_t *) * count);
|
||||
alloc_assert (next.table);
|
||||
for (unsigned short i = 0; i != count; ++i)
|
||||
next.table[i] = 0;
|
||||
min = std::min (min, c);
|
||||
next.table[oldc - min] = oldp;
|
||||
}
|
||||
else
|
||||
if (min < c) {
|
||||
} else if (min < c) {
|
||||
// The new character is above the current character range.
|
||||
unsigned short old_count = count;
|
||||
count = c - min + 1;
|
||||
next.table = (mtrie_t**) realloc (next.table,
|
||||
sizeof (mtrie_t*) * count);
|
||||
next.table =
|
||||
(mtrie_t **) realloc (next.table, sizeof (mtrie_t *) * count);
|
||||
alloc_assert (next.table);
|
||||
for (unsigned short i = old_count; i != count; i++)
|
||||
next.table[i] = NULL;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// The new character is below the current character range.
|
||||
unsigned short old_count = count;
|
||||
count = (min + old_count) - c;
|
||||
next.table = (mtrie_t**) realloc (next.table,
|
||||
sizeof (mtrie_t*) * count);
|
||||
next.table =
|
||||
(mtrie_t **) realloc (next.table, sizeof (mtrie_t *) * count);
|
||||
alloc_assert (next.table);
|
||||
memmove (next.table + min - c, next.table,
|
||||
old_count * sizeof (mtrie_t *));
|
||||
@@ -138,8 +127,7 @@ bool zmq::mtrie_t::add_helper (unsigned char *prefix_, size_t size_,
|
||||
++live_nodes;
|
||||
}
|
||||
return next.node->add_helper (prefix_ + 1, size_ - 1, pipe_);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (!next.table[c - min]) {
|
||||
next.table[c - min] = new (std::nothrow) mtrie_t;
|
||||
alloc_assert (next.table[c - min]);
|
||||
@@ -151,18 +139,26 @@ bool zmq::mtrie_t::add_helper (unsigned char *prefix_, size_t size_,
|
||||
|
||||
|
||||
void zmq::mtrie_t::rm (pipe_t *pipe_,
|
||||
void (*func_) (unsigned char *data_, size_t size_, void *arg_),
|
||||
void *arg_, bool call_on_uniq_)
|
||||
void (*func_) (unsigned char *data_,
|
||||
size_t size_,
|
||||
void *arg_),
|
||||
void *arg_,
|
||||
bool call_on_uniq_)
|
||||
{
|
||||
unsigned char *buff = NULL;
|
||||
rm_helper (pipe_, &buff, 0, 0, func_, arg_, call_on_uniq_);
|
||||
free (buff);
|
||||
}
|
||||
|
||||
void zmq::mtrie_t::rm_helper (pipe_t *pipe_, unsigned char **buff_,
|
||||
size_t buffsize_, size_t maxbuffsize_,
|
||||
void (*func_) (unsigned char *data_, size_t size_, void *arg_),
|
||||
void *arg_, bool call_on_uniq_)
|
||||
void zmq::mtrie_t::rm_helper (pipe_t *pipe_,
|
||||
unsigned char **buff_,
|
||||
size_t buffsize_,
|
||||
size_t maxbuffsize_,
|
||||
void (*func_) (unsigned char *data_,
|
||||
size_t size_,
|
||||
void *arg_),
|
||||
void *arg_,
|
||||
bool call_on_uniq_)
|
||||
{
|
||||
// Remove the subscription from this node.
|
||||
if (pipes && pipes->erase (pipe_)) {
|
||||
@@ -190,8 +186,8 @@ void zmq::mtrie_t::rm_helper (pipe_t *pipe_, unsigned char **buff_,
|
||||
if (count == 1) {
|
||||
(*buff_)[buffsize_] = min;
|
||||
buffsize_++;
|
||||
next.node->rm_helper (pipe_, buff_, buffsize_, maxbuffsize_,
|
||||
func_, arg_, call_on_uniq_);
|
||||
next.node->rm_helper (pipe_, buff_, buffsize_, maxbuffsize_, func_,
|
||||
arg_, call_on_uniq_);
|
||||
|
||||
// Prune the node if it was made redundant by the removal
|
||||
if (next.node->is_redundant ()) {
|
||||
@@ -212,8 +208,8 @@ void zmq::mtrie_t::rm_helper (pipe_t *pipe_, unsigned char **buff_,
|
||||
for (unsigned short c = 0; c != count; c++) {
|
||||
(*buff_)[buffsize_] = min + c;
|
||||
if (next.table[c]) {
|
||||
next.table [c]->rm_helper (pipe_, buff_, buffsize_ + 1,
|
||||
maxbuffsize_, func_, arg_, call_on_uniq_);
|
||||
next.table[c]->rm_helper (pipe_, buff_, buffsize_ + 1, maxbuffsize_,
|
||||
func_, arg_, call_on_uniq_);
|
||||
|
||||
// Prune redundant nodes from the mtrie
|
||||
if (next.table[c]->is_redundant ()) {
|
||||
@@ -221,8 +217,7 @@ void zmq::mtrie_t::rm_helper (pipe_t *pipe_, unsigned char **buff_,
|
||||
|
||||
zmq_assert (live_nodes > 0);
|
||||
--live_nodes;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// The node is not redundant, so it's a candidate for being
|
||||
// the new min/max node.
|
||||
//
|
||||
@@ -247,8 +242,7 @@ void zmq::mtrie_t::rm_helper (pipe_t *pipe_, unsigned char **buff_,
|
||||
count = 0;
|
||||
}
|
||||
// Compact the node table if possible
|
||||
else
|
||||
if (live_nodes == 1) {
|
||||
else if (live_nodes == 1) {
|
||||
// If there's only one live node in the table we can
|
||||
// switch to using the more compact single-node
|
||||
// representation
|
||||
@@ -260,9 +254,7 @@ void zmq::mtrie_t::rm_helper (pipe_t *pipe_, unsigned char **buff_,
|
||||
next.node = node;
|
||||
count = 1;
|
||||
min = new_min;
|
||||
}
|
||||
else
|
||||
if (new_min > min || new_max < min + count - 1) {
|
||||
} else if (new_min > min || new_max < min + count - 1) {
|
||||
zmq_assert (new_max - new_min + 1 > 1);
|
||||
|
||||
mtrie_t **old_table = next.table;
|
||||
@@ -288,7 +280,8 @@ bool zmq::mtrie_t::rm (unsigned char *prefix_, size_t size_, pipe_t *pipe_)
|
||||
return rm_helper (prefix_, size_, pipe_);
|
||||
}
|
||||
|
||||
bool zmq::mtrie_t::rm_helper (unsigned char *prefix_, size_t size_,
|
||||
bool zmq::mtrie_t::rm_helper (unsigned char *prefix_,
|
||||
size_t size_,
|
||||
pipe_t *pipe_)
|
||||
{
|
||||
if (!size_) {
|
||||
@@ -306,8 +299,7 @@ bool zmq::mtrie_t::rm_helper (unsigned char *prefix_, size_t size_,
|
||||
if (!count || c < min || c >= min + count)
|
||||
return false;
|
||||
|
||||
mtrie_t *next_node =
|
||||
count == 1 ? next.node : next.table [c - min];
|
||||
mtrie_t *next_node = count == 1 ? next.node : next.table[c - min];
|
||||
|
||||
if (!next_node)
|
||||
return false;
|
||||
@@ -323,8 +315,7 @@ bool zmq::mtrie_t::rm_helper (unsigned char *prefix_, size_t size_,
|
||||
count = 0;
|
||||
--live_nodes;
|
||||
zmq_assert (live_nodes == 0);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
next.table[c - min] = 0;
|
||||
zmq_assert (live_nodes > 1);
|
||||
--live_nodes;
|
||||
@@ -345,9 +336,7 @@ bool zmq::mtrie_t::rm_helper (unsigned char *prefix_, size_t size_,
|
||||
mtrie_t *oldp = next.table[i];
|
||||
free (next.table);
|
||||
next.node = oldp;
|
||||
}
|
||||
else
|
||||
if (c == min) {
|
||||
} else if (c == min) {
|
||||
// We can compact the table "from the left"
|
||||
unsigned short i;
|
||||
for (i = 1; i < count; ++i)
|
||||
@@ -362,9 +351,7 @@ bool zmq::mtrie_t::rm_helper (unsigned char *prefix_, size_t size_,
|
||||
alloc_assert (next.table);
|
||||
memmove (next.table, old_table + i, sizeof (mtrie_t *) * count);
|
||||
free (old_table);
|
||||
}
|
||||
else
|
||||
if (c == min + count - 1) {
|
||||
} else if (c == min + count - 1) {
|
||||
// We can compact the table "from the right"
|
||||
unsigned short i;
|
||||
for (i = 1; i < count; ++i)
|
||||
@@ -385,12 +372,13 @@ bool zmq::mtrie_t::rm_helper (unsigned char *prefix_, size_t size_,
|
||||
return ret;
|
||||
}
|
||||
|
||||
void zmq::mtrie_t::match (unsigned char *data_, size_t size_,
|
||||
void (*func_) (pipe_t *pipe_, void *arg_), void *arg_)
|
||||
void zmq::mtrie_t::match (unsigned char *data_,
|
||||
size_t size_,
|
||||
void (*func_) (pipe_t *pipe_, void *arg_),
|
||||
void *arg_)
|
||||
{
|
||||
mtrie_t *current = this;
|
||||
while (true) {
|
||||
|
||||
// Signal the pipes attached to this node.
|
||||
if (current->pipes) {
|
||||
for (pipes_t::iterator it = current->pipes->begin ();
|
||||
@@ -417,8 +405,8 @@ void zmq::mtrie_t::match (unsigned char *data_, size_t size_,
|
||||
}
|
||||
|
||||
// If there are multiple subnodes.
|
||||
if (data_ [0] < current->min || data_ [0] >=
|
||||
current->min + current->count)
|
||||
if (data_[0] < current->min
|
||||
|| data_[0] >= current->min + current->count)
|
||||
break;
|
||||
if (!current->next.table[data_[0] - current->min])
|
||||
break;
|
||||
|
@@ -37,7 +37,6 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
class pipe_t;
|
||||
|
||||
// Multi-trie. Each node in the trie is a set of pointers to pipes.
|
||||
@@ -45,7 +44,6 @@ namespace zmq
|
||||
class mtrie_t
|
||||
{
|
||||
public:
|
||||
|
||||
mtrie_t ();
|
||||
~mtrie_t ();
|
||||
|
||||
@@ -59,26 +57,30 @@ namespace zmq
|
||||
// every removal.
|
||||
void rm (zmq::pipe_t *pipe_,
|
||||
void (*func_) (unsigned char *data_, size_t size_, void *arg_),
|
||||
void *arg_, bool call_on_uniq_);
|
||||
void *arg_,
|
||||
bool call_on_uniq_);
|
||||
|
||||
// Remove specific subscription from the trie. Return true is it was
|
||||
// actually removed rather than de-duplicated.
|
||||
bool rm (unsigned char *prefix_, size_t size_, zmq::pipe_t *pipe_);
|
||||
|
||||
// Signal all the matching pipes.
|
||||
void match (unsigned char *data_, size_t size_,
|
||||
void (*func_) (zmq::pipe_t *pipe_, void *arg_), void *arg_);
|
||||
void match (unsigned char *data_,
|
||||
size_t size_,
|
||||
void (*func_) (zmq::pipe_t *pipe_, void *arg_),
|
||||
void *arg_);
|
||||
|
||||
private:
|
||||
|
||||
bool add_helper (unsigned char *prefix_, size_t size_,
|
||||
zmq::pipe_t *pipe_);
|
||||
void rm_helper (zmq::pipe_t *pipe_, unsigned char **buff_,
|
||||
size_t buffsize_, size_t maxbuffsize_,
|
||||
bool add_helper (unsigned char *prefix_, size_t size_, zmq::pipe_t *pipe_);
|
||||
void
|
||||
rm_helper (zmq::pipe_t *pipe_,
|
||||
unsigned char **buff_,
|
||||
size_t buffsize_,
|
||||
size_t maxbuffsize_,
|
||||
void (*func_) (unsigned char *data_, size_t size_, void *arg_),
|
||||
void *arg_, bool call_on_uniq_);
|
||||
bool rm_helper (unsigned char *prefix_, size_t size_,
|
||||
zmq::pipe_t *pipe_);
|
||||
void *arg_,
|
||||
bool call_on_uniq_);
|
||||
bool rm_helper (unsigned char *prefix_, size_t size_, zmq::pipe_t *pipe_);
|
||||
bool is_redundant () const;
|
||||
|
||||
typedef std::set<zmq::pipe_t *> pipes_t;
|
||||
@@ -87,7 +89,8 @@ namespace zmq
|
||||
unsigned char min;
|
||||
unsigned short count;
|
||||
unsigned short live_nodes;
|
||||
union {
|
||||
union
|
||||
{
|
||||
class mtrie_t *node;
|
||||
class mtrie_t **table;
|
||||
} next;
|
||||
@@ -95,8 +98,6 @@ namespace zmq
|
||||
mtrie_t (const mtrie_t &);
|
||||
const mtrie_t &operator= (const mtrie_t &);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -40,49 +40,31 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
class mutex_t
|
||||
{
|
||||
public:
|
||||
inline mutex_t ()
|
||||
{
|
||||
InitializeCriticalSection (&cs);
|
||||
}
|
||||
inline mutex_t () { InitializeCriticalSection (&cs); }
|
||||
|
||||
inline ~mutex_t ()
|
||||
{
|
||||
DeleteCriticalSection (&cs);
|
||||
}
|
||||
inline ~mutex_t () { DeleteCriticalSection (&cs); }
|
||||
|
||||
inline void lock ()
|
||||
{
|
||||
EnterCriticalSection (&cs);
|
||||
}
|
||||
inline void lock () { EnterCriticalSection (&cs); }
|
||||
|
||||
inline bool try_lock ()
|
||||
{
|
||||
return (TryEnterCriticalSection (&cs)) ? true : false;
|
||||
}
|
||||
|
||||
inline void unlock ()
|
||||
{
|
||||
LeaveCriticalSection (&cs);
|
||||
}
|
||||
inline void unlock () { LeaveCriticalSection (&cs); }
|
||||
|
||||
inline CRITICAL_SECTION* get_cs()
|
||||
{
|
||||
return &cs;
|
||||
}
|
||||
inline CRITICAL_SECTION *get_cs () { return &cs; }
|
||||
|
||||
private:
|
||||
|
||||
CRITICAL_SECTION cs;
|
||||
|
||||
// Disable copy construction and assignment.
|
||||
mutex_t (const mutex_t &);
|
||||
void operator= (const mutex_t &);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
@@ -91,7 +73,6 @@ namespace zmq
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
class mutex_t
|
||||
{
|
||||
public:
|
||||
@@ -138,13 +119,9 @@ namespace zmq
|
||||
posix_assert (rc);
|
||||
}
|
||||
|
||||
inline pthread_mutex_t* get_mutex()
|
||||
{
|
||||
return &mutex;
|
||||
}
|
||||
inline pthread_mutex_t *get_mutex () { return &mutex; }
|
||||
|
||||
private:
|
||||
|
||||
pthread_mutex_t mutex;
|
||||
pthread_mutexattr_t attr;
|
||||
|
||||
@@ -152,7 +129,6 @@ namespace zmq
|
||||
mutex_t (const mutex_t &);
|
||||
const mutex_t &operator= (const mutex_t &);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -162,19 +138,11 @@ namespace zmq
|
||||
{
|
||||
struct scoped_lock_t
|
||||
{
|
||||
scoped_lock_t (mutex_t& mutex_)
|
||||
: mutex (mutex_)
|
||||
{
|
||||
mutex.lock ();
|
||||
}
|
||||
scoped_lock_t (mutex_t &mutex_) : mutex (mutex_) { mutex.lock (); }
|
||||
|
||||
~scoped_lock_t ()
|
||||
{
|
||||
mutex.unlock ();
|
||||
}
|
||||
~scoped_lock_t () { mutex.unlock (); }
|
||||
|
||||
private:
|
||||
|
||||
mutex_t &mutex;
|
||||
|
||||
// Disable copy construction and assignment.
|
||||
@@ -185,8 +153,7 @@ namespace zmq
|
||||
|
||||
struct scoped_optional_lock_t
|
||||
{
|
||||
scoped_optional_lock_t (mutex_t* mutex_)
|
||||
: mutex (mutex_)
|
||||
scoped_optional_lock_t (mutex_t *mutex_) : mutex (mutex_)
|
||||
{
|
||||
if (mutex != NULL)
|
||||
mutex->lock ();
|
||||
@@ -199,15 +166,12 @@ namespace zmq
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
mutex_t *mutex;
|
||||
|
||||
// Disable copy construction and assignment.
|
||||
scoped_optional_lock_t (const scoped_lock_t &);
|
||||
const scoped_optional_lock_t &operator= (const scoped_lock_t &);
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -10,14 +10,22 @@
|
||||
#include "v2_protocol.hpp"
|
||||
|
||||
zmq::norm_engine_t::norm_engine_t (io_thread_t *parent_,
|
||||
const options_t& options_)
|
||||
: io_object_t(parent_), zmq_session(NULL), options(options_),
|
||||
norm_instance(NORM_INSTANCE_INVALID), norm_session(NORM_SESSION_INVALID),
|
||||
is_sender(false), is_receiver(false),
|
||||
zmq_encoder(0), norm_tx_stream(NORM_OBJECT_INVALID),
|
||||
tx_first_msg(true), tx_more_bit(false),
|
||||
zmq_output_ready(false), norm_tx_ready(false),
|
||||
tx_index(0), tx_len(0),
|
||||
const options_t &options_) :
|
||||
io_object_t (parent_),
|
||||
zmq_session (NULL),
|
||||
options (options_),
|
||||
norm_instance (NORM_INSTANCE_INVALID),
|
||||
norm_session (NORM_SESSION_INVALID),
|
||||
is_sender (false),
|
||||
is_receiver (false),
|
||||
zmq_encoder (0),
|
||||
norm_tx_stream (NORM_OBJECT_INVALID),
|
||||
tx_first_msg (true),
|
||||
tx_more_bit (false),
|
||||
zmq_output_ready (false),
|
||||
norm_tx_ready (false),
|
||||
tx_index (0),
|
||||
tx_len (0),
|
||||
zmq_input_ready (false)
|
||||
{
|
||||
int rc = tx_msg.init ();
|
||||
@@ -38,59 +46,53 @@ int zmq::norm_engine_t::init(const char* network_, bool send, bool recv)
|
||||
// (default NORM_NODE_ANY causes NORM to use host IP addr for NormNodeId)
|
||||
NormNodeId localId = NORM_NODE_ANY;
|
||||
const char *ifacePtr = strchr (network_, ',');
|
||||
if (NULL != ifacePtr)
|
||||
{
|
||||
if (NULL != ifacePtr) {
|
||||
size_t idLen = ifacePtr - network_;
|
||||
if (idLen > 31) idLen = 31;
|
||||
if (idLen > 31)
|
||||
idLen = 31;
|
||||
char idText[32];
|
||||
strncpy (idText, network_, idLen);
|
||||
idText[idLen] = '\0';
|
||||
localId = (NormNodeId) atoi (idText);
|
||||
ifacePtr++;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
ifacePtr = network_;
|
||||
}
|
||||
|
||||
// Second, look for optional multicast ifaceName
|
||||
char ifaceName[256];
|
||||
const char *addrPtr = strchr (ifacePtr, ';');
|
||||
if (NULL != addrPtr)
|
||||
{
|
||||
if (NULL != addrPtr) {
|
||||
size_t ifaceLen = addrPtr - ifacePtr;
|
||||
if (ifaceLen > 255) ifaceLen = 255; // return error instead?
|
||||
if (ifaceLen > 255)
|
||||
ifaceLen = 255; // return error instead?
|
||||
strncpy (ifaceName, ifacePtr, ifaceLen);
|
||||
ifaceName[ifaceLen] = '\0';
|
||||
ifacePtr = ifaceName;
|
||||
addrPtr++;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
addrPtr = ifacePtr;
|
||||
ifacePtr = NULL;
|
||||
}
|
||||
|
||||
// Finally, parse IP address and port number
|
||||
const char *portPtr = strrchr (addrPtr, ':');
|
||||
if (NULL == portPtr)
|
||||
{
|
||||
if (NULL == portPtr) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
char addr[256];
|
||||
size_t addrLen = portPtr - addrPtr;
|
||||
if (addrLen > 255) addrLen = 255;
|
||||
if (addrLen > 255)
|
||||
addrLen = 255;
|
||||
strncpy (addr, addrPtr, addrLen);
|
||||
addr[addrLen] = '\0';
|
||||
portPtr++;
|
||||
unsigned short portNumber = atoi (portPtr);
|
||||
|
||||
if (NORM_INSTANCE_INVALID == norm_instance)
|
||||
{
|
||||
if (NORM_INSTANCE_INVALID == (norm_instance = NormCreateInstance()))
|
||||
{
|
||||
if (NORM_INSTANCE_INVALID == norm_instance) {
|
||||
if (NORM_INSTANCE_INVALID == (norm_instance = NormCreateInstance ())) {
|
||||
// errno set by whatever caused NormCreateInstance() to fail
|
||||
return -1;
|
||||
}
|
||||
@@ -104,8 +106,7 @@ int zmq::norm_engine_t::init(const char* network_, bool send, bool recv)
|
||||
// conflict detection/resolution protocol
|
||||
|
||||
norm_session = NormCreateSession (norm_instance, addr, portNumber, localId);
|
||||
if (NORM_SESSION_INVALID == norm_session)
|
||||
{
|
||||
if (NORM_SESSION_INVALID == norm_session) {
|
||||
int savedErrno = errno;
|
||||
NormDestroyInstance (norm_instance);
|
||||
norm_instance = NORM_INSTANCE_INVALID;
|
||||
@@ -113,33 +114,32 @@ int zmq::norm_engine_t::init(const char* network_, bool send, bool recv)
|
||||
return -1;
|
||||
}
|
||||
// There's many other useful NORM options that could be applied here
|
||||
if (NormIsUnicastAddress(addr))
|
||||
{
|
||||
if (NormIsUnicastAddress (addr)) {
|
||||
NormSetDefaultUnicastNack (norm_session, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// These only apply for multicast sessions
|
||||
//NormSetTTL(norm_session, options.multicast_hops); // ZMQ default is 1
|
||||
NormSetTTL(norm_session, 255); // since the ZMQ_MULTICAST_HOPS socket option isn't well-supported
|
||||
NormSetRxPortReuse(norm_session, true); // port reuse doesn't work for non-connected unicast
|
||||
NormSetLoopback(norm_session, true); // needed when multicast users on same machine
|
||||
if (NULL != ifacePtr)
|
||||
{
|
||||
NormSetTTL (
|
||||
norm_session,
|
||||
255); // since the ZMQ_MULTICAST_HOPS socket option isn't well-supported
|
||||
NormSetRxPortReuse (
|
||||
norm_session,
|
||||
true); // port reuse doesn't work for non-connected unicast
|
||||
NormSetLoopback (norm_session,
|
||||
true); // needed when multicast users on same machine
|
||||
if (NULL != ifacePtr) {
|
||||
// Note a bad interface may not be caught until sender or receiver start
|
||||
// (Since sender/receiver is not yet started, this always succeeds here)
|
||||
NormSetMulticastInterface (norm_session, ifacePtr);
|
||||
}
|
||||
}
|
||||
|
||||
if (recv)
|
||||
{
|
||||
if (recv) {
|
||||
// The alternative NORM_SYNC_CURRENT here would provide "instant"
|
||||
// receiver sync to the sender's _current_ message transmission.
|
||||
// NORM_SYNC_STREAM tries to get everything the sender has cached/buffered
|
||||
NormSetDefaultSyncPolicy (norm_session, NORM_SYNC_STREAM);
|
||||
if (!NormStartReceiver(norm_session, 2*1024*1024))
|
||||
{
|
||||
if (!NormStartReceiver (norm_session, 2 * 1024 * 1024)) {
|
||||
// errno set by whatever failed
|
||||
int savedErrno = errno;
|
||||
NormDestroyInstance (norm_instance); // session gets closed, too
|
||||
@@ -151,13 +151,12 @@ int zmq::norm_engine_t::init(const char* network_, bool send, bool recv)
|
||||
is_receiver = true;
|
||||
}
|
||||
|
||||
if (send)
|
||||
{
|
||||
if (send) {
|
||||
// Pick a random sender instance id (aka norm sender session id)
|
||||
NormSessionId instanceId = NormGetRandomSessionId ();
|
||||
// TBD - provide "options" for some NORM sender parameters
|
||||
if (!NormStartSender(norm_session, instanceId, 2*1024*1024, 1400, 16, 4))
|
||||
{
|
||||
if (!NormStartSender (norm_session, instanceId, 2 * 1024 * 1024, 1400,
|
||||
16, 4)) {
|
||||
// errno set by whatever failed
|
||||
int savedErrno = errno;
|
||||
NormDestroyInstance (norm_instance); // session gets closed, too
|
||||
@@ -169,8 +168,9 @@ int zmq::norm_engine_t::init(const char* network_, bool send, bool recv)
|
||||
NormSetCongestionControl (norm_session, true);
|
||||
norm_tx_ready = true;
|
||||
is_sender = true;
|
||||
if (NORM_OBJECT_INVALID == (norm_tx_stream = NormStreamOpen(norm_session, 2*1024*1024)))
|
||||
{
|
||||
if (NORM_OBJECT_INVALID
|
||||
== (norm_tx_stream =
|
||||
NormStreamOpen (norm_session, 2 * 1024 * 1024))) {
|
||||
// errno set by whatever failed
|
||||
int savedErrno = errno;
|
||||
NormDestroyInstance (norm_instance); // session gets closed, too
|
||||
@@ -191,8 +191,7 @@ int zmq::norm_engine_t::init(const char* network_, bool send, bool recv)
|
||||
void zmq::norm_engine_t::shutdown ()
|
||||
{
|
||||
// TBD - implement a more graceful shutdown option
|
||||
if (is_receiver)
|
||||
{
|
||||
if (is_receiver) {
|
||||
NormStopReceiver (norm_session);
|
||||
|
||||
// delete any active NormRxStreamState
|
||||
@@ -202,37 +201,38 @@ void zmq::norm_engine_t::shutdown()
|
||||
|
||||
is_receiver = false;
|
||||
}
|
||||
if (is_sender)
|
||||
{
|
||||
if (is_sender) {
|
||||
NormStopSender (norm_session);
|
||||
is_sender = false;
|
||||
}
|
||||
if (NORM_SESSION_INVALID != norm_session)
|
||||
{
|
||||
if (NORM_SESSION_INVALID != norm_session) {
|
||||
NormDestroySession (norm_session);
|
||||
norm_session = NORM_SESSION_INVALID;
|
||||
}
|
||||
if (NORM_INSTANCE_INVALID != norm_instance)
|
||||
{
|
||||
if (NORM_INSTANCE_INVALID != norm_instance) {
|
||||
NormStopInstance (norm_instance);
|
||||
NormDestroyInstance (norm_instance);
|
||||
norm_instance = NORM_INSTANCE_INVALID;
|
||||
}
|
||||
} // end zmq::norm_engine_t::shutdown()
|
||||
|
||||
void zmq::norm_engine_t::plug (io_thread_t* io_thread_, session_base_t *session_)
|
||||
void zmq::norm_engine_t::plug (io_thread_t *io_thread_,
|
||||
session_base_t *session_)
|
||||
{
|
||||
// TBD - we may assign the NORM engine to an io_thread in the future???
|
||||
zmq_session = session_;
|
||||
if (is_sender) zmq_output_ready = true;
|
||||
if (is_receiver) zmq_input_ready = true;
|
||||
if (is_sender)
|
||||
zmq_output_ready = true;
|
||||
if (is_receiver)
|
||||
zmq_input_ready = true;
|
||||
|
||||
fd_t normDescriptor = NormGetDescriptor (norm_instance);
|
||||
norm_descriptor_handle = add_fd (normDescriptor);
|
||||
// Set POLLIN for notification of pending NormEvents
|
||||
set_pollin (norm_descriptor_handle);
|
||||
|
||||
if (is_sender) send_data();
|
||||
if (is_sender)
|
||||
send_data ();
|
||||
|
||||
} // end zmq::norm_engine_t::init()
|
||||
|
||||
@@ -254,31 +254,26 @@ void zmq::norm_engine_t::restart_output()
|
||||
{
|
||||
// There's new message data available from the session
|
||||
zmq_output_ready = true;
|
||||
if (norm_tx_ready) send_data();
|
||||
if (norm_tx_ready)
|
||||
send_data ();
|
||||
|
||||
} // end zmq::norm_engine_t::restart_output()
|
||||
|
||||
void zmq::norm_engine_t::send_data ()
|
||||
{
|
||||
// Here we write as much as is available or we can
|
||||
while (zmq_output_ready && norm_tx_ready)
|
||||
{
|
||||
if (0 == tx_len)
|
||||
{
|
||||
while (zmq_output_ready && norm_tx_ready) {
|
||||
if (0 == tx_len) {
|
||||
// Our tx_buffer needs data to send
|
||||
// Get more data from encoder
|
||||
size_t space = BUFFER_SIZE;
|
||||
unsigned char *bufPtr = (unsigned char *) tx_buffer;
|
||||
tx_len = zmq_encoder.encode (&bufPtr, space);
|
||||
if (0 == tx_len)
|
||||
{
|
||||
if (tx_first_msg)
|
||||
{
|
||||
if (0 == tx_len) {
|
||||
if (tx_first_msg) {
|
||||
// We don't need to mark eom/flush until a message is sent
|
||||
tx_first_msg = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// A prior message was completely written to stream, so
|
||||
// mark end-of-message and possibly flush (to force packet transmission,
|
||||
// even if it's not a full segment so message gets delivered quickly)
|
||||
@@ -289,8 +284,7 @@ void zmq::norm_engine_t::send_data()
|
||||
NormStreamFlush (norm_tx_stream, true, NORM_FLUSH_ACTIVE);
|
||||
}
|
||||
// Need to pull and load a new message to send
|
||||
if (-1 == zmq_session->pull_msg(&tx_msg))
|
||||
{
|
||||
if (-1 == zmq_session->pull_msg (&tx_msg)) {
|
||||
// We need to wait for "restart_output()" to be called by ZMQ
|
||||
zmq_output_ready = false;
|
||||
break;
|
||||
@@ -304,7 +298,8 @@ void zmq::norm_engine_t::send_data()
|
||||
// I.e.,If more_flag _was_ false previously, this is the first
|
||||
// frame of a ZMQ message.
|
||||
if (tx_more_bit)
|
||||
tx_buffer[0] = (char)0xff; // this is not first frame of message
|
||||
tx_buffer[0] =
|
||||
(char) 0xff; // this is not first frame of message
|
||||
else
|
||||
tx_buffer[0] = 0x00; // this is first frame of message
|
||||
tx_more_bit = (0 != (tx_msg.flags () & msg_t::more));
|
||||
@@ -316,12 +311,11 @@ void zmq::norm_engine_t::send_data()
|
||||
}
|
||||
}
|
||||
// Do we have data in our tx_buffer pending
|
||||
if (tx_index < tx_len)
|
||||
{
|
||||
if (tx_index < tx_len) {
|
||||
// We have data in our tx_buffer to send, so write it to the stream
|
||||
tx_index += NormStreamWrite(norm_tx_stream, tx_buffer + tx_index, tx_len - tx_index);
|
||||
if (tx_index < tx_len)
|
||||
{
|
||||
tx_index += NormStreamWrite (norm_tx_stream, tx_buffer + tx_index,
|
||||
tx_len - tx_index);
|
||||
if (tx_index < tx_len) {
|
||||
// NORM stream buffer full, wait for NORM_TX_QUEUE_VACANCY
|
||||
norm_tx_ready = false;
|
||||
break;
|
||||
@@ -335,19 +329,16 @@ void zmq::norm_engine_t::in_event()
|
||||
{
|
||||
// This means a NormEvent is pending, so call NormGetNextEvent() and handle
|
||||
NormEvent event;
|
||||
if (!NormGetNextEvent(norm_instance, &event))
|
||||
{
|
||||
if (!NormGetNextEvent (norm_instance, &event)) {
|
||||
// NORM has died before we unplugged?!
|
||||
zmq_assert (false);
|
||||
return;
|
||||
}
|
||||
|
||||
switch(event.type)
|
||||
{
|
||||
switch (event.type) {
|
||||
case NORM_TX_QUEUE_VACANCY:
|
||||
case NORM_TX_QUEUE_EMPTY:
|
||||
if (!norm_tx_ready)
|
||||
{
|
||||
if (!norm_tx_ready) {
|
||||
norm_tx_ready = true;
|
||||
send_data ();
|
||||
}
|
||||
@@ -359,16 +350,16 @@ void zmq::norm_engine_t::in_event()
|
||||
recv_data (event.object);
|
||||
break;
|
||||
|
||||
case NORM_RX_OBJECT_ABORTED:
|
||||
{
|
||||
NormRxStreamState* rxState = (NormRxStreamState*)NormObjectGetUserData(event.object);
|
||||
if (NULL != rxState)
|
||||
{
|
||||
case NORM_RX_OBJECT_ABORTED: {
|
||||
NormRxStreamState *rxState =
|
||||
(NormRxStreamState *) NormObjectGetUserData (event.object);
|
||||
if (NULL != rxState) {
|
||||
// Remove the state from the list it's in
|
||||
// This is now unnecessary since deletion takes care of list removal
|
||||
// but in the interest of being clear ...
|
||||
NormRxStreamState::List *list = rxState->AccessList ();
|
||||
if (NULL != list) list->Remove(*rxState);
|
||||
if (NULL != list)
|
||||
list->Remove (*rxState);
|
||||
}
|
||||
delete rxState;
|
||||
break;
|
||||
@@ -403,37 +394,33 @@ void zmq::norm_engine_t::restart_input()
|
||||
|
||||
void zmq::norm_engine_t::recv_data (NormObjectHandle object)
|
||||
{
|
||||
if (NORM_OBJECT_INVALID != object)
|
||||
{
|
||||
if (NORM_OBJECT_INVALID != object) {
|
||||
// Call result of NORM_RX_OBJECT_UPDATED notification
|
||||
// This is a rx_ready indication for a new or existing rx stream
|
||||
// First, determine if this is a stream we already know
|
||||
zmq_assert (NORM_OBJECT_STREAM == NormObjectGetType (object));
|
||||
// Since there can be multiple senders (publishers), we keep
|
||||
// state for each separate rx stream.
|
||||
NormRxStreamState* rxState = (NormRxStreamState*)NormObjectGetUserData(object);
|
||||
if (NULL == rxState)
|
||||
{
|
||||
NormRxStreamState *rxState =
|
||||
(NormRxStreamState *) NormObjectGetUserData (object);
|
||||
if (NULL == rxState) {
|
||||
// This is a new stream, so create rxState with zmq decoder, etc
|
||||
rxState = new (std::nothrow) NormRxStreamState(object, options.maxmsgsize);
|
||||
rxState =
|
||||
new (std::nothrow) NormRxStreamState (object, options.maxmsgsize);
|
||||
errno_assert (rxState);
|
||||
|
||||
if (!rxState->Init())
|
||||
{
|
||||
if (!rxState->Init ()) {
|
||||
errno_assert (false);
|
||||
delete rxState;
|
||||
return;
|
||||
}
|
||||
NormObjectSetUserData (object, rxState);
|
||||
}
|
||||
else if (!rxState->IsRxReady())
|
||||
{
|
||||
} else if (!rxState->IsRxReady ()) {
|
||||
// Existing non-ready stream, so remove from pending
|
||||
// list to be promoted to rx_ready_list ...
|
||||
rx_pending_list.Remove (*rxState);
|
||||
}
|
||||
if (!rxState->IsRxReady())
|
||||
{
|
||||
if (!rxState->IsRxReady ()) {
|
||||
// TBD - prepend up front for immediate service?
|
||||
rxState->SetRxReady (true);
|
||||
rx_ready_list.Append (*rxState);
|
||||
@@ -441,16 +428,14 @@ void zmq::norm_engine_t::recv_data(NormObjectHandle object)
|
||||
}
|
||||
// This loop repeats until we've read all data available from "rx ready" inbound streams
|
||||
// and pushed any accumulated messages we can up to the zmq session.
|
||||
while (!rx_ready_list.IsEmpty() || (zmq_input_ready && !msg_ready_list.IsEmpty()))
|
||||
{
|
||||
while (!rx_ready_list.IsEmpty ()
|
||||
|| (zmq_input_ready && !msg_ready_list.IsEmpty ())) {
|
||||
// Iterate through our rx_ready streams, reading data into the decoder
|
||||
// (This services incoming "rx ready" streams in a round-robin fashion)
|
||||
NormRxStreamState::List::Iterator iterator (rx_ready_list);
|
||||
NormRxStreamState *rxState;
|
||||
while (NULL != (rxState = iterator.GetNextItem()))
|
||||
{
|
||||
switch(rxState->Decode())
|
||||
{
|
||||
while (NULL != (rxState = iterator.GetNextItem ())) {
|
||||
switch (rxState->Decode ()) {
|
||||
case 1: // msg completed
|
||||
// Complete message decoded, move this stream to msg_ready_list
|
||||
// to push the message up to the session below. Note the stream
|
||||
@@ -470,34 +455,30 @@ void zmq::norm_engine_t::recv_data(NormObjectHandle object)
|
||||
// Get more data from this stream
|
||||
NormObjectHandle stream = rxState->GetStreamHandle ();
|
||||
// First, make sure we're in sync ...
|
||||
while (!rxState->InSync())
|
||||
{
|
||||
while (!rxState->InSync ()) {
|
||||
// seek NORM message start
|
||||
if (!NormStreamSeekMsgStart(stream))
|
||||
{
|
||||
if (!NormStreamSeekMsgStart (stream)) {
|
||||
// Need to wait for more data
|
||||
break;
|
||||
}
|
||||
// read message 'flag' byte to see if this it's a 'final' frame
|
||||
char syncFlag;
|
||||
unsigned int numBytes = 1;
|
||||
if (!NormStreamRead(stream, &syncFlag, &numBytes))
|
||||
{
|
||||
if (!NormStreamRead (stream, &syncFlag, &numBytes)) {
|
||||
// broken stream (shouldn't happen after seek msg start?)
|
||||
zmq_assert (false);
|
||||
continue;
|
||||
}
|
||||
if (0 == numBytes)
|
||||
{
|
||||
if (0 == numBytes) {
|
||||
// This probably shouldn't happen either since we found msg start
|
||||
// Need to wait for more data
|
||||
break;
|
||||
}
|
||||
if (0 == syncFlag) rxState->SetSync(true);
|
||||
if (0 == syncFlag)
|
||||
rxState->SetSync (true);
|
||||
// else keep seeking ...
|
||||
} // end while(!rxState->InSync())
|
||||
if (!rxState->InSync())
|
||||
{
|
||||
if (!rxState->InSync ()) {
|
||||
// Need more data for this stream, so remove from "rx ready"
|
||||
// list and iterate to next "rx ready" stream
|
||||
rxState->SetRxReady (false);
|
||||
@@ -509,8 +490,7 @@ void zmq::norm_engine_t::recv_data(NormObjectHandle object)
|
||||
// Now we're actually ready to read data from the NORM stream to the zmq_decoder
|
||||
// the underlying zmq_decoder->get_buffer() call sets how much is needed.
|
||||
unsigned int numBytes = rxState->GetBytesNeeded ();
|
||||
if (!NormStreamRead(stream, rxState->AccessBuffer(), &numBytes))
|
||||
{
|
||||
if (!NormStreamRead (stream, rxState->AccessBuffer (), &numBytes)) {
|
||||
// broken NORM stream, so re-sync
|
||||
rxState->Init (); // TBD - check result
|
||||
// This will retry syncing, and getting data from this stream
|
||||
@@ -518,8 +498,7 @@ void zmq::norm_engine_t::recv_data(NormObjectHandle object)
|
||||
continue;
|
||||
}
|
||||
rxState->IncrementBufferCount (numBytes);
|
||||
if (0 == numBytes)
|
||||
{
|
||||
if (0 == numBytes) {
|
||||
// All the data available has been read
|
||||
// Need to wait for NORM_RX_OBJECT_UPDATED for this stream
|
||||
rxState->SetRxReady (false);
|
||||
@@ -529,28 +508,22 @@ void zmq::norm_engine_t::recv_data(NormObjectHandle object)
|
||||
}
|
||||
} // end while(NULL != (rxState = iterator.GetNextItem()))
|
||||
|
||||
if (zmq_input_ready)
|
||||
{
|
||||
if (zmq_input_ready) {
|
||||
// At this point, we've made a pass through the "rx_ready" stream list
|
||||
// Now make a pass through the "msg_pending" list (if the zmq session
|
||||
// ready for more input). This may possibly return streams back to
|
||||
// the "rx ready" stream list after their pending message is handled
|
||||
NormRxStreamState::List::Iterator iterator (msg_ready_list);
|
||||
NormRxStreamState *rxState;
|
||||
while (NULL != (rxState = iterator.GetNextItem()))
|
||||
{
|
||||
while (NULL != (rxState = iterator.GetNextItem ())) {
|
||||
msg_t *msg = rxState->AccessMsg ();
|
||||
int rc = zmq_session->push_msg (msg);
|
||||
if (-1 == rc)
|
||||
{
|
||||
if (EAGAIN == errno)
|
||||
{
|
||||
if (-1 == rc) {
|
||||
if (EAGAIN == errno) {
|
||||
// need to wait until session calls "restart_input()"
|
||||
zmq_input_ready = false;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// session rejected message?
|
||||
// TBD - handle this better
|
||||
zmq_assert (false);
|
||||
@@ -558,7 +531,9 @@ void zmq::norm_engine_t::recv_data(NormObjectHandle object)
|
||||
}
|
||||
// else message was accepted.
|
||||
msg_ready_list.Remove (*rxState);
|
||||
if (rxState->IsRxReady()) // Move back to "rx_ready" list to read more data
|
||||
if (
|
||||
rxState
|
||||
->IsRxReady ()) // Move back to "rx_ready" list to read more data
|
||||
rx_ready_list.Append (*rxState);
|
||||
else // Move back to "rx_pending" list until NORM_RX_OBJECT_UPDATED
|
||||
msg_ready_list.Append (*rxState);
|
||||
@@ -571,24 +546,30 @@ void zmq::norm_engine_t::recv_data(NormObjectHandle object)
|
||||
|
||||
} // end zmq::norm_engine_t::recv_data()
|
||||
|
||||
zmq::norm_engine_t::NormRxStreamState::NormRxStreamState(NormObjectHandle normStream,
|
||||
int64_t maxMsgSize)
|
||||
: norm_stream(normStream), max_msg_size(maxMsgSize),
|
||||
in_sync(false), rx_ready(false), zmq_decoder(NULL), skip_norm_sync(false),
|
||||
buffer_ptr(NULL), buffer_size(0), buffer_count(0),
|
||||
prev(NULL), next(NULL), list(NULL)
|
||||
zmq::norm_engine_t::NormRxStreamState::NormRxStreamState (
|
||||
NormObjectHandle normStream, int64_t maxMsgSize) :
|
||||
norm_stream (normStream),
|
||||
max_msg_size (maxMsgSize),
|
||||
in_sync (false),
|
||||
rx_ready (false),
|
||||
zmq_decoder (NULL),
|
||||
skip_norm_sync (false),
|
||||
buffer_ptr (NULL),
|
||||
buffer_size (0),
|
||||
buffer_count (0),
|
||||
prev (NULL),
|
||||
next (NULL),
|
||||
list (NULL)
|
||||
{
|
||||
}
|
||||
|
||||
zmq::norm_engine_t::NormRxStreamState::~NormRxStreamState ()
|
||||
{
|
||||
if (NULL != zmq_decoder)
|
||||
{
|
||||
if (NULL != zmq_decoder) {
|
||||
delete zmq_decoder;
|
||||
zmq_decoder = NULL;
|
||||
}
|
||||
if (NULL != list)
|
||||
{
|
||||
if (NULL != list) {
|
||||
list->Remove (*this);
|
||||
list = NULL;
|
||||
}
|
||||
@@ -598,19 +579,17 @@ bool zmq::norm_engine_t::NormRxStreamState::Init()
|
||||
{
|
||||
in_sync = false;
|
||||
skip_norm_sync = false;
|
||||
if (NULL != zmq_decoder) delete zmq_decoder;
|
||||
if (NULL != zmq_decoder)
|
||||
delete zmq_decoder;
|
||||
// Note "in_batch_size" comes from config.h
|
||||
zmq_decoder = new (std::nothrow) v2_decoder_t (in_batch_size, max_msg_size);
|
||||
alloc_assert (zmq_decoder);
|
||||
if (NULL != zmq_decoder)
|
||||
{
|
||||
if (NULL != zmq_decoder) {
|
||||
buffer_count = 0;
|
||||
buffer_size = 0;
|
||||
zmq_decoder->get_buffer (&buffer_ptr, &buffer_size);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} // end zmq::norm_engine_t::NormRxStreamState::Init()
|
||||
@@ -620,16 +599,14 @@ bool zmq::norm_engine_t::NormRxStreamState::Init()
|
||||
int zmq::norm_engine_t::NormRxStreamState::Decode ()
|
||||
{
|
||||
// If we have pending bytes to decode, process those first
|
||||
while (buffer_count > 0)
|
||||
{
|
||||
while (buffer_count > 0) {
|
||||
// There's pending data for the decoder to decode
|
||||
size_t processed = 0;
|
||||
|
||||
// This a bit of a kludgy approach used to weed
|
||||
// out the NORM ZMQ message transport "syncFlag" byte
|
||||
// from the ZMQ message stream being decoded (but it works!)
|
||||
if (skip_norm_sync)
|
||||
{
|
||||
if (skip_norm_sync) {
|
||||
buffer_ptr++;
|
||||
buffer_count--;
|
||||
skip_norm_sync = false;
|
||||
@@ -638,12 +615,10 @@ int zmq::norm_engine_t::NormRxStreamState::Decode()
|
||||
int rc = zmq_decoder->decode (buffer_ptr, buffer_count, processed);
|
||||
buffer_ptr += processed;
|
||||
buffer_count -= processed;
|
||||
switch (rc)
|
||||
{
|
||||
switch (rc) {
|
||||
case 1:
|
||||
// msg completed
|
||||
if (0 == buffer_count)
|
||||
{
|
||||
if (0 == buffer_count) {
|
||||
buffer_size = 0;
|
||||
zmq_decoder->get_buffer (&buffer_ptr, &buffer_size);
|
||||
}
|
||||
@@ -669,8 +644,7 @@ int zmq::norm_engine_t::NormRxStreamState::Decode()
|
||||
|
||||
} // end zmq::norm_engine_t::NormRxStreamState::Decode()
|
||||
|
||||
zmq::norm_engine_t::NormRxStreamState::List::List()
|
||||
: head(NULL), tail(NULL)
|
||||
zmq::norm_engine_t::NormRxStreamState::List::List () : head (NULL), tail (NULL)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -682,15 +656,15 @@ zmq::norm_engine_t::NormRxStreamState::List::~List()
|
||||
void zmq::norm_engine_t::NormRxStreamState::List::Destroy ()
|
||||
{
|
||||
NormRxStreamState *item = head;
|
||||
while (NULL != item)
|
||||
{
|
||||
while (NULL != item) {
|
||||
Remove (*item);
|
||||
delete item;
|
||||
item = head;
|
||||
}
|
||||
} // end zmq::norm_engine_t::NormRxStreamState::List::Destroy()
|
||||
|
||||
void zmq::norm_engine_t::NormRxStreamState::List::Append(NormRxStreamState& item)
|
||||
void zmq::norm_engine_t::NormRxStreamState::List::Append (
|
||||
NormRxStreamState &item)
|
||||
{
|
||||
item.prev = tail;
|
||||
if (NULL != tail)
|
||||
@@ -702,7 +676,8 @@ void zmq::norm_engine_t::NormRxStreamState::List::Append(NormRxStreamState& item
|
||||
item.list = this;
|
||||
} // end zmq::norm_engine_t::NormRxStreamState::List::Append()
|
||||
|
||||
void zmq::norm_engine_t::NormRxStreamState::List::Remove(NormRxStreamState& item)
|
||||
void zmq::norm_engine_t::NormRxStreamState::List::Remove (
|
||||
NormRxStreamState &item)
|
||||
{
|
||||
if (NULL != item.prev)
|
||||
item.prev->next = item.next;
|
||||
@@ -716,15 +691,18 @@ void zmq::norm_engine_t::NormRxStreamState::List::Remove(NormRxStreamState& item
|
||||
item.list = NULL;
|
||||
} // end zmq::norm_engine_t::NormRxStreamState::List::Remove()
|
||||
|
||||
zmq::norm_engine_t::NormRxStreamState::List::Iterator::Iterator(const List& list)
|
||||
: next_item(list.head)
|
||||
zmq::norm_engine_t::NormRxStreamState::List::Iterator::Iterator (
|
||||
const List &list) :
|
||||
next_item (list.head)
|
||||
{
|
||||
}
|
||||
|
||||
zmq::norm_engine_t::NormRxStreamState* zmq::norm_engine_t::NormRxStreamState::List::Iterator::GetNextItem()
|
||||
zmq::norm_engine_t::NormRxStreamState *
|
||||
zmq::norm_engine_t::NormRxStreamState::List::Iterator::GetNextItem ()
|
||||
{
|
||||
NormRxStreamState *nextItem = next_item;
|
||||
if (NULL != nextItem) next_item = nextItem->next;
|
||||
if (NULL != nextItem)
|
||||
next_item = nextItem->next;
|
||||
return nextItem;
|
||||
} // end zmq::norm_engine_t::NormRxStreamState::List::Iterator::GetNextItem()
|
||||
|
||||
|
@@ -59,41 +59,34 @@ namespace zmq
|
||||
void recv_data (NormObjectHandle stream);
|
||||
|
||||
|
||||
enum {BUFFER_SIZE = 2048};
|
||||
enum
|
||||
{
|
||||
BUFFER_SIZE = 2048
|
||||
};
|
||||
|
||||
// Used to keep track of streams from multiple senders
|
||||
class NormRxStreamState
|
||||
{
|
||||
public:
|
||||
NormRxStreamState(NormObjectHandle normStream,
|
||||
int64_t maxMsgSize);
|
||||
NormRxStreamState (NormObjectHandle normStream, int64_t maxMsgSize);
|
||||
~NormRxStreamState ();
|
||||
|
||||
NormObjectHandle GetStreamHandle() const
|
||||
{return norm_stream;}
|
||||
NormObjectHandle GetStreamHandle () const { return norm_stream; }
|
||||
|
||||
bool Init ();
|
||||
|
||||
void SetRxReady(bool state)
|
||||
{rx_ready = state;}
|
||||
bool IsRxReady() const
|
||||
{return rx_ready;}
|
||||
void SetRxReady (bool state) { rx_ready = state; }
|
||||
bool IsRxReady () const { return rx_ready; }
|
||||
|
||||
void SetSync(bool state)
|
||||
{in_sync = state;}
|
||||
bool InSync() const
|
||||
{return in_sync;}
|
||||
void SetSync (bool state) { in_sync = state; }
|
||||
bool InSync () const { return in_sync; }
|
||||
|
||||
// These are used to feed data to decoder
|
||||
// and its underlying "msg" buffer
|
||||
char* AccessBuffer()
|
||||
{return (char*)(buffer_ptr + buffer_count);}
|
||||
size_t GetBytesNeeded() const
|
||||
{return (buffer_size - buffer_count);}
|
||||
void IncrementBufferCount(size_t count)
|
||||
{buffer_count += count;}
|
||||
msg_t* AccessMsg()
|
||||
{return zmq_decoder->msg();}
|
||||
char *AccessBuffer () { return (char *) (buffer_ptr + buffer_count); }
|
||||
size_t GetBytesNeeded () const { return (buffer_size - buffer_count); }
|
||||
void IncrementBufferCount (size_t count) { buffer_count += count; }
|
||||
msg_t *AccessMsg () { return zmq_decoder->msg (); }
|
||||
// This invokes the decoder "decode" method
|
||||
// returning 0 if more data is needed,
|
||||
// 1 if the message is complete, If an error
|
||||
@@ -110,8 +103,7 @@ namespace zmq
|
||||
void Append (NormRxStreamState &item);
|
||||
void Remove (NormRxStreamState &item);
|
||||
|
||||
bool IsEmpty() const
|
||||
{return (NULL == head);}
|
||||
bool IsEmpty () const { return (NULL == head); }
|
||||
|
||||
void Destroy ();
|
||||
|
||||
@@ -120,6 +112,7 @@ namespace zmq
|
||||
public:
|
||||
Iterator (const List &list);
|
||||
NormRxStreamState *GetNextItem ();
|
||||
|
||||
private:
|
||||
NormRxStreamState *next_item;
|
||||
};
|
||||
@@ -133,8 +126,7 @@ namespace zmq
|
||||
|
||||
friend class List;
|
||||
|
||||
List* AccessList()
|
||||
{return list;}
|
||||
List *AccessList () { return list; }
|
||||
|
||||
|
||||
private:
|
||||
@@ -177,9 +169,12 @@ namespace zmq
|
||||
// Receiver state
|
||||
// Lists of norm rx streams from remote senders
|
||||
bool zmq_input_ready; // zmq ready to receive msg(s)
|
||||
NormRxStreamState::List rx_pending_list; // rx streams waiting for data reception
|
||||
NormRxStreamState::List rx_ready_list; // rx streams ready for NormStreamRead()
|
||||
NormRxStreamState::List msg_ready_list; // rx streams w/ msg ready for push to zmq
|
||||
NormRxStreamState::List
|
||||
rx_pending_list; // rx streams waiting for data reception
|
||||
NormRxStreamState::List
|
||||
rx_ready_list; // rx streams ready for NormStreamRead()
|
||||
NormRxStreamState::List
|
||||
msg_ready_list; // rx streams w/ msg ready for push to zmq
|
||||
|
||||
|
||||
}; // end class norm_engine_t
|
||||
|
@@ -70,11 +70,9 @@ int zmq::null_mechanism_t::next_handshake_command (msg_t *msg_)
|
||||
return -1;
|
||||
}
|
||||
int rc = session->zap_connect ();
|
||||
if (rc == -1)
|
||||
{
|
||||
if (rc == -1) {
|
||||
session->get_socket ()->event_handshake_failed_no_detail (
|
||||
session->get_endpoint(),
|
||||
EFAULT);
|
||||
session->get_endpoint (), EFAULT);
|
||||
return -1;
|
||||
}
|
||||
send_zap_request ();
|
||||
@@ -120,8 +118,7 @@ int zmq::null_mechanism_t::process_handshake_command (msg_t *msg_)
|
||||
{
|
||||
if (ready_command_received || error_command_received) {
|
||||
session->get_socket ()->event_handshake_failed_protocol (
|
||||
session->get_endpoint (),
|
||||
ZMQ_PROTOCOL_ERROR_ZMTP_UNEXPECTED_COMMAND);
|
||||
session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_UNEXPECTED_COMMAND);
|
||||
errno = EPROTO;
|
||||
return -1;
|
||||
}
|
||||
@@ -133,13 +130,11 @@ int zmq::null_mechanism_t::process_handshake_command (msg_t *msg_)
|
||||
int rc = 0;
|
||||
if (data_size >= 6 && !memcmp (cmd_data, "\5READY", 6))
|
||||
rc = process_ready_command (cmd_data, data_size);
|
||||
else
|
||||
if (data_size >= 6 && !memcmp (cmd_data, "\5ERROR", 6))
|
||||
else if (data_size >= 6 && !memcmp (cmd_data, "\5ERROR", 6))
|
||||
rc = process_error_command (cmd_data, data_size);
|
||||
else {
|
||||
session->get_socket ()->event_handshake_failed_protocol (
|
||||
session->get_endpoint (),
|
||||
ZMQ_PROTOCOL_ERROR_ZMTP_UNEXPECTED_COMMAND);
|
||||
session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_UNEXPECTED_COMMAND);
|
||||
errno = EPROTO;
|
||||
rc = -1;
|
||||
}
|
||||
@@ -153,15 +148,15 @@ int zmq::null_mechanism_t::process_handshake_command (msg_t *msg_)
|
||||
return rc;
|
||||
}
|
||||
|
||||
int zmq::null_mechanism_t::process_ready_command (
|
||||
const unsigned char *cmd_data, size_t data_size)
|
||||
int zmq::null_mechanism_t::process_ready_command (const unsigned char *cmd_data,
|
||||
size_t data_size)
|
||||
{
|
||||
ready_command_received = true;
|
||||
return parse_metadata (cmd_data + 6, data_size - 6);
|
||||
}
|
||||
|
||||
int zmq::null_mechanism_t::process_error_command (
|
||||
const unsigned char *cmd_data, size_t data_size)
|
||||
int zmq::null_mechanism_t::process_error_command (const unsigned char *cmd_data,
|
||||
size_t data_size)
|
||||
{
|
||||
if (data_size < 7) {
|
||||
session->get_socket ()->event_handshake_failed_protocol (
|
||||
@@ -200,15 +195,13 @@ int zmq::null_mechanism_t::zap_msg_available ()
|
||||
|
||||
zmq::mechanism_t::status_t zmq::null_mechanism_t::status () const
|
||||
{
|
||||
const bool command_sent =
|
||||
ready_command_sent || error_command_sent;
|
||||
const bool command_sent = ready_command_sent || error_command_sent;
|
||||
const bool command_received =
|
||||
ready_command_received || error_command_received;
|
||||
|
||||
if (ready_command_sent && ready_command_received)
|
||||
return mechanism_t::ready;
|
||||
else
|
||||
if (command_sent && command_received)
|
||||
else if (command_sent && command_received)
|
||||
return error;
|
||||
else
|
||||
return handshaking;
|
||||
|
@@ -36,14 +36,12 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
class msg_t;
|
||||
class session_base_t;
|
||||
|
||||
class null_mechanism_t : public zap_client_t
|
||||
{
|
||||
public:
|
||||
|
||||
null_mechanism_t (session_base_t *session_,
|
||||
const std::string &peer_address,
|
||||
const options_t &options_);
|
||||
@@ -56,7 +54,6 @@ namespace zmq
|
||||
virtual status_t status () const;
|
||||
|
||||
private:
|
||||
|
||||
bool ready_command_sent;
|
||||
bool error_command_sent;
|
||||
bool ready_command_received;
|
||||
@@ -64,14 +61,11 @@ namespace zmq
|
||||
bool zap_request_sent;
|
||||
bool zap_reply_received;
|
||||
|
||||
int process_ready_command (
|
||||
const unsigned char *cmd_data, size_t data_size);
|
||||
int process_error_command (
|
||||
const unsigned char *cmd_data, size_t data_size);
|
||||
int process_ready_command (const unsigned char *cmd_data, size_t data_size);
|
||||
int process_error_command (const unsigned char *cmd_data, size_t data_size);
|
||||
|
||||
void send_zap_request ();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -39,9 +39,7 @@
|
||||
#include "session_base.hpp"
|
||||
#include "socket_base.hpp"
|
||||
|
||||
zmq::object_t::object_t (ctx_t *ctx_, uint32_t tid_) :
|
||||
ctx (ctx_),
|
||||
tid (tid_)
|
||||
zmq::object_t::object_t (ctx_t *ctx_, uint32_t tid_) : ctx (ctx_), tid (tid_)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -73,7 +71,6 @@ zmq::ctx_t *zmq::object_t::get_ctx ()
|
||||
void zmq::object_t::process_command (command_t &cmd_)
|
||||
{
|
||||
switch (cmd_.type) {
|
||||
|
||||
case command_t::activate_read:
|
||||
process_activate_read ();
|
||||
break;
|
||||
@@ -119,7 +116,8 @@ void zmq::object_t::process_command (command_t &cmd_)
|
||||
break;
|
||||
|
||||
case command_t::pipe_hwm:
|
||||
process_pipe_hwm (cmd_.args.pipe_hwm.inhwm, cmd_.args.pipe_hwm.outhwm);
|
||||
process_pipe_hwm (cmd_.args.pipe_hwm.inhwm,
|
||||
cmd_.args.pipe_hwm.outhwm);
|
||||
break;
|
||||
|
||||
case command_t::term_req:
|
||||
@@ -162,8 +160,8 @@ int zmq::object_t::register_endpoint (const char *addr_,
|
||||
return ctx->register_endpoint (addr_, endpoint_);
|
||||
}
|
||||
|
||||
int zmq::object_t::unregister_endpoint (
|
||||
const std::string &addr_, socket_base_t *socket_)
|
||||
int zmq::object_t::unregister_endpoint (const std::string &addr_,
|
||||
socket_base_t *socket_)
|
||||
{
|
||||
return ctx->unregister_endpoint (addr_, socket_);
|
||||
}
|
||||
@@ -179,12 +177,14 @@ zmq::endpoint_t zmq::object_t::find_endpoint (const char *addr_)
|
||||
}
|
||||
|
||||
void zmq::object_t::pend_connection (const std::string &addr_,
|
||||
const endpoint_t &endpoint_, pipe_t **pipes_)
|
||||
const endpoint_t &endpoint_,
|
||||
pipe_t **pipes_)
|
||||
{
|
||||
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_)
|
||||
{
|
||||
return ctx->connect_pending (addr_, bind_socket_);
|
||||
}
|
||||
@@ -231,7 +231,8 @@ void zmq::object_t::send_own (own_t *destination_, own_t *object_)
|
||||
}
|
||||
|
||||
void zmq::object_t::send_attach (session_base_t *destination_,
|
||||
i_engine *engine_, bool inc_seqnum_)
|
||||
i_engine *engine_,
|
||||
bool inc_seqnum_)
|
||||
{
|
||||
if (inc_seqnum_)
|
||||
destination_->inc_seqnum ();
|
||||
@@ -243,7 +244,8 @@ void zmq::object_t::send_attach (session_base_t *destination_,
|
||||
send_command (cmd);
|
||||
}
|
||||
|
||||
void zmq::object_t::send_bind (own_t *destination_, pipe_t *pipe_,
|
||||
void zmq::object_t::send_bind (own_t *destination_,
|
||||
pipe_t *pipe_,
|
||||
bool inc_seqnum_)
|
||||
{
|
||||
if (inc_seqnum_)
|
||||
@@ -299,7 +301,9 @@ void zmq::object_t::send_pipe_term_ack (pipe_t *destination_)
|
||||
send_command (cmd);
|
||||
}
|
||||
|
||||
void zmq::object_t::send_pipe_hwm (pipe_t *destination_, int inhwm_, int outhwm_)
|
||||
void zmq::object_t::send_pipe_hwm (pipe_t *destination_,
|
||||
int inhwm_,
|
||||
int outhwm_)
|
||||
{
|
||||
command_t cmd;
|
||||
cmd.destination = destination_;
|
||||
@@ -309,8 +313,7 @@ void zmq::object_t::send_pipe_hwm (pipe_t *destination_, int inhwm_, int outhwm_
|
||||
send_command (cmd);
|
||||
}
|
||||
|
||||
void zmq::object_t::send_term_req (own_t *destination_,
|
||||
own_t *object_)
|
||||
void zmq::object_t::send_term_req (own_t *destination_, own_t *object_)
|
||||
{
|
||||
command_t cmd;
|
||||
cmd.destination = destination_;
|
||||
@@ -473,4 +476,3 @@ void zmq::object_t::send_command (command_t &cmd_)
|
||||
{
|
||||
ctx->send_command (cmd_.destination->get_tid (), cmd_);
|
||||
}
|
||||
|
||||
|
@@ -35,7 +35,6 @@
|
||||
|
||||
namespace zmq
|
||||
{
|
||||
|
||||
struct i_engine;
|
||||
struct endpoint_t;
|
||||
struct pending_connection_t;
|
||||
@@ -53,7 +52,6 @@ namespace zmq
|
||||
class object_t
|
||||
{
|
||||
public:
|
||||
|
||||
object_t (zmq::ctx_t *ctx_, uint32_t tid_);
|
||||
object_t (object_t *parent_);
|
||||
virtual ~object_t ();
|
||||
@@ -63,20 +61,20 @@ namespace zmq
|
||||
ctx_t *get_ctx ();
|
||||
void process_command (zmq::command_t &cmd_);
|
||||
void send_inproc_connected (zmq::socket_base_t *socket_);
|
||||
void send_bind (zmq::own_t *destination_, zmq::pipe_t *pipe_, bool inc_seqnum_ = true);
|
||||
void send_bind (zmq::own_t *destination_,
|
||||
zmq::pipe_t *pipe_,
|
||||
bool inc_seqnum_ = true);
|
||||
|
||||
protected:
|
||||
|
||||
// Using following function, socket is able to access global
|
||||
// repository of inproc endpoints.
|
||||
int register_endpoint (const char *addr_,
|
||||
const zmq::endpoint_t &endpoint_);
|
||||
int unregister_endpoint (
|
||||
const std::string &addr_, socket_base_t *socket_);
|
||||
int register_endpoint (const char *addr_, const zmq::endpoint_t &endpoint_);
|
||||
int unregister_endpoint (const std::string &addr_, socket_base_t *socket_);
|
||||
void unregister_endpoints (zmq::socket_base_t *socket_);
|
||||
zmq::endpoint_t find_endpoint (const char *addr_);
|
||||
void pend_connection (const std::string &addr_,
|
||||
const endpoint_t &endpoint, pipe_t **pipes_);
|
||||
const endpoint_t &endpoint,
|
||||
pipe_t **pipes_);
|
||||
void connect_pending (const char *addr_, zmq::socket_base_t *bind_socket_);
|
||||
|
||||
void destroy_socket (zmq::socket_base_t *socket_);
|
||||
@@ -90,21 +88,18 @@ namespace zmq
|
||||
// Derived object can use these functions to send commands
|
||||
// to other objects.
|
||||
void send_stop ();
|
||||
void send_plug (zmq::own_t *destination_,
|
||||
bool inc_seqnum_ = true);
|
||||
void send_own (zmq::own_t *destination_,
|
||||
zmq::own_t *object_);
|
||||
void send_plug (zmq::own_t *destination_, bool inc_seqnum_ = true);
|
||||
void send_own (zmq::own_t *destination_, zmq::own_t *object_);
|
||||
void send_attach (zmq::session_base_t *destination_,
|
||||
zmq::i_engine *engine_, bool inc_seqnum_ = true);
|
||||
zmq::i_engine *engine_,
|
||||
bool inc_seqnum_ = true);
|
||||
void send_activate_read (zmq::pipe_t *destination_);
|
||||
void send_activate_write (zmq::pipe_t *destination_,
|
||||
uint64_t msgs_read_);
|
||||
void send_activate_write (zmq::pipe_t *destination_, uint64_t msgs_read_);
|
||||
void send_hiccup (zmq::pipe_t *destination_, void *pipe_);
|
||||
void send_pipe_term (zmq::pipe_t *destination_);
|
||||
void send_pipe_term_ack (zmq::pipe_t *destination_);
|
||||
void send_pipe_hwm (zmq::pipe_t *destination_, int inhwm_, int outhwm_);
|
||||
void send_term_req (zmq::own_t *destination_,
|
||||
zmq::own_t *object_);
|
||||
void send_term_req (zmq::own_t *destination_, zmq::own_t *object_);
|
||||
void send_term (zmq::own_t *destination_, int linger_);
|
||||
void send_term_ack (zmq::own_t *destination_);
|
||||
void send_term_endpoint (own_t *destination_, std::string *endpoint_);
|
||||
@@ -138,7 +133,6 @@ namespace zmq
|
||||
virtual void process_seqnum ();
|
||||
|
||||
private:
|
||||
|
||||
// Context provides access to the global state.
|
||||
zmq::ctx_t *ctx;
|
||||
|
||||
@@ -150,7 +144,6 @@ namespace zmq
|
||||
object_t (const object_t &);
|
||||
const object_t &operator= (const object_t &);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
100
src/options.cpp
100
src/options.cpp
@@ -103,10 +103,11 @@ zmq::options_t::options_t () :
|
||||
#endif
|
||||
}
|
||||
|
||||
int zmq::options_t::set_curve_key(uint8_t * destination, const void * optval_, size_t optvallen_)
|
||||
int zmq::options_t::set_curve_key (uint8_t *destination,
|
||||
const void *optval_,
|
||||
size_t optvallen_)
|
||||
{
|
||||
switch (optvallen_) {
|
||||
|
||||
case CURVE_KEYSIZE:
|
||||
memcpy (destination, optval_, optvallen_);
|
||||
mechanism = ZMQ_CURVE;
|
||||
@@ -135,12 +136,14 @@ int zmq::options_t::set_curve_key(uint8_t * destination, const void * optval_, s
|
||||
return -1;
|
||||
}
|
||||
|
||||
int zmq::options_t::setsockopt (int option_, const void *optval_,
|
||||
int zmq::options_t::setsockopt (int option_,
|
||||
const void *optval_,
|
||||
size_t optvallen_)
|
||||
{
|
||||
bool is_int = (optvallen_ == sizeof (int));
|
||||
int value = 0;
|
||||
if (is_int) memcpy(&value, optval_, sizeof (int));
|
||||
if (is_int)
|
||||
memcpy (&value, optval_, sizeof (int));
|
||||
#if defined(ZMQ_ACT_MILITANT)
|
||||
bool malformed = true; // Did caller pass a bad option value?
|
||||
#endif
|
||||
@@ -308,9 +311,7 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
|
||||
if (optval_ == NULL && optvallen_ == 0) {
|
||||
socks_proxy_address.clear ();
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
if (optval_ != NULL && optvallen_ > 0 ) {
|
||||
} else if (optval_ != NULL && optvallen_ > 0) {
|
||||
socks_proxy_address =
|
||||
std::string ((const char *) optval_, optvallen_);
|
||||
return 0;
|
||||
@@ -356,9 +357,8 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
|
||||
if (optvallen_ == 0 && optval_ == NULL) {
|
||||
tcp_accept_filters.clear ();
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
if (optvallen_ > 0 && optvallen_ < 256 && optval_ != NULL && *((const char*) optval_) != 0) {
|
||||
} else if (optvallen_ > 0 && optvallen_ < 256 && optval_ != NULL
|
||||
&& *((const char *) optval_) != 0) {
|
||||
std::string filter_str ((const char *) optval_, optvallen_);
|
||||
tcp_address_mask_t mask;
|
||||
int rc = mask.resolve (filter_str.c_str (), ipv6);
|
||||
@@ -374,9 +374,7 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
|
||||
if (optvallen_ == 0 && optval_ == NULL) {
|
||||
ipc_uid_accept_filters.clear ();
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
if (optvallen_ == sizeof (uid_t) && optval_ != NULL) {
|
||||
} else if (optvallen_ == sizeof (uid_t) && optval_ != NULL) {
|
||||
ipc_uid_accept_filters.insert (*((uid_t *) optval_));
|
||||
return 0;
|
||||
}
|
||||
@@ -386,9 +384,7 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
|
||||
if (optvallen_ == 0 && optval_ == NULL) {
|
||||
ipc_gid_accept_filters.clear ();
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
if (optvallen_ == sizeof (gid_t) && optval_ != NULL) {
|
||||
} else if (optvallen_ == sizeof (gid_t) && optval_ != NULL) {
|
||||
ipc_gid_accept_filters.insert (*((gid_t *) optval_));
|
||||
return 0;
|
||||
}
|
||||
@@ -400,9 +396,7 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
|
||||
if (optvallen_ == 0 && optval_ == NULL) {
|
||||
ipc_pid_accept_filters.clear ();
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
if (optvallen_ == sizeof (pid_t) && optval_ != NULL) {
|
||||
} else if (optvallen_ == sizeof (pid_t) && optval_ != NULL) {
|
||||
ipc_pid_accept_filters.insert (*((pid_t *) optval_));
|
||||
return 0;
|
||||
}
|
||||
@@ -421,9 +415,7 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
|
||||
if (optvallen_ == 0 && optval_ == NULL) {
|
||||
mechanism = ZMQ_NULL;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
if (optvallen_ > 0 && optvallen_ < 256 && optval_ != NULL) {
|
||||
} else if (optvallen_ > 0 && optvallen_ < 256 && optval_ != NULL) {
|
||||
plain_username.assign ((const char *) optval_, optvallen_);
|
||||
as_server = 0;
|
||||
mechanism = ZMQ_PLAIN;
|
||||
@@ -435,9 +427,7 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
|
||||
if (optvallen_ == 0 && optval_ == NULL) {
|
||||
mechanism = ZMQ_NULL;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
if (optvallen_ > 0 && optvallen_ < 256 && optval_ != NULL) {
|
||||
} else if (optvallen_ > 0 && optvallen_ < 256 && optval_ != NULL) {
|
||||
plain_password.assign ((const char *) optval_, optvallen_);
|
||||
as_server = 0;
|
||||
mechanism = ZMQ_PLAIN;
|
||||
@@ -509,7 +499,8 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
|
||||
|
||||
case ZMQ_GSSAPI_SERVICE_PRINCIPAL:
|
||||
if (optvallen_ > 0 && optvallen_ < 256 && optval_ != NULL) {
|
||||
gss_service_principal.assign ((const char *) optval_, optvallen_);
|
||||
gss_service_principal.assign ((const char *) optval_,
|
||||
optvallen_);
|
||||
mechanism = ZMQ_GSSAPI;
|
||||
as_server = 0;
|
||||
return 0;
|
||||
@@ -524,7 +515,8 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
|
||||
break;
|
||||
|
||||
case ZMQ_GSSAPI_PRINCIPAL_NAMETYPE:
|
||||
if (is_int && (value == ZMQ_GSSAPI_NT_HOSTBASED
|
||||
if (is_int
|
||||
&& (value == ZMQ_GSSAPI_NT_HOSTBASED
|
||||
|| value == ZMQ_GSSAPI_NT_USER_NAME
|
||||
|| value == ZMQ_GSSAPI_NT_KRB5_PRINCIPAL)) {
|
||||
gss_principal_nt = value;
|
||||
@@ -533,7 +525,8 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
|
||||
break;
|
||||
|
||||
case ZMQ_GSSAPI_SERVICE_PRINCIPAL_NAMETYPE:
|
||||
if (is_int && (value == ZMQ_GSSAPI_NT_HOSTBASED
|
||||
if (is_int
|
||||
&& (value == ZMQ_GSSAPI_NT_HOSTBASED
|
||||
|| value == ZMQ_GSSAPI_NT_USER_NAME
|
||||
|| value == ZMQ_GSSAPI_NT_KRB5_PRINCIPAL)) {
|
||||
gss_service_principal_nt = value;
|
||||
@@ -620,11 +613,9 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
|
||||
if (optval_ == NULL && optvallen_ == 0) {
|
||||
bound_device.clear ();
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
if (optval_ != NULL && optvallen_ > 0 && optvallen_ <= BINDDEVSIZ) {
|
||||
bound_device =
|
||||
std::string ((const char *) optval_, optvallen_);
|
||||
} else if (optval_ != NULL && optvallen_ > 0
|
||||
&& optvallen_ <= BINDDEVSIZ) {
|
||||
bound_device = std::string ((const char *) optval_, optvallen_);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
@@ -658,7 +649,9 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
|
||||
return -1;
|
||||
}
|
||||
|
||||
int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_) const
|
||||
int zmq::options_t::getsockopt (int option_,
|
||||
void *optval_,
|
||||
size_t *optvallen_) const
|
||||
{
|
||||
bool is_int = (*optvallen_ == sizeof (int));
|
||||
int *value = (int *) optval_;
|
||||
@@ -839,7 +832,8 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_)
|
||||
|
||||
case ZMQ_SOCKS_PROXY:
|
||||
if (*optvallen_ >= socks_proxy_address.size () + 1) {
|
||||
memcpy (optval_, socks_proxy_address.c_str (), socks_proxy_address.size () + 1);
|
||||
memcpy (optval_, socks_proxy_address.c_str (),
|
||||
socks_proxy_address.size () + 1);
|
||||
*optvallen_ = socks_proxy_address.size () + 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -889,7 +883,8 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_)
|
||||
|
||||
case ZMQ_PLAIN_USERNAME:
|
||||
if (*optvallen_ >= plain_username.size () + 1) {
|
||||
memcpy (optval_, plain_username.c_str (), plain_username.size () + 1);
|
||||
memcpy (optval_, plain_username.c_str (),
|
||||
plain_username.size () + 1);
|
||||
*optvallen_ = plain_username.size () + 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -897,7 +892,8 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_)
|
||||
|
||||
case ZMQ_PLAIN_PASSWORD:
|
||||
if (*optvallen_ >= plain_password.size () + 1) {
|
||||
memcpy (optval_, plain_password.c_str (), plain_password.size () + 1);
|
||||
memcpy (optval_, plain_password.c_str (),
|
||||
plain_password.size () + 1);
|
||||
*optvallen_ = plain_password.size () + 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -924,10 +920,9 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_)
|
||||
if (*optvallen_ == CURVE_KEYSIZE) {
|
||||
memcpy (optval_, curve_public_key, CURVE_KEYSIZE);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
if (*optvallen_ == CURVE_KEYSIZE_Z85 + 1) {
|
||||
zmq_z85_encode ((char *) optval_, curve_public_key, CURVE_KEYSIZE);
|
||||
} else if (*optvallen_ == CURVE_KEYSIZE_Z85 + 1) {
|
||||
zmq_z85_encode ((char *) optval_, curve_public_key,
|
||||
CURVE_KEYSIZE);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
@@ -936,10 +931,9 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_)
|
||||
if (*optvallen_ == CURVE_KEYSIZE) {
|
||||
memcpy (optval_, curve_secret_key, CURVE_KEYSIZE);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
if (*optvallen_ == CURVE_KEYSIZE_Z85 + 1) {
|
||||
zmq_z85_encode ((char *) optval_, curve_secret_key, CURVE_KEYSIZE);
|
||||
} else if (*optvallen_ == CURVE_KEYSIZE_Z85 + 1) {
|
||||
zmq_z85_encode ((char *) optval_, curve_secret_key,
|
||||
CURVE_KEYSIZE);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
@@ -948,10 +942,9 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_)
|
||||
if (*optvallen_ == CURVE_KEYSIZE) {
|
||||
memcpy (optval_, curve_server_key, CURVE_KEYSIZE);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
if (*optvallen_ == CURVE_KEYSIZE_Z85 + 1) {
|
||||
zmq_z85_encode ((char *) optval_, curve_server_key, CURVE_KEYSIZE);
|
||||
} else if (*optvallen_ == CURVE_KEYSIZE_Z85 + 1) {
|
||||
zmq_z85_encode ((char *) optval_, curve_server_key,
|
||||
CURVE_KEYSIZE);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
@@ -975,7 +968,8 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_)
|
||||
|
||||
case ZMQ_GSSAPI_PRINCIPAL:
|
||||
if (*optvallen_ >= gss_principal.size () + 1) {
|
||||
memcpy (optval_, gss_principal.c_str (), gss_principal.size () + 1);
|
||||
memcpy (optval_, gss_principal.c_str (),
|
||||
gss_principal.size () + 1);
|
||||
*optvallen_ = gss_principal.size () + 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -983,7 +977,8 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_)
|
||||
|
||||
case ZMQ_GSSAPI_SERVICE_PRINCIPAL:
|
||||
if (*optvallen_ >= gss_service_principal.size () + 1) {
|
||||
memcpy (optval_, gss_service_principal.c_str (), gss_service_principal.size () + 1);
|
||||
memcpy (optval_, gss_service_principal.c_str (),
|
||||
gss_service_principal.size () + 1);
|
||||
*optvallen_ = gss_service_principal.size () + 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -1055,7 +1050,8 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_)
|
||||
|
||||
case ZMQ_BINDTODEVICE:
|
||||
if (*optvallen_ >= bound_device.size () + 1) {
|
||||
memcpy (optval_, bound_device.c_str (), bound_device.size () + 1);
|
||||
memcpy (optval_, bound_device.c_str (),
|
||||
bound_device.size () + 1);
|
||||
*optvallen_ = bound_device.size () + 1;
|
||||
return 0;
|
||||
}
|
||||
|
@@ -56,7 +56,9 @@ namespace zmq
|
||||
{
|
||||
options_t ();
|
||||
|
||||
int set_curve_key(uint8_t * destination, const void * optval_, size_t optvallen_);
|
||||
int set_curve_key (uint8_t *destination,
|
||||
const void *optval_,
|
||||
size_t optvallen_);
|
||||
|
||||
int setsockopt (int option_, const void *optval_, size_t optvallen_);
|
||||
int getsockopt (int option_, void *optval_, size_t *optvallen_) const;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user