0
0
mirror of https://github.com/zeromq/libzmq.git synced 2025-01-14 09:47:56 +08:00

Problem: Source files contain mixed tabs and spaces.

Solution: Convert to spaces and remove trailing whitespace in these files.
This commit is contained in:
Joe Eli McIlvain 2015-08-20 07:46:34 -07:00
parent 6aa5c20b3d
commit 61217a2686
22 changed files with 397 additions and 398 deletions

View File

@ -517,8 +517,8 @@ ZMQ_EXPORT void zmq_threadclose (void* thread);
#define ZMQ_UNUSED(object) (void)object
#define LIBZMQ_DELETE(p_object) {\
delete p_object; \
p_object = 0; \
delete p_object; \
p_object = 0; \
}
#undef ZMQ_EXPORT

View File

@ -45,10 +45,10 @@ namespace std
{
typedef unsigned char char_type;
// Unsigned as wint_t in unsigned.
typedef unsigned long int_type;
typedef streampos pos_type;
typedef streamoff off_type;
typedef mbstate_t state_type;
typedef unsigned long int_type;
typedef streampos pos_type;
typedef streamoff off_type;
typedef mbstate_t state_type;
static void
assign(char_type& __c1, const char_type& __c2)

View File

@ -149,16 +149,16 @@ uint64_t zmq::clock_t::now_us ()
// Use POSIX clock_gettime function to get precise monotonic time.
struct timespec tv;
int rc = clock_gettime (CLOCK_MONOTONIC, &tv);
// Fix case where system has clock_gettime but CLOCK_MONOTONIC is not supported.
// This should be a configuration check, but I looked into it and writing an
// AC_FUNC_CLOCK_MONOTONIC seems beyond my powers.
if( rc != 0) {
// Use POSIX gettimeofday function to get precise time.
struct timeval tv;
int rc = gettimeofday (&tv, NULL);
errno_assert (rc == 0);
return (tv.tv_sec * (uint64_t) 1000000 + tv.tv_usec);
}
// Fix case where system has clock_gettime but CLOCK_MONOTONIC is not supported.
// This should be a configuration check, but I looked into it and writing an
// AC_FUNC_CLOCK_MONOTONIC seems beyond my powers.
if( rc != 0) {
// Use POSIX gettimeofday function to get precise time.
struct timeval tv;
int rc = gettimeofday (&tv, NULL);
errno_assert (rc == 0);
return (tv.tv_sec * (uint64_t) 1000000 + tv.tv_usec);
}
return (tv.tv_sec * (uint64_t) 1000000 + tv.tv_nsec / 1000);
#elif defined HAVE_GETHRTIME

View File

@ -47,36 +47,36 @@
namespace zmq
{
class condition_variable_t
{
public:
inline condition_variable_t ()
{
zmq_assert(false);
}
class condition_variable_t
{
public:
inline condition_variable_t ()
{
zmq_assert(false);
}
inline ~condition_variable_t ()
{
inline ~condition_variable_t ()
{
}
}
inline int wait (mutex_t* mutex_, int timeout_ )
{
zmq_assert(false);
return -1;
}
inline int wait (mutex_t* mutex_, int timeout_ )
{
zmq_assert(false);
return -1;
}
inline void broadcast ()
{
zmq_assert(false);
}
inline void broadcast ()
{
zmq_assert(false);
}
private:
private:
// Disable copy construction and assignment.
condition_variable_t (const condition_variable_t&);
void operator = (const condition_variable_t&);
};
// Disable copy construction and assignment.
condition_variable_t (const condition_variable_t&);
void operator = (const condition_variable_t&);
};
}

View File

@ -98,7 +98,7 @@ namespace zmq
zmq::socket_base_t *create_socket (int type_);
void destroy_socket (zmq::socket_base_t *socket_);
// Start a new thread with proper scheduling parameters.
// Start a new thread with proper scheduling parameters.
void start_thread (thread_t &thread_, thread_fn *tfn_, void *arg_) const;
// Send command to the destination thread.
@ -203,7 +203,7 @@ namespace zmq
// Is IPv6 enabled on this context?
bool ipv6;
// Thread scheduling parameters.
// Thread scheduling parameters.
int thread_priority;
int thread_sched_policy;

View File

@ -178,7 +178,7 @@ int zmq::gssapi_mechanism_base_t::decode_message (msg_t *msg_)
const uint8_t flags = static_cast <char *> (plaintext.value)[0];
if (flags & 0x01)
msg_->set_flags (msg_t::more);
msg_->set_flags (msg_t::more);
if (flags & 0x02)
msg_->set_flags (msg_t::command);

View File

@ -123,7 +123,7 @@ int zmq::gssapi_server_t::process_handshake_command (msg_t *msg_)
}
if (security_context_established) {
// Use ZAP protocol (RFC 27) to authenticate the user.
// Use ZAP protocol (RFC 27) to authenticate the user.
bool expecting_zap_reply = false;
int rc = session->zap_connect ();
if (rc == 0) {

View File

@ -85,8 +85,8 @@ namespace zmq
void accept_context ();
int produce_next_token (msg_t *msg_);
int process_next_token (msg_t *msg_);
void send_zap_request ();
int receive_and_process_zap_reply();
void send_zap_request ();
int receive_and_process_zap_reply();
};
}

View File

@ -412,16 +412,16 @@ void zmq::mtrie_t::match (unsigned char *data_, size_t size_,
break;
// If there's one subnode (optimisation).
if (current->count == 1) {
if (current->count == 1) {
if (data_ [0] != current->min)
break;
current = current->next.node;
data_++;
size_--;
continue;
}
continue;
}
// If there are multiple subnodes.
// If there are multiple subnodes.
if (data_ [0] < current->min || data_ [0] >=
current->min + current->count)
break;

View File

@ -195,24 +195,24 @@ int zmq::pgm_socket_t::init (bool udp_encapsulation_, const char *network_)
}
{
const int rcvbuf = (int) options.rcvbuf;
if (rcvbuf >= 0) {
if (!pgm_setsockopt (sock, SOL_SOCKET, SO_RCVBUF, &rcvbuf,
sizeof (rcvbuf)))
goto err_abort;
}
const int rcvbuf = (int) options.rcvbuf;
if (rcvbuf >= 0) {
if (!pgm_setsockopt (sock, SOL_SOCKET, SO_RCVBUF, &rcvbuf,
sizeof (rcvbuf)))
goto err_abort;
}
const int sndbuf = (int) options.sndbuf;
if (sndbuf >= 0) {
if (!pgm_setsockopt (sock, SOL_SOCKET, SO_SNDBUF, &sndbuf,
sizeof (sndbuf)))
goto err_abort;
}
const int sndbuf = (int) options.sndbuf;
if (sndbuf >= 0) {
if (!pgm_setsockopt (sock, SOL_SOCKET, SO_SNDBUF, &sndbuf,
sizeof (sndbuf)))
goto err_abort;
}
const int max_tpdu = (int) pgm_max_tpdu;
if (!pgm_setsockopt (sock, IPPROTO_PGM, PGM_MTU, &max_tpdu,
sizeof (max_tpdu)))
goto err_abort;
const int max_tpdu = (int) pgm_max_tpdu;
if (!pgm_setsockopt (sock, IPPROTO_PGM, PGM_MTU, &max_tpdu,
sizeof (max_tpdu)))
goto err_abort;
}
if (receiver) {
@ -334,28 +334,28 @@ int zmq::pgm_socket_t::init (bool udp_encapsulation_, const char *network_)
// Set IP level parameters.
{
// Multicast loopback disabled by default
const int multicast_loop = 0;
if (!pgm_setsockopt (sock, IPPROTO_PGM, PGM_MULTICAST_LOOP,
&multicast_loop, sizeof (multicast_loop)))
goto err_abort;
// Multicast loopback disabled by default
const int multicast_loop = 0;
if (!pgm_setsockopt (sock, IPPROTO_PGM, PGM_MULTICAST_LOOP,
&multicast_loop, sizeof (multicast_loop)))
goto err_abort;
const int multicast_hops = options.multicast_hops;
if (!pgm_setsockopt (sock, IPPROTO_PGM, PGM_MULTICAST_HOPS,
&multicast_hops, sizeof (multicast_hops)))
goto err_abort;
const int multicast_hops = options.multicast_hops;
if (!pgm_setsockopt (sock, IPPROTO_PGM, PGM_MULTICAST_HOPS,
&multicast_hops, sizeof (multicast_hops)))
goto err_abort;
// Expedited Forwarding PHB for network elements, no ECN.
// Ignore return value due to varied runtime support.
const int dscp = 0x2e << 2;
if (AF_INET6 != sa_family)
pgm_setsockopt (sock, IPPROTO_PGM, PGM_TOS,
&dscp, sizeof (dscp));
// Expedited Forwarding PHB for network elements, no ECN.
// Ignore return value due to varied runtime support.
const int dscp = 0x2e << 2;
if (AF_INET6 != sa_family)
pgm_setsockopt (sock, IPPROTO_PGM, PGM_TOS,
&dscp, sizeof (dscp));
const int nonblocking = 1;
if (!pgm_setsockopt (sock, IPPROTO_PGM, PGM_NOBLOCK,
&nonblocking, sizeof (nonblocking)))
goto err_abort;
const int nonblocking = 1;
if (!pgm_setsockopt (sock, IPPROTO_PGM, PGM_NOBLOCK,
&nonblocking, sizeof (nonblocking)))
goto err_abort;
}
// Connect PGM transport to start state machine.

View File

@ -515,13 +515,13 @@ void zmq::pipe_t::set_hwms (int inhwm_, int outhwm_)
// if either send or recv side has hwm <= 0 it means infinite so we should set hwms infinite
if (inhwm_ <= 0 || inhwmboost <= 0)
in = 0;
in = 0;
if (outhwm_ <= 0 || outhwmboost <= 0)
out = 0;
out = 0;
lwm = compute_lwm(in);
hwm = out;
lwm = compute_lwm(in);
hwm = out;
}
void zmq::pipe_t::set_hwms_boost(int inhwmboost_, int outhwmboost_)

View File

@ -316,12 +316,11 @@ int zmq::socket_base_t::setsockopt (int option_, const void *optval_,
{
ENTER_MUTEX();
if (!options.is_valid(option_)) {
errno = EINVAL;
EXIT_MUTEX();
return -1;
}
if (!options.is_valid(option_)) {
errno = EINVAL;
EXIT_MUTEX();
return -1;
}
if (unlikely (ctx_terminated)) {
errno = ETERM;
@ -339,7 +338,7 @@ int zmq::socket_base_t::setsockopt (int option_, const void *optval_,
// If the socket type doesn't support the option, pass it to
// the generic option parser.
rc = options.setsockopt (option_, optval_, optvallen_);
update_pipe_options(option_);
update_pipe_options(option_);
EXIT_MUTEX();
return rc;
@ -1308,13 +1307,13 @@ void zmq::socket_base_t::process_term (int linger_)
void zmq::socket_base_t::update_pipe_options(int option_)
{
if (option_ == ZMQ_SNDHWM || option_ == ZMQ_RCVHWM)
{
for (pipes_t::size_type i = 0; i != pipes.size(); ++i)
{
pipes[i]->set_hwms(options.rcvhwm, options.sndhwm);
}
}
if (option_ == ZMQ_SNDHWM || option_ == ZMQ_RCVHWM)
{
for (pipes_t::size_type i = 0; i != pipes.size(); ++i)
{
pipes[i]->set_hwms(options.rcvhwm, options.sndhwm);
}
}
}

View File

@ -36,7 +36,7 @@
extern "C"
{
#if defined _WIN32_WCE
static DWORD thread_routine (LPVOID arg_)
static DWORD thread_routine (LPVOID arg_)
#else
static unsigned int __stdcall thread_routine (void *arg_)
#endif

View File

@ -40,17 +40,17 @@ zmq::xpub_t::xpub_t (class ctx_t *parent_, uint32_t tid_, int sid_) :
verbose_unsubs (false),
more (false),
lossy (true),
manual(false),
welcome_msg ()
manual(false),
welcome_msg ()
{
last_pipe = NULL;
last_pipe = NULL;
options.type = ZMQ_XPUB;
welcome_msg.init();
welcome_msg.init();
}
zmq::xpub_t::~xpub_t ()
{
welcome_msg.close();
welcome_msg.close();
}
void zmq::xpub_t::xattach_pipe (pipe_t *pipe_, bool subscribe_to_all_)
@ -63,16 +63,16 @@ void zmq::xpub_t::xattach_pipe (pipe_t *pipe_, bool subscribe_to_all_)
if (subscribe_to_all_)
subscriptions.add (NULL, 0, pipe_);
// if welcome message exist
if (welcome_msg.size() > 0)
{
msg_t copy;
copy.init();
copy.copy(welcome_msg);
// if welcome message exist
if (welcome_msg.size() > 0)
{
msg_t copy;
copy.init();
copy.copy(welcome_msg);
pipe_->write(&copy);
pipe_->flush();
}
pipe_->write(&copy);
pipe_->flush();
}
// The pipe is active when attached. Let's read the subscriptions from
// it, if any.
@ -88,31 +88,31 @@ void zmq::xpub_t::xread_activated (pipe_t *pipe_)
unsigned char *const data = (unsigned char *) sub.data ();
const size_t size = sub.size ();
if (size > 0 && (*data == 0 || *data == 1)) {
if (manual)
{
last_pipe = pipe_;
pending_data.push_back(blob_t(data, size));
if (manual)
{
last_pipe = pipe_;
pending_data.push_back(blob_t(data, size));
pending_metadata.push_back(sub.metadata());
pending_flags.push_back(0);
}
else
{
bool unique;
if (*data == 0)
unique = subscriptions.rm(data + 1, size - 1, pipe_);
else
unique = subscriptions.add(data + 1, size - 1, pipe_);
pending_flags.push_back(0);
}
else
{
bool unique;
if (*data == 0)
unique = subscriptions.rm(data + 1, size - 1, pipe_);
else
unique = subscriptions.add(data + 1, size - 1, pipe_);
// If the (un)subscription is not a duplicate store it so that it can be
// passed to the user on next recv call unless verbose mode is enabled
// which makes to pass always these messages.
if (options.type == ZMQ_XPUB && (unique || (*data == 1 && verbose_subs) ||
(*data == 0 && verbose_unsubs && verbose_subs))) {
pending_data.push_back(blob_t(data, size));
// If the (un)subscription is not a duplicate store it so that it can be
// passed to the user on next recv call unless verbose mode is enabled
// which makes to pass always these messages.
if (options.type == ZMQ_XPUB && (unique || (*data == 1 && verbose_subs) ||
(*data == 0 && verbose_unsubs && verbose_subs))) {
pending_data.push_back(blob_t(data, size));
pending_metadata.push_back(sub.metadata());
pending_flags.push_back(0);
}
}
pending_flags.push_back(0);
}
}
}
else {
// Process user message coming upstream from xsub socket
@ -132,45 +132,45 @@ void zmq::xpub_t::xwrite_activated (pipe_t *pipe_)
int zmq::xpub_t::xsetsockopt (int option_, const void *optval_,
size_t optvallen_)
{
if (option_ == ZMQ_XPUB_VERBOSE || option_ == ZMQ_XPUB_VERBOSE_UNSUBSCRIBE ||
option_ == ZMQ_XPUB_NODROP || option_ == ZMQ_XPUB_MANUAL)
{
if (optvallen_ != sizeof(int) || *static_cast <const int*> (optval_) < 0) {
errno = EINVAL;
return -1;
}
if (option_ == ZMQ_XPUB_VERBOSE || option_ == ZMQ_XPUB_VERBOSE_UNSUBSCRIBE ||
option_ == ZMQ_XPUB_NODROP || option_ == ZMQ_XPUB_MANUAL)
{
if (optvallen_ != sizeof(int) || *static_cast <const int*> (optval_) < 0) {
errno = EINVAL;
return -1;
}
if (option_ == ZMQ_XPUB_VERBOSE)
verbose_subs = (*static_cast <const int*> (optval_) != 0);
else
if (option_ == ZMQ_XPUB_VERBOSE_UNSUBSCRIBE)
verbose_unsubs = (*static_cast <const int*> (optval_) != 0);
else
if (option_ == ZMQ_XPUB_NODROP)
lossy = (*static_cast <const int*> (optval_) == 0);
else
if (option_ == ZMQ_XPUB_MANUAL)
manual = (*static_cast <const int*> (optval_) != 0);
}
if (option_ == ZMQ_XPUB_VERBOSE)
verbose_subs = (*static_cast <const int*> (optval_) != 0);
else
if (option_ == ZMQ_XPUB_VERBOSE_UNSUBSCRIBE)
verbose_unsubs = (*static_cast <const int*> (optval_) != 0);
else
if (option_ == ZMQ_XPUB_NODROP)
lossy = (*static_cast <const int*> (optval_) == 0);
else
if (option_ == ZMQ_XPUB_MANUAL)
manual = (*static_cast <const int*> (optval_) != 0);
}
else
if (option_ == ZMQ_SUBSCRIBE && manual && last_pipe != NULL)
subscriptions.add((unsigned char *)optval_, optvallen_, last_pipe);
else
if (option_ == ZMQ_UNSUBSCRIBE && manual && last_pipe != NULL)
subscriptions.rm((unsigned char *)optval_, optvallen_, last_pipe);
else
if (option_ == ZMQ_XPUB_WELCOME_MSG) {
welcome_msg.close();
if (option_ == ZMQ_SUBSCRIBE && manual && last_pipe != NULL)
subscriptions.add((unsigned char *)optval_, optvallen_, last_pipe);
else
if (option_ == ZMQ_UNSUBSCRIBE && manual && last_pipe != NULL)
subscriptions.rm((unsigned char *)optval_, optvallen_, last_pipe);
else
if (option_ == ZMQ_XPUB_WELCOME_MSG) {
welcome_msg.close();
if (optvallen_ > 0) {
welcome_msg.init_size(optvallen_);
if (optvallen_ > 0) {
welcome_msg.init_size(optvallen_);
unsigned char *data = (unsigned char*)welcome_msg.data();
memcpy(data, optval_, optvallen_);
}
else
welcome_msg.init();
}
unsigned char *data = (unsigned char*)welcome_msg.data();
memcpy(data, optval_, optvallen_);
}
else
welcome_msg.init();
}
else {
errno = EINVAL;
return -1;
@ -245,10 +245,10 @@ int zmq::xpub_t::xrecv (msg_t *msg_)
pending_data.front ().data (),
pending_data.front ().size ());
// set metadata only if there is some
if (metadata_t* metadata = pending_metadata.front ()) {
msg_->set_metadata (metadata);
}
// set metadata only if there is some
if (metadata_t* metadata = pending_metadata.front ()) {
msg_->set_metadata (metadata);
}
msg_->set_flags (pending_flags.front ());
pending_data.pop_front ();

View File

@ -96,14 +96,14 @@ namespace zmq
// Drop messages if HWM reached, otherwise return with EAGAIN
bool lossy;
// Subscriptions will not bed added automatically, only after calling set option with ZMQ_SUBSCRIBE or ZMQ_UNSUBSCRIBE
bool manual;
// Subscriptions will not bed added automatically, only after calling set option with ZMQ_SUBSCRIBE or ZMQ_UNSUBSCRIBE
bool manual;
// Last pipe send subscription message, only used if xpub is on manual
pipe_t *last_pipe;
// Last pipe send subscription message, only used if xpub is on manual
pipe_t *last_pipe;
// Welcome message to send to pipe when attached
msg_t welcome_msg;
// Welcome message to send to pipe when attached
msg_t welcome_msg;
// List of pending (un)subscriptions, ie. those that were already
// applied to the trie, but not yet received by the user.

View File

@ -183,7 +183,7 @@ int main (void)
{
setup_test_environment ();
test_stream_2_stream ();
test_stream_2_stream ();
test_router_2_router (false);
test_router_2_router (true);

View File

@ -71,14 +71,14 @@ int main (void)
zmq_recvmsg(rep, &msg, 0);
assert(zmq_msg_size(&msg) == MSG_SIZE);
// get the messages source file descriptor
// get the messages source file descriptor
int srcFd = zmq_msg_get(&msg, ZMQ_SRCFD);
assert(srcFd >= 0);
rc = zmq_msg_close(&msg);
assert (rc == 0);
// get the remote endpoint
// get the remote endpoint
struct sockaddr_storage ss;
#ifdef ZMQ_HAVE_HPUX
int addrlen = sizeof ss;
@ -92,7 +92,7 @@ int main (void)
rc = getnameinfo ((struct sockaddr*) &ss, addrlen, host, sizeof host, NULL, 0, NI_NUMERICHOST);
assert (rc == 0);
// assert it is localhost which connected
// assert it is localhost which connected
assert (strcmp(host, "127.0.0.1") == 0);
rc = zmq_close (rep);
@ -100,10 +100,10 @@ int main (void)
rc = zmq_close (req);
assert (rc == 0);
// sleep a bit for the socket to be freed
usleep(30000);
// sleep a bit for the socket to be freed
usleep(30000);
// getting name from closed socket will fail
// getting name from closed socket will fail
rc = getpeername (srcFd, (struct sockaddr*) &ss, &addrlen);
assert (rc == -1);
assert (errno == EBADF);

View File

@ -165,18 +165,18 @@ int main(int, char**)
// Grab the 1st frame (peer identity).
zmq_msg_t peer_frame;
rc = zmq_msg_init (&peer_frame);
assert (rc == 0);
assert (rc == 0);
rc = zmq_msg_recv (&peer_frame, sockets [SERVER], 0);
assert (rc != -1);
assert(zmq_msg_size (&peer_frame) > 0);
assert (rc != -1);
assert(zmq_msg_size (&peer_frame) > 0);
assert (has_more (sockets [SERVER]));
// Grab the 2nd frame (actual payload).
zmq_msg_t data_frame;
rc = zmq_msg_init (&data_frame);
assert (rc == 0);
assert (rc == 0);
rc = zmq_msg_recv (&data_frame, sockets [SERVER], 0);
assert (rc != -1);
assert (rc != -1);
// Make sure payload matches what we expect.
const char * const data = (const char*)zmq_msg_data (&data_frame);
@ -184,39 +184,39 @@ int main(int, char**)
// 0-length frame is a disconnection notification. The server
// should receive it as the last step in the dialogue.
if (size == 0) {
++step;
++step;
assert (step == steps);
}
else {
assert ((size_t) size == strlen (dialog [step].text));
int cmp = memcmp (dialog [step].text, data, size);
assert (cmp == 0);
assert ((size_t) size == strlen (dialog [step].text));
int cmp = memcmp (dialog [step].text, data, size);
assert (cmp == 0);
++step;
++step;
assert (step < steps);
// Prepare the response.
rc = zmq_msg_close (&data_frame);
assert (rc == 0);
assert (rc == 0);
rc = zmq_msg_init_size (&data_frame,
strlen (dialog [step].text));
assert (rc == 0);
strlen (dialog [step].text));
assert (rc == 0);
memcpy (zmq_msg_data (&data_frame), dialog [step].text,
zmq_msg_size (&data_frame));
zmq_msg_size (&data_frame));
// Send the response.
rc = zmq_msg_send (&peer_frame, sockets [SERVER], ZMQ_SNDMORE);
assert (rc != -1);
assert (rc != -1);
rc = zmq_msg_send (&data_frame, sockets [SERVER], ZMQ_SNDMORE);
assert (rc != -1);
assert (rc != -1);
}
// Release resources.
rc = zmq_msg_close (&peer_frame);
assert (rc == 0);
assert (rc == 0);
rc = zmq_msg_close (&data_frame);
assert (rc == 0);
assert (rc == 0);
}
// Check for data received by the client.
@ -226,24 +226,24 @@ int main(int, char**)
// Grab the 1st frame (peer identity).
zmq_msg_t peer_frame;
rc = zmq_msg_init (&peer_frame);
assert (rc == 0);
assert (rc == 0);
rc = zmq_msg_recv (&peer_frame, sockets [CLIENT], 0);
assert (rc != -1);
assert(zmq_msg_size (&peer_frame) > 0);
assert (rc != -1);
assert(zmq_msg_size (&peer_frame) > 0);
assert (has_more (sockets [CLIENT]));
// Grab the 2nd frame (actual payload).
zmq_msg_t data_frame;
rc = zmq_msg_init (&data_frame);
assert (rc == 0);
assert (rc == 0);
rc = zmq_msg_recv (&data_frame, sockets [CLIENT], 0);
assert (rc != -1);
assert(zmq_msg_size (&data_frame) > 0);
assert (rc != -1);
assert(zmq_msg_size (&data_frame) > 0);
// Make sure payload matches what we expect.
const char * const data = (const char*)zmq_msg_data (&data_frame);
const int size = zmq_msg_size (&data_frame);
assert ((size_t)size == strlen(dialog [step].text));
assert ((size_t)size == strlen(dialog [step].text));
int cmp = memcmp(dialog [step].text, data, size);
assert (cmp == 0);
@ -252,22 +252,22 @@ int main(int, char**)
// Prepare the response (next line in the dialog).
assert (step < steps);
rc = zmq_msg_close (&data_frame);
assert (rc == 0);
assert (rc == 0);
rc = zmq_msg_init_size (&data_frame, strlen (dialog [step].text));
assert (rc == 0);
assert (rc == 0);
memcpy (zmq_msg_data (&data_frame), dialog [step].text, zmq_msg_size (&data_frame));
// Send the response.
rc = zmq_msg_send (&peer_frame, sockets [CLIENT], ZMQ_SNDMORE);
assert (rc != -1);
assert (rc != -1);
rc = zmq_msg_send (&data_frame, sockets [CLIENT], ZMQ_SNDMORE);
assert (rc != -1);
assert (rc != -1);
// Release resources.
rc = zmq_msg_close (&peer_frame);
assert (rc == 0);
assert (rc == 0);
rc = zmq_msg_close (&data_frame);
assert (rc == 0);
assert (rc == 0);
}
}
assert (step == steps);

View File

@ -56,42 +56,42 @@ int main (void)
rc = zmq_connect (client2, "tcp://127.0.0.1:5560");
assert (rc == 0);
void* t1 = zmq_threadstart(worker1, client2);
void* t2 = zmq_threadstart(worker2, client2);
void* t1 = zmq_threadstart(worker1, client2);
void* t2 = zmq_threadstart(worker2, client2);
char data[1];
data[0] = 0;
char data[1];
data[0] = 0;
for (int i=0; i < 10; i++) {
rc = zmq_send_const(client, data, 1, 0);
assert (rc == 1);
for (int i=0; i < 10; i++) {
rc = zmq_send_const(client, data, 1, 0);
assert (rc == 1);
rc = zmq_send_const(client, data, 1, 0);
assert(rc == 1);
rc = zmq_send_const(client, data, 1, 0);
assert(rc == 1);
char a, b;
char a, b;
rc = zmq_recv(client, &a, 1, 0);
assert(rc == 1);
rc = zmq_recv(client, &a, 1, 0);
assert(rc == 1);
rc = zmq_recv(client, &b, 1, 0);
assert(rc == 1);
rc = zmq_recv(client, &b, 1, 0);
assert(rc == 1);
// make sure they came from different threads
assert((a == 1 && b == 2) || (a == 2 && b == 1));
}
// make sure they came from different threads
assert((a == 1 && b == 2) || (a == 2 && b == 1));
}
// make the thread exit
data[0] = 1;
// make the thread exit
data[0] = 1;
rc = zmq_send_const(client, data, 1, 0);
assert (rc == 1);
rc = zmq_send_const(client, data, 1, 0);
assert (rc == 1);
rc = zmq_send_const(client, data, 1, 0);
assert(rc == 1);
rc = zmq_send_const(client, data, 1, 0);
assert(rc == 1);
zmq_threadclose(t1);
zmq_threadclose(t2);
zmq_threadclose(t1);
zmq_threadclose(t2);
rc = zmq_close (client2);
assert (rc == 0);
@ -107,52 +107,52 @@ int main (void)
void worker1(void* s)
{
const char worker_id = 1;
char c;
const char worker_id = 1;
char c;
while (true)
{
int rc = zmq_recv(s, &c,1, 0);
assert(rc == 1);
while (true)
{
int rc = zmq_recv(s, &c,1, 0);
assert(rc == 1);
if (c == 0)
{
msleep(100);
rc = zmq_send_const(s,&worker_id, 1, 0);
assert(rc == 1);
}
else
{
// we got exit request
break;
}
}
if (c == 0)
{
msleep(100);
rc = zmq_send_const(s,&worker_id, 1, 0);
assert(rc == 1);
}
else
{
// we got exit request
break;
}
}
}
void worker2(void* s)
{
const char worker_id = 2;
char c;
const char worker_id = 2;
char c;
while (true)
{
int rc = zmq_recv(s, &c,1, 0);
assert(rc == 1);
while (true)
{
int rc = zmq_recv(s, &c,1, 0);
assert(rc == 1);
assert(c == 1 || c == 0);
assert(c == 1 || c == 0);
if (c == 0)
{
msleep(100);
rc = zmq_send_const(s,&worker_id, 1, 0);
assert(rc == 1);
}
else
{
// we got exit request
break;
}
}
if (c == 0)
{
msleep(100);
rc = zmq_send_const(s,&worker_id, 1, 0);
assert(rc == 1);
}
else
{
// we got exit request
break;
}
}
}

View File

@ -43,7 +43,7 @@ int main (void)
// set pub socket options
int manual = 1;
rc = zmq_setsockopt(pub, ZMQ_XPUB_MANUAL, &manual, 4);
rc = zmq_setsockopt(pub, ZMQ_XPUB_MANUAL, &manual, 4);
assert (rc == 0);
// Create a subscriber
@ -53,32 +53,32 @@ int main (void)
assert (rc == 0);
// Subscribe for A
char subscription[2] = { 1, 'A'};
rc = zmq_send_const(sub, subscription, 2, 0);
char subscription[2] = { 1, 'A'};
rc = zmq_send_const(sub, subscription, 2, 0);
assert (rc == 2);
char buffer[2];
char buffer[2];
// Receive subscriptions from subscriber
rc = zmq_recv(pub, buffer, 2, 0);
assert(rc == 2);
assert(buffer[0] == 1);
assert(buffer[1] == 'A');
// Receive subscriptions from subscriber
rc = zmq_recv(pub, buffer, 2, 0);
assert(rc == 2);
assert(buffer[0] == 1);
assert(buffer[1] == 'A');
// Subscribe socket for B instead
rc = zmq_setsockopt(pub, ZMQ_SUBSCRIBE, "B", 1);
assert(rc == 0);
// Subscribe socket for B instead
rc = zmq_setsockopt(pub, ZMQ_SUBSCRIBE, "B", 1);
assert(rc == 0);
// Sending A message and B Message
rc = zmq_send_const(pub, "A", 1, 0);
assert(rc == 1);
// Sending A message and B Message
rc = zmq_send_const(pub, "A", 1, 0);
assert(rc == 1);
rc = zmq_send_const(pub, "B", 1, 0);
assert(rc == 1);
rc = zmq_send_const(pub, "B", 1, 0);
assert(rc == 1);
rc = zmq_recv(sub, buffer, 1, ZMQ_DONTWAIT);
assert(rc == 1);
assert(buffer[0] == 'B');
rc = zmq_recv(sub, buffer, 1, ZMQ_DONTWAIT);
assert(rc == 1);
assert(buffer[0] == 'B');
// Clean up.
rc = zmq_close (pub);

View File

@ -42,7 +42,7 @@ int main (void)
assert (rc == 0);
// set pub socket options
rc = zmq_setsockopt(pub, ZMQ_XPUB_WELCOME_MSG, "W", 1);
rc = zmq_setsockopt(pub, ZMQ_XPUB_WELCOME_MSG, "W", 1);
assert (rc == 0);
// Create a subscriber