当前位置: 首页>>代码示例>>C++>>正文


C++ zframe_recv函数代码示例

本文整理汇总了C++中zframe_recv函数的典型用法代码示例。如果您正苦于以下问题:C++ zframe_recv函数的具体用法?C++ zframe_recv怎么用?C++ zframe_recv使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了zframe_recv函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: s_agent_handle_dealer

static int
s_agent_handle_dealer (agent_t *self)
{
    if (self->state == connecting) {
        zframe_t *input = zframe_recv (self->dealer);
        zframe_t *output = curve_codec_execute (self->codec, &input);
        if (output)
            zframe_send (&output, self->dealer, 0);
        else
        if (curve_codec_connected (self->codec))
            self->state = connected;
        else
        if (curve_codec_exception (self->codec))
            self->state = exception;
    }
    else
    if (self->state == connected) {
        zframe_t *encrypted = zframe_recv (self->dealer);
        zframe_t *cleartext = curve_codec_decode (self->codec, &encrypted);
        if (cleartext) {
            int flags = zframe_more (cleartext)? ZFRAME_MORE: 0;
            zframe_send (&cleartext, self->data, flags);
        }
        else
            self->state = exception;
    }
    return 0;
}
开发者ID:zeromq,项目名称:libcurve,代码行数:28,代码来源:curve_client.c

示例2: unregister

    void unregister(std::string const &name) {
	directoryd::ServiceRequest request;
	request.set_type(directoryd::UNREGISTER);
	auto *r = request.mutable_unregister();
	r->set_name(name);

	zframe_t *sf = zframe_new(NULL, request.ByteSize());
	assert (sf != NULL);
	request.SerializeToArray(zframe_data(sf),zframe_size(sf));
	int retval = zframe_send(&sf,
				 DDClient::instance().register_socket(), 0);
	assert(retval == 0);

	zframe_t *rf = zframe_recv (DDClient::instance().register_socket());
	directoryd::ServiceReply reply;
	reply.ParseFromArray(zframe_data(rf),zframe_size(rf));
	zframe_destroy(&rf);

	if (reply.type() != directoryd::UNREGISTER) {
	    throw RegistrationError("Got back incorrect message type when trying to unregister.");
	}
	if (reply.success() != true) {
	    throw RegistrationError(reply.result());
	}
    }
开发者ID:mhaberler,项目名称:directoryd,代码行数:25,代码来源:register.cpp

示例3: handle_event

int handle_event(zloop_t *loop, zsock_t *reader, void *args) {
         // initialization
        ubx_block_t *b = (ubx_block_t *) args;
        struct zmq_receiver_info *inf = (struct zmq_receiver_info*) b->private_data;
        printf("zmq_receiver: data available.\n");

        zframe_t *frame = zframe_recv (reader);
        // print out frame data
        zframe_print (frame, NULL);

        // move to step function?
        ubx_type_t* type =  ubx_type_get(b->ni, "unsigned char");
        ubx_data_t msg;
        msg.data = (void *)zframe_data(frame);
        msg.len = zframe_size(frame);
        msg.type = type;

        //hexdump((unsigned char *)msg.data, msg.len, 16);
        __port_write(inf->ports.zmq_in, &msg);

        /* Inform potential observers ? */

        // clean up temporary frame object
        zframe_destroy (&frame);

        return 1;
}
开发者ID:blumenthal,项目名称:ubx,代码行数:27,代码来源:zmq_receiver.cpp

示例4: zmsg_recv

zmsg_t *
zmsg_recv (void *source)
{
    assert (source);
    zmsg_t *self = zmsg_new ();
    if (!self)
        return NULL;

    while (true) {
        zframe_t *frame = zframe_recv (source);
        if (!frame) {
            if (errno == EINTR && zlist_head (self->frames))
                continue;
            else {
                zmsg_destroy (&self);
                break;              //  Interrupted or terminated
            }
        }
        if (zmsg_append (self, &frame)) {
            zmsg_destroy (&self);
            break;
        }
        if (!zsock_rcvmore (source))
            break;              //  Last message frame
    }
    return self;
}
开发者ID:hellermf,项目名称:lstore-release,代码行数:27,代码来源:zmsg.c

示例5: main

int main (void)
{
    zctx_t *ctx = zctx_new ();
    zctx_set_linger (ctx, 1000);
    
    void *pub = zsocket_new (ctx, ZMQ_XPUB);
    zsocket_set_hwm (pub, 0);
    zsocket_connect (pub, "tcp://127.0.0.1:9000");

    //  Wait for subscriber to subscribe
    zframe_t *frame = zframe_recv (pub);
    zframe_destroy (&frame);
    
    //  Send HELLOs for five seconds
    size_t total = 0;
    int64_t finish_at = zclock_time () + 5000;
    
    while (zclock_time () < finish_at) {
        //  Send 100K and then check time again
        int count = 0;
        for (count = 0; count < 100000; count++)
            zstr_send (pub, "HELLO");
        total++;
    }
    printf ("%zd00000 messages sent\n", total);
    
    zstr_send (pub, "WORLD");
    zctx_destroy (&ctx);
    return 0;
}
开发者ID:hintjens,项目名称:zmtp,代码行数:30,代码来源:pub.c

示例6: s_snapshots

static int
s_snapshots (zloop_t *loop, zmq_pollitem_t *poller, void *args)
{
    clonesrv_t *self = (clonesrv_t *) args;

    zframe_t *identity = zframe_recv (poller->socket);
    if (identity) {
        //  Request is in second frame of message
        char *request = zstr_recv (poller->socket);
        char *subtree = NULL;
        if (streq (request, "ICANHAZ?")) {
            free (request);
            subtree = zstr_recv (poller->socket);
        }
        else
            printf ("E: bad request, aborting\n");

        if (subtree) {
            //  Send state socket to client
            kvroute_t routing = { poller->socket, identity, subtree };
            zhash_foreach (self->kvmap, s_send_single, &routing);

            //  Now send END message with sequence number
            zclock_log ("I: sending shapshot=%d", (int) self->sequence);
            zframe_send (&identity, poller->socket, ZFRAME_MORE);
            kvmsg_t *kvmsg = kvmsg_new (self->sequence);
            kvmsg_set_key  (kvmsg, "KTHXBAI");
            kvmsg_set_body (kvmsg, (byte *) subtree, 0);
            kvmsg_send     (kvmsg, poller->socket);
            kvmsg_destroy (&kvmsg);
            free (subtree);
        }
    }
    return 0;
}
开发者ID:Alex-Benveniste,项目名称:zguide,代码行数:35,代码来源:clonesrv5.c

示例7: zchanneler_recv

zframe_t *
zchanneler_recv (zchanneler_t *self)
{
    assert (self);
    zframe_t *frame = zframe_recv (self->server);
    return frame;
}
开发者ID:taotetek,项目名称:zchannel,代码行数:7,代码来源:zchanneler.c

示例8: state_manager

static void
state_manager (void *args, zctx_t *ctx, void *pipe)
{
    zhash_t *kvmap = zhash_new ();

    zstr_send (pipe, "READY");
    void *snapshot = zsocket_new (ctx, ZMQ_ROUTER);
    zsocket_bind (snapshot, "tcp://*:5556");

    zmq_pollitem_t items [] = {
        { pipe, 0, ZMQ_POLLIN, 0 },
        { snapshot, 0, ZMQ_POLLIN, 0 }
    };
    int64_t sequence = 0;       //  Current snapshot version number
    while (!zctx_interrupted) {
        int rc = zmq_poll (items, 2, -1);
        if (rc == -1 && errno == ETERM)
            break;              //  Context has been shut down

        //  Apply state update from main thread
        if (items [0].revents & ZMQ_POLLIN) {
            kvmsg_t *kvmsg = kvmsg_recv (pipe);
            if (!kvmsg)
                break;          //  Interrupted
            sequence = kvmsg_sequence (kvmsg);
            kvmsg_store (&kvmsg, kvmap);
        }
        //  Execute state snapshot request
        if (items [1].revents & ZMQ_POLLIN) {
            zframe_t *identity = zframe_recv (snapshot);
            if (!identity)
                break;          //  Interrupted

            //  Request is in second frame of message
            char *request = zstr_recv (snapshot);
            if (streq (request, "ICANHAZ?"))
                free (request);
            else {
                printf ("E: bad request, aborting\n");
                break;
            }
            //  Send state snapshot to client
            kvroute_t routing = { snapshot, identity };

            //  For each entry in kvmap, send kvmsg to client
            zhash_foreach (kvmap, s_send_single, &routing);

            //  Now send END message with sequence number
            printf ("Sending state shapshot=%d\n", (int) sequence);
            zframe_send (&identity, snapshot, ZFRAME_MORE);
            kvmsg_t *kvmsg = kvmsg_new (sequence);
            kvmsg_set_key  (kvmsg, "KTHXBAI");
            kvmsg_set_body (kvmsg, (byte *) "", 0);
            kvmsg_send     (kvmsg, snapshot);
            kvmsg_destroy (&kvmsg);
        }
    }
    zhash_destroy (&kvmap);
}
开发者ID:Alexis-D,项目名称:zguide,代码行数:59,代码来源:clonesrv2.c

示例9: s_socket_event

static void
s_socket_event (agent_t *self)
{
    //  First frame is event number and value
    zframe_t *frame = zframe_recv (self->socket);
    int event = *(uint16_t *) (zframe_data (frame));
    int value = *(uint32_t *) (zframe_data (frame) + 2);
    zframe_destroy (&frame);
    
    //  Second frame is address
    char *address = zstr_recv (self->socket);
    char *description = "Unknown";
    switch (event) {
        case ZMQ_EVENT_ACCEPTED:
            description = "Accepted";
            break;
        case ZMQ_EVENT_ACCEPT_FAILED:
            description = "Accept failed";
            break;
        case ZMQ_EVENT_BIND_FAILED:
            description = "Bind failed";
            break;
        case ZMQ_EVENT_CLOSED:
            description = "Closed";
            break;
        case ZMQ_EVENT_CLOSE_FAILED:
            description = "Close failed";
            break;
        case ZMQ_EVENT_DISCONNECTED:
            description = "Disconnected";
            break;
        case ZMQ_EVENT_CONNECTED:
            description = "Connected";
            break;
        case ZMQ_EVENT_CONNECT_DELAYED:
            description = "Connect delayed";
            break;
        case ZMQ_EVENT_CONNECT_RETRIED:
            description = "Connect retried";
            break;
        case ZMQ_EVENT_LISTENING:
            description = "Listening";
            break;
        case ZMQ_EVENT_MONITOR_STOPPED:
            description = "Monitor stopped";
            break;
        default:
            zsys_error ("illegal socket monitor event: %d", event);
            break;
    }
    if (self->verbose)
        zsys_info ("zmonitor: %s - %s\n", description, address);

    zstr_sendfm (self->pipe, "%d", event);
    zstr_sendfm (self->pipe, "%d", value);
    zstr_sendm  (self->pipe, address);
    zstr_send   (self->pipe, description);
    free (address);
}
开发者ID:mtspencer,项目名称:czmq,代码行数:59,代码来源:zmonitor.c

示例10: listener_thread

static void listener_thread (void *args, zctx_t *ctx, void *pipe)
{
	while (true) {
		zframe_t *frame = zframe_recv (pipe);
		if (!frame)
			break; //  Interrupted
		//zframe_print (frame, NULL);
		zframe_destroy (&frame);
	}
}
开发者ID:KnightKu,项目名称:rnotify-c,代码行数:10,代码来源:publisher.c

示例11: listener_thread

static void
listener_thread (void *args, zctx_t *ctx, void *pipe)
{
    //  Print everything that arrives on pipe
    while (true) {
        zframe_t *frame = zframe_recv (pipe);
        if (!frame)
            break;              //  Interrupted
        zframe_print (frame, NULL);
        zframe_destroy (&frame);
    }
}
开发者ID:quanhua92,项目名称:LearnZeroMQ,代码行数:12,代码来源:espresso.c

示例12: s_self_handle_pipe

static int
s_self_handle_pipe (self_t *self)
{
    //  Get just the command off the pipe
    char *command = zstr_recv (self->pipe);
    if (!command)
        return -1;                  //  Interrupted

    if (self->verbose)
        zsys_info ("zbeacon: API command=%s", command);

    if (streq (command, "VERBOSE"))
        self->verbose = true;
    else
    if (streq (command, "CONFIGURE")) {
        int port;
        int rc = zsock_recv (self->pipe, "i", &port);
        assert (rc == 0);
        s_self_configure (self, port);
    }
    else
    if (streq (command, "PUBLISH")) {
        zframe_destroy (&self->transmit);
        zsock_recv (self->pipe, "fi", &self->transmit, &self->interval);
        assert (zframe_size (self->transmit) <= UDP_FRAME_MAX);
        if (self->interval == 0)
            self->interval = INTERVAL_DFLT;
        //  Start broadcasting immediately
        self->ping_at = zclock_mono ();
    }
    else
    if (streq (command, "SILENCE"))
        zframe_destroy (&self->transmit);
    else
    if (streq (command, "SUBSCRIBE")) {
        zframe_destroy (&self->filter);
        self->filter = zframe_recv (self->pipe);
        assert (zframe_size (self->filter) <= UDP_FRAME_MAX);
    }
    else
    if (streq (command, "UNSUBSCRIBE"))
        zframe_destroy (&self->filter);
    else
    if (streq (command, "$TERM"))
        self->terminated = true;
    else {
        zsys_error ("zbeacon: - invalid command: %s", command);
        assert (false);
    }
    zstr_free (&command);
    return 0;
}
开发者ID:minhoryang,项目名称:czmq,代码行数:52,代码来源:zbeacon.c

示例13: main

int main (void)
{
    zctx_t *ctx = zctx_new ();

    void *server = zsocket_new (ctx, ZMQ_XPUB);
    zsocket_bind (server, "tcp://*:6001");

    void *client = zsocket_new (ctx, ZMQ_XSUB);
    zsocket_connect (client, "tcp://localhost:6001");
    byte subscribe [] = { 1 };
    
    zmq_send (client, &subscribe, sizeof (subscribe), 0);
    zmq_send (client, "MOREMOREMORE", 12, ZMQ_SNDMORE);
    zmq_send (client, "LAST", 4, 0);

    //  First message is subscription, 1 byte
    zframe_t *frame = zframe_recv (server);
    assert (zframe_size (frame) == 1);
    assert (zsocket_rcvmore (server) == 0);
    zframe_destroy (&frame);
    
    //  Second message is 12 bytes with MORE
    frame = zframe_recv (server);
    assert (zframe_size (frame) == 12);
    assert (zsocket_rcvmore (server) == 1);
    zframe_destroy (&frame);
    
    //  Third message is 4 bytes with no more
    frame = zframe_recv (server);
    assert (zframe_size (frame) == 4);
    assert (zsocket_rcvmore (server) == 0);
    zframe_destroy (&frame);
    
    zctx_destroy (&ctx);
    return 0;
}
开发者ID:hashstat,项目名称:zeromq-issues,代码行数:36,代码来源:issue.c

示例14: counter_task

static void
counter_task (void *args, zctx_t *ctx, void *pipe)
{
    void *counter = zsocket_new (ctx, ZMQ_ROUTER);
    zsocket_bind (counter, "tcp://*:6001");

    //  Parameters for the census
    int census_msec = 250;       //  Msecs to settle down

    //  Calling thread tells us the population size
    char *population = zstr_recv (pipe);
    
    //  All activity happens on our counter socket
    zmq_pollitem_t items [] = { { counter, 0, ZMQ_POLLIN, 0 } };

    int headcount = 0;         //  Known target size
    int positives = 0;         //  How many said "yes"
    
    int64_t timer_end = zclock_time () + census_msec;
    int still_waiting = atoi (population);
    while (still_waiting) {
        int64_t time_left = timer_end - zclock_time ();
        if (time_left <= 0)
            break;              //  We're done here
        int rc = zmq_poll (items, 1, time_left * ZMQ_POLL_MSEC);
        if (rc == -1)
            break;              //  Interrupted

        if (items [0].revents & ZMQ_POLLIN) {
            zframe_t *address = zframe_recv (counter);
            char *message = zstr_recv (counter);
            if (streq (message, "Hello")) {
                headcount++;
                zframe_send (&address, counter, ZFRAME_MORE);
                zstr_send (counter, "Who wants pizza?");
            }
            else
            if (streq (message, "Yes"))
                positives++;
            
            zframe_destroy (&address);
            free (message);
        }
    }
    printf ("Out of %d people, %d want pizza\n", headcount, positives);
    zstr_send (pipe, "DONE");
}
开发者ID:hintjens,项目名称:codeconnected,代码行数:47,代码来源:census2.c

示例15: register_service

    void register_service(std::string const &name,
			  int port,
			  std::map<std::string, std::string> const &txt)
    {
	directoryd::ServiceRequest request;
	request.set_type(directoryd::REGISTER);
	auto *r = request.mutable_register_();
	auto l = r->add_location();
	l->set_port(port);
	l->set_type("_hotdec._tcp");
	r->set_name(name);
	for (auto &t : txt) {
	    auto txtfield = r->add_txt();
	    txtfield->set_key(t.first);
	    txtfield->set_value(t.second);
	}
	zframe_t *sf = zframe_new(NULL, request.ByteSize());
	assert (sf != NULL);
	request.SerializeToArray(zframe_data(sf),zframe_size(sf));

	string buffer;
	if (debug && TextFormat::PrintToString(request, &buffer)) {
	    fprintf(stderr, "request: %s\n", buffer.c_str());
	}

	int retval = zframe_send(&sf, DDClient::instance().register_socket(), 0);
	assert(retval == 0);

	zframe_t *rf = zframe_recv (DDClient::instance().register_socket());
	directoryd::ServiceReply reply;
	reply.ParseFromArray(zframe_data(rf),zframe_size(rf));

	if (debug && TextFormat::PrintToString(reply, &buffer)) {
	    fprintf(stderr, "reply: %s\n", buffer.c_str());
	}

	zframe_destroy(&rf);

	if (reply.type() != directoryd::REGISTER) {
	    throw RegistrationError("Got back incorrect message type when trying to register.");
	}
	if (reply.success() != true) {
	    throw RegistrationError(reply.result());
	}

	RegistrationManager::instance().add(name);
    }
开发者ID:mhaberler,项目名称:directoryd,代码行数:47,代码来源:register.cpp


注:本文中的zframe_recv函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。