本文整理汇总了C++中zsock_resolve函数的典型用法代码示例。如果您正苦于以下问题:C++ zsock_resolve函数的具体用法?C++ zsock_resolve怎么用?C++ zsock_resolve使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zsock_resolve函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: s_self_switch
static void
s_self_switch (self_t *self, zsock_t *input, zsock_t *output)
{
// We use the low-level libzmq API for best performance
void *zmq_input = zsock_resolve (input);
void *zmq_output = zsock_resolve (output);
void *zmq_capture = self->capture ? zsock_resolve (self->capture) : NULL;
zmq_msg_t msg;
zmq_msg_init (&msg);
while (true) {
if (zmq_recvmsg (zmq_input, &msg, ZMQ_DONTWAIT) == -1)
break; // Presumably EAGAIN
int send_flags = zsock_rcvmore (zmq_input) ? ZMQ_SNDMORE : 0;
if (zmq_capture) {
zmq_msg_t dup;
zmq_msg_init (&dup);
zmq_msg_copy (&dup, &msg);
if (zmq_sendmsg (zmq_capture, &dup, send_flags) == -1)
zmq_msg_close (&dup);
}
if (zmq_sendmsg (zmq_output, &msg, send_flags) == -1) {
zmq_msg_close (&msg);
break;
}
}
}
示例2: zmailer_msg_send
int
zmailer_msg_send (zmailer_msg_t *self, zsock_t *output)
{
assert (self);
assert (output);
if (zsock_type (output) == ZMQ_ROUTER)
zframe_send (&self->routing_id, output, ZFRAME_MORE + ZFRAME_REUSE);
size_t frame_size = 2 + 1; // Signature and message ID
switch (self->id) {
case ZMAILER_MSG_MAIL:
frame_size += 2; // version
frame_size += 1 + strlen (self->from);
frame_size += 4;
if (self->to)
frame_size += strlen (self->to);
frame_size += 4;
if (self->subject)
frame_size += strlen (self->subject);
frame_size += 4;
if (self->request)
frame_size += strlen (self->request);
break;
}
// Now serialize message into the frame
zmq_msg_t frame;
zmq_msg_init_size (&frame, frame_size);
self->needle = (byte *) zmq_msg_data (&frame);
PUT_NUMBER2 (0xAAA0 | 0);
PUT_NUMBER1 (self->id);
size_t nbr_frames = 1; // Total number of frames to send
switch (self->id) {
case ZMAILER_MSG_MAIL:
PUT_NUMBER2 (1);
PUT_STRING (self->from);
if (self->to) {
PUT_LONGSTR (self->to);
}
else
PUT_NUMBER4 (0); // Empty string
if (self->subject) {
PUT_LONGSTR (self->subject);
}
else
PUT_NUMBER4 (0); // Empty string
if (self->request) {
PUT_LONGSTR (self->request);
}
else
PUT_NUMBER4 (0); // Empty string
break;
}
// Now send the data frame
zmq_msg_send (&frame, zsock_resolve (output), --nbr_frames? ZMQ_SNDMORE: 0);
return 0;
}
示例3: zmsg_send
int
zmsg_send (zmsg_t **self_p, void *dest)
{
assert (self_p);
assert (dest);
zmsg_t *self = *self_p;
int rc = 0;
void *handle = zsock_resolve (dest);
if (self) {
assert (zmsg_is (self));
if (zlist_size (self->frames) == 0)
return -1; // Sending an empty message is an error
zframe_t *frame = (zframe_t *) zlist_pop (self->frames);
while (frame) {
rc = zframe_send (&frame, handle,
zlist_size (self->frames)? ZFRAME_MORE: 0);
if (rc != 0)
break;
frame = (zframe_t *) zlist_pop (self->frames);
}
zmsg_destroy (self_p);
}
return rc;
}
示例4: zpoller_remove
int
zpoller_remove (zpoller_t *self, void *reader)
{
assert (self);
assert (reader);
int rc = 0;
#ifdef ZMQ_HAVE_POLLER
void *socket = zsock_resolve (reader);
if (socket)
rc = zmq_poller_remove (self->zmq_poller, socket);
else
rc = zmq_poller_remove_fd (self->zmq_poller, *(SOCKET *) reader);
#else
size_t num_readers_before = zlist_size (self->reader_list);
zlist_remove (self->reader_list, reader); // won't fail with non-existent reader
size_t num_readers_after = zlist_size (self->reader_list);
if (num_readers_before != num_readers_after)
self->need_rebuild = true;
else {
errno = EINVAL;
rc = -1;
}
#endif
return rc;
}
示例5: zstr_recvx
int
zstr_recvx (void *source, char **string_p, ...)
{
assert (source);
void *handle = zsock_resolve (source);
zmsg_t *msg = zmsg_recv (handle);
if (!msg)
return -1;
// Filter a signal that may come from a dying actor
if (zmsg_signal (msg) >= 0) {
zmsg_destroy (&msg);
return -1;
}
int count = 0;
va_list args;
va_start (args, string_p);
while (string_p) {
*string_p = zmsg_popstr (msg);
string_p = va_arg (args, char **);
count++;
}
va_end (args);
zmsg_destroy (&msg);
return count;
}
示例6: mdp_client_getsockopt
int
mdp_client_getsockopt (mdp_client_t *self, int option, void *optval, size_t *optvallen)
{
assert (self);
assert (self->client);
return zmq_getsockopt (zsock_resolve(self->client), option, optval, optvallen);
}
示例7: s_rebuild_poll_set
static int
s_rebuild_poll_set (zpoller_t *self)
{
freen (self->poll_set);
self->poll_set = NULL;
freen (self->poll_readers);
self->poll_readers = NULL;
self->poll_size = zlist_size (self->reader_list);
self->poll_set = (zmq_pollitem_t *)
zmalloc (self->poll_size * sizeof (zmq_pollitem_t));
self->poll_readers = (void **) zmalloc (self->poll_size * sizeof (void *));
if (!self->poll_set || !self->poll_readers)
return -1;
uint reader_nbr = 0;
void *reader = zlist_first (self->reader_list);
while (reader) {
self->poll_readers [reader_nbr] = reader;
void *socket = zsock_resolve (reader);
if (socket == NULL) {
self->poll_set [reader_nbr].socket = NULL;
self->poll_set [reader_nbr].fd = *(SOCKET *) reader;
}
else
self->poll_set [reader_nbr].socket = socket;
self->poll_set [reader_nbr].events = ZMQ_POLLIN;
reader_nbr++;
reader = zlist_next (self->reader_list);
}
self->need_rebuild = false;
return 0;
}
示例8: zgossip_msg_send
int
zgossip_msg_send (zgossip_msg_t **self_p, void *output)
{
assert (self_p);
assert (*self_p);
assert (output);
// Save routing_id if any, as encode will destroy it
zgossip_msg_t *self = *self_p;
zframe_t *routing_id = self->routing_id;
self->routing_id = NULL;
// Encode zgossip_msg message to a single zmsg
zmsg_t *msg = zgossip_msg_encode (&self);
// If we're sending to a ROUTER, send the routing_id first
if (zsocket_type (zsock_resolve (output)) == ZMQ_ROUTER) {
assert (routing_id);
zmsg_prepend (msg, &routing_id);
}
else
zframe_destroy (&routing_id);
if (msg && zmsg_send (&msg, output) == 0)
return 0;
else
return -1; // Failed to encode, or send
}
示例9: zactor_resolve
void *
zactor_resolve (void *self)
{
assert (self);
if (zactor_is (self))
return zsock_resolve (((zactor_t *) self)->pipe);
else
return self;
}
示例10: s_self_new
static self_t *
s_self_new (zsock_t *pipe, zsock_t *sock)
{
self_t *self = (self_t *) zmalloc (sizeof (self_t));
self->pipe = pipe;
self->monitored = zsock_resolve (sock);
self->poller = zpoller_new (self->pipe, NULL);
return self;
}
示例11: zgossip_msg_recv_nowait
zgossip_msg_t *
zgossip_msg_recv_nowait (void *input)
{
assert (input);
zmsg_t *msg = zmsg_recv_nowait (input);
// If message came from a router socket, first frame is routing_id
zframe_t *routing_id = NULL;
if (zsocket_type (zsock_resolve (input)) == ZMQ_ROUTER) {
routing_id = zmsg_pop (msg);
// If message was not valid, forget about it
if (!routing_id || !zmsg_next (msg))
return NULL; // Malformed or empty
}
zgossip_msg_t * zgossip_msg = zgossip_msg_decode (&msg);
if (zsocket_type (zsock_resolve (input)) == ZMQ_ROUTER)
zgossip_msg->routing_id = routing_id;
return zgossip_msg;
}
示例12: zcert_apply
void
zcert_apply (zcert_t *self, void *zocket)
{
assert (self);
#if (ZMQ_VERSION_MAJOR == 4)
void *handle = zsock_resolve (zocket);
if (zsys_has_curve ()) {
zsocket_set_curve_secretkey_bin (handle, self->secret_key);
zsocket_set_curve_publickey_bin (handle, self->public_key);
}
#endif
}
示例13: s_self_new
static self_t *
s_self_new (zsock_t *pipe, void *sock)
{
self_t *self = (self_t *) zmalloc (sizeof (self_t));
if (!self)
return NULL;
self->pipe = pipe;
self->monitored = zsock_resolve (sock);
self->poller = zpoller_new (self->pipe, NULL);
if (!self->poller)
s_self_destroy (&self);
return self;
}
示例14: zyre_peer_connect
void
zyre_peer_connect (zyre_peer_t *self, zuuid_t *from, const char *endpoint)
{
assert (self);
assert (!self->connected);
// Create new outgoing socket (drop any messages in transit)
self->mailbox = zsock_new (ZMQ_DEALER);
if (!self->mailbox)
return; // Null when we're shutting down
// Set our own identity on the socket so that receiving node
// knows who each message came from. Note that we cannot use
// the UUID directly as the identity since it may contain a
// zero byte at the start, which libzmq does not like for
// historical and arguably bogus reasons that it nonetheless
// enforces.
byte routing_id [ZUUID_LEN + 1] = { 1 };
memcpy (routing_id + 1, zuuid_data (from), ZUUID_LEN);
int rc = zmq_setsockopt (zsock_resolve (self->mailbox),
ZMQ_IDENTITY, routing_id, ZUUID_LEN + 1);
assert (rc == 0);
// Set a high-water mark that allows for reasonable activity
zsock_set_sndhwm (self->mailbox, PEER_EXPIRED * 100);
// Send messages immediately or return EAGAIN
zsock_set_sndtimeo (self->mailbox, 0);
// Connect through to peer node
rc = zsock_connect (self->mailbox, "%s", endpoint);
if (rc != 0) {
zsys_error ("(%s) cannot connect to endpoint=%s",
self->origin, endpoint);
// Don't really have any error handling yet; if connect
// fails, there's something wrong with connect endpoint?
assert (false);
}
assert (rc == 0);
if (self->verbose)
zsys_info ("(%s) connect to peer: endpoint=%s",
self->origin, endpoint);
self->endpoint = strdup (endpoint);
self->connected = true;
self->ready = false;
}
示例15: s_send_string
static int
s_send_string (void *dest, bool more, char *string)
{
assert (dest);
void *handle = zsock_resolve (dest);
size_t len = strlen (string);
zmq_msg_t message;
zmq_msg_init_size (&message, len);
memcpy (zmq_msg_data (&message), string, len);
if (zmq_sendmsg (handle, &message, more ? ZMQ_SNDMORE : 0) == -1) {
zmq_msg_close (&message);
return -1;
}
else
return 0;
}