本文整理汇总了C++中zmsg_first函数的典型用法代码示例。如果您正苦于以下问题:C++ zmsg_first函数的具体用法?C++ zmsg_first怎么用?C++ zmsg_first使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zmsg_first函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: process_meta_information_and_handle_heartbeat
static
int process_meta_information_and_handle_heartbeat(subscriber_state_t *state, zmsg_t* msg)
{
zframe_t *first = zmsg_first(msg);
char *pub_spec = NULL;
bool is_heartbeat = zframe_streq(first, "heartbeat");
msg_meta_t meta;
int rc = msg_extract_meta_info(msg, &meta);
if (!rc) {
// dump_meta_info(&meta);
if (!state->meta_info_failures++)
fprintf(stderr, "[E] subscriber: received invalid meta info\n");
return is_heartbeat;
}
if (meta.device_number == 0) {
// ignore device number 0
state->messages_dev_zero++;
return is_heartbeat;
}
if (is_heartbeat) {
if (debug)
printf("received heartbeat from device %d\n", meta.device_number);
zmsg_first(msg); // msg_extract_meta_info repositions the pointer, so reset
zframe_t *spec_frame = zmsg_next(msg);
pub_spec = zframe_strdup(spec_frame);
}
state->message_gap_size += device_tracker_calculate_gap(state->tracker, &meta, pub_spec);
return is_heartbeat;
}
示例2: pss_response
void pss_response(void *spss, req_store_t * req_store, void *sweb, void *sgraph)
{
zmsg_t *msg = zmsg_recv(spss);
zframe_t *null = zmsg_unwrap(msg);
zframe_destroy(&null);
json_error_t error;
printf("\nbroker:spss received: %s\n",
(const char *)zframe_data(zmsg_first(msg)));
const char *data;
size_t data_size = zframe_size(zmsg_first(msg));
data = zframe_data(zmsg_first(msg));
json_t *pss_resp_json = json_loadb(data,
data_size, 0, &error);
zmsg_destroy(&msg);
//identify the request
int32_t requestId =
json_integer_value(json_object_get(pss_resp_json, "requestId"));
req_t *req = request_store_req(req_store, requestId);
json_t *response = json_object_get(pss_resp_json, "response");
json_incref(response);
json_decref(pss_resp_json);
const char *resp_type =
json_string_value(json_object_get(response, "type"));
const char *req_type =
json_string_value(json_object_get
(json_object_get
(json_object_get(req->request, "clientRequest"),
"request"), "type"));
if ((strcmp(resp_type, "searchResponse") == 0)
&& (strcmp(req_type, "searchRequest") == 0))
pss_response_searchResponse(req, response, requestId, sgraph);
else if ((strcmp(resp_type, "newNodeResponse") == 0)
&& (strcmp(req_type, "newNode") == 0))
pss_response_newNodeResponse(req, response, requestId, sweb,
req_store);
else if ((strcmp(resp_type, "delNode") == 0)
&& (strcmp(req_type, "delNode") == 0))
pss_response_delNode(req, response, requestId, sweb, req_store);
else {
}
}
示例3: s_handle_backend
// Handle input from worker, on backend
int s_handle_backend(zloop_t *loop, zmq_pollitem_t *poller, void *arg)
{
// Use worker identity for load-balancing
lbbroker_t *self = (lbbroker_t *)arg;
zmsg_t *msg = zmsg_recv(self->backend);
if (msg) {
zframe_t *identity = zmsg_unwrap(msg);
zlist_append(self->workers, identity);
// Enable reader on frontend if we went from 0 to 1 workers
if (zlist_size(self->workers) == 1) {
zmq_pollitem_t poller = { self->frontend, 0, ZMQ_POLLIN };
zloop_poller(loop, &poller, s_handle_frontend, self);
}
// Forward message to client if it's not a READY
zframe_t *frame = zmsg_first(msg);
if (memcmp(zframe_data(frame), WORKER_READY, strlen(WORKER_READY)) == 0) {
zmsg_destroy(&msg);
} else {
zmsg_send(&msg, self->frontend);
}
}
return 0;
}
示例4: zsock_wait
int
zsock_wait (void *self)
{
assert (self);
// A signal is a message containing one frame with our 8-byte magic
// value. If we get anything else, we discard it and continue to look
// for the signal message
while (true) {
zmsg_t *msg = zmsg_recv (self);
if (!msg)
return -1;
if (zmsg_size (msg) == 1
&& zmsg_content_size (msg) == 8) {
zframe_t *frame = zmsg_first (msg);
int64_t signal_value = *((int64_t *) zframe_data (frame));
if ((signal_value & 0xFFFFFFFFFFFFFF00L) == 0x7766554433221100L) {
zmsg_destroy (&msg);
return signal_value & 255;
}
}
zmsg_destroy (&msg);
}
return -1;
}
示例5: download_data
/* ================ download_data() ================ */
int download_data(zsock_t *sock, const char *key)
{
/* ---------------- Send Message ---------------- */
zmsg_t *download_msg = create_action_message(MSG_ACTION_GET);
message_add_key_data(download_msg, key, "", 0);
zmsg_send(&download_msg, sock);
/* ---------------- Receive Message ---------------- */
zmsg_t *recv_msg = zmsg_recv(sock);
if ( recv_msg == NULL ){
return -2;
}
/*zmsg_print(recv_msg);*/
int rc = -1;
if (message_check_status(recv_msg, MSG_STATUS_WORKER_NOTFOUND) == 0 ){
warning_log("Not Found. key=%s", key);
rc = 0;
} else if ( message_check_status(recv_msg, MSG_STATUS_WORKER_ERROR) == 0 ){
error_log("Return MSG_STATUS_WORKER_ERROR. key=%s", key);
rc = -1;
} else {
/*zmsg_print(recv_msg);*/
zframe_t *frame_msgtype = zmsg_first(recv_msg);
if ( frame_msgtype != NULL ){
int16_t msgtype = *(int16_t*)zframe_data(frame_msgtype);
if ( msgtype == MSGTYPE_DATA ){
zmsg_first(recv_msg);
zframe_t *frame_key = zmsg_next(recv_msg);
UNUSED const char *key = (const char *)zframe_data(frame_key);
zframe_t *frame_data = zmsg_next(recv_msg);
UNUSED const char *data = (const char *)zframe_data(frame_data);
UNUSED uint32_t data_size = zframe_size(frame_data);
/*notice_log("Receive key:%s data_size:%d", key, data_size);*/
rc = 0;
}
}
}
zmsg_destroy(&recv_msg);
return rc;
}
示例6: message_get_msgtype
int16_t message_get_msgtype(zmsg_t *msg){
zframe_t *frame_msgtype = zmsg_first(msg);
if ( frame_msgtype != NULL && zframe_size(frame_msgtype) == sizeof(int16_t) ){
return *(int16_t*)zframe_data(frame_msgtype);
}
return MSGTYPE_UNKNOWN;
}
示例7: main
int main (void)
{
zctx_t *ctx = zctx_new ();
void *frontend = zsocket_new (ctx, ZMQ_ROUTER);
void *backend = zsocket_new (ctx, ZMQ_ROUTER);
zsocket_bind (frontend, "tcp://*:5555"); // For clients
zsocket_bind (backend, "tcp://*:5556"); // For workers
// Queue of available workers
zlist_t *workers = zlist_new ();
// The body of this example is exactly the same as lruqueue2.
// .skip
while (1) {
zmq_pollitem_t items [] = {
{ backend, 0, ZMQ_POLLIN, 0 },
{ frontend, 0, ZMQ_POLLIN, 0 }
};
// Poll frontend only if we have available workers
int rc = zmq_poll (items, zlist_size (workers)? 2: 1, -1);
if (rc == -1)
break; // Interrupted
// Handle worker activity on backend
if (items [0].revents & ZMQ_POLLIN) {
// Use worker address for LRU routing
zmsg_t *msg = zmsg_recv (backend);
if (!msg)
break; // Interrupted
zframe_t *address = zmsg_unwrap (msg);
zlist_append (workers, address);
// Forward message to client if it's not a READY
zframe_t *frame = zmsg_first (msg);
if (memcmp (zframe_data (frame), LRU_READY, 1) == 0)
zmsg_destroy (&msg);
else
zmsg_send (&msg, frontend);
}
if (items [1].revents & ZMQ_POLLIN) {
// Get client request, route to first available worker
zmsg_t *msg = zmsg_recv (frontend);
if (msg) {
zmsg_wrap (msg, (zframe_t *) zlist_pop (workers));
zmsg_send (&msg, backend);
}
}
}
// When we're done, clean up properly
while (zlist_size (workers)) {
zframe_t *frame = (zframe_t *) zlist_pop (workers);
zframe_destroy (&frame);
}
zlist_destroy (&workers);
zctx_destroy (&ctx);
return 0;
// .until
}
示例8: zmsg_encode
size_t
zmsg_encode (zmsg_t *self, byte **buffer)
{
assert (self);
assert (zmsg_is (self));
// Calculate real size of buffer
size_t buffer_size = 0;
zframe_t *frame = zmsg_first (self);
while (frame) {
size_t frame_size = zframe_size (frame);
if (frame_size < 255)
buffer_size += frame_size + 1;
else
buffer_size += frame_size + 1 + 4;
frame = zmsg_next (self);
}
*buffer = (byte *) zmalloc (buffer_size);
if (*buffer) {
// Encode message now
byte *dest = *buffer;
frame = zmsg_first (self);
while (frame) {
size_t frame_size = zframe_size (frame);
if (frame_size < 255) {
*dest++ = (byte) frame_size;
memcpy (dest, zframe_data (frame), frame_size);
dest += frame_size;
}
else {
*dest++ = 0xFF;
*dest++ = (frame_size >> 24) & 255;
*dest++ = (frame_size >> 16) & 255;
*dest++ = (frame_size >> 8) & 255;
*dest++ = frame_size & 255;
memcpy (dest, zframe_data (frame), frame_size);
dest += frame_size;
}
frame = zmsg_next (self);
}
assert ((dest - *buffer) == buffer_size);
}
return buffer_size;
}
示例9: zmsg_signal
int
zmsg_signal (zmsg_t *self)
{
if (zmsg_size (self) == 1
&& zmsg_content_size (self) == 8) {
zframe_t *frame = zmsg_first (self);
int64_t signal_value = *((int64_t *) zframe_data (frame));
if ((signal_value & 0xFFFFFFFFFFFFFF00L) == 0x7766554433221100L)
return signal_value & 255;
}
return -1;
}
示例10: message_check_action
int message_check_action(zmsg_t *msg, const char *action)
{
int16_t msgtype = message_get_msgtype(msg);
if ( msgtype == MSGTYPE_ACTION ){
zmsg_first(msg);
zframe_t *frame = zmsg_next(msg);
if ( frame != NULL ){
return memcmp(zframe_data(frame), action, strlen(action));
}
}
return -1;
}
示例11: message_check_heartbeat
int message_check_heartbeat(zmsg_t *msg, const char *heartbeat)
{
int16_t msgtype = message_get_msgtype(msg);
if ( msgtype == MSGTYPE_HEARTBEAT ){
zmsg_first(msg);
zframe_t *frame = zmsg_next(msg);
if ( frame != NULL ){
return memcmp(zframe_data(frame), heartbeat, strlen(heartbeat));
}
}
return -1;
}
示例12: message_check_status
int message_check_status(zmsg_t *msg, const char *status)
{
int16_t msgtype = message_get_msgtype(msg);
if ( msgtype == MSGTYPE_STATUS ){
zmsg_first(msg);
zframe_t *frame = zmsg_next(msg);
if ( frame != NULL ){
return memcmp(zframe_data(frame), status, strlen(status));
}
}
return -1;
}
示例13: zmsg_unwrap
zframe_t *
zmsg_unwrap (zmsg_t *self)
{
assert (self);
zframe_t *frame = zmsg_pop (self);
zframe_t *empty = zmsg_first (self);
if (zframe_size (empty) == 0) {
empty = zmsg_pop (self);
zframe_destroy (&empty);
}
return frame;
}
示例14: zmsg_encode
size_t
zmsg_encode (zmsg_t *self, byte **buffer)
{
assert (self);
// Calculate real size of buffer
size_t buffer_size = 0;
zframe_t *frame = zmsg_first (self);
while (frame) {
size_t frame_size = zframe_size (frame);
if (frame_size < ZMSG_SHORT_LEN)
buffer_size += frame_size + 1;
else
if (frame_size < 0x10000)
buffer_size += frame_size + 3;
else
buffer_size += frame_size + 5;
frame = zmsg_next (self);
}
*buffer = malloc (buffer_size);
// Encode message now
byte *dest = *buffer;
frame = zmsg_first (self);
while (frame) {
size_t frame_size = zframe_size (frame);
if (frame_size < ZMSG_SHORT_LEN) {
*dest++ = (byte) frame_size;
memcpy (dest, zframe_data (frame), frame_size);
dest += frame_size;
}
else
if (frame_size < 0x10000) {
*dest++ = ZMSG_SHORT_LEN;
*dest++ = (frame_size >> 8) & 255;
*dest++ = frame_size & 255;
memcpy (dest, zframe_data (frame), frame_size);
dest += frame_size;
}
else {
示例15: interval_minit
void
interval_minit (interval_t ** interval, zmsg_t * msg)
{
*interval = malloc (sizeof (interval_t));
zframe_t *frame = zmsg_first (msg);
memcpy (&((*interval)->start), zframe_data (frame), zframe_size (frame));
frame = zmsg_next (msg);
memcpy (&((*interval)->end), zframe_data (frame), zframe_size (frame));
}