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


C++ zstr_send函数代码示例

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


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

示例1: s_agent_new

static agent_t *
s_agent_new (zctx_t *ctx, void *pipe)
{
    agent_t *self = (agent_t *) zmalloc (sizeof (agent_t));
    if (!self)
        return NULL;

    self->ctx = ctx;
    self->pipe = pipe;
    self->whitelist = zhash_new ();
    if (self->whitelist)
        self->blacklist = zhash_new ();

    //  Create ZAP handler and get ready for requests
    if (self->blacklist)
        self->handler = zsocket_new (self->ctx, ZMQ_REP);
    if (self->handler) {
        if (zsocket_bind (self->handler, ZAP_ENDPOINT) == 0)
            zstr_send (self->pipe, "OK");
        else
            zstr_send (self->pipe, "ERROR");
    }
    else
        s_agent_destroy (&self);

    return self;
}
开发者ID:AxelVoitier,项目名称:czmq,代码行数:27,代码来源:zauth_v2.c

示例2: main

int main (void)
{
    puts ("Starting the zchat server");

    zsock_t *responder = zsock_new_rep ("tcp://*:5555");
    assert (responder);

    zsock_t *publisher = zsock_new_pub ("tcp://*:5556");
    assert (publisher);

    while (!zsys_interrupted) {
        //  Receive messages from client.
        char *client_msg = zstr_recv (responder);
        if (!client_msg)
            break;
        
        //  Let the zchat client know we got it.
        zstr_send (responder, "OK");

        //  Publish message to all zchat client subscribers
        zstr_send (publisher, client_msg);
        zstr_free (&client_msg);
    }

    puts ("Stopping the zchat server");

    zsock_destroy (&publisher);
    zsock_destroy (&responder);
    return 0;
}
开发者ID:jppunnett,项目名称:zchat,代码行数:30,代码来源:zchats.c

示例3: 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

示例4: main

int main (int argc, char *argv [])
{
    zctx_t *context = zctx_new ();
    void *publisher = zsocket_new (context, ZMQ_PUB);
    if (argc == 2)
        zsocket_connect (publisher, argv [1]);
    else
        zsocket_bind (publisher, "tcp://*:5556");

    //  Ensure subscriber connection has time to complete
    sleep (1);

    //  Send out all 1,000 topic messages
    int topic_nbr;
    for (topic_nbr = 0; topic_nbr < 1000; topic_nbr++) {
        zstr_sendm (publisher, "%03d", topic_nbr, ZMQ_SNDMORE);
        zstr_send (publisher, "Save Roger");
    }
    //  Send one random update per second
    srandom ((unsigned) time (NULL));
    while (!zctx_interrupted) {
        sleep (1);
        zstr_sendm (publisher, "%03d", randof (1000), ZMQ_SNDMORE);
        zstr_send (publisher, "Off with his head!");
    }
    zctx_destroy (&context);
    return 0;
}
开发者ID:arimogi,项目名称:zguide,代码行数:28,代码来源:pathopub.c

示例5: zproxy_test

void
zproxy_test (bool verbose)
{
    printf (" * zproxy: ");

    //  @selftest
    zctx_t *ctx = zctx_new ();
    void *frontend = zsocket_new (ctx, ZMQ_PULL);
    int rc = zsocket_bind (frontend, "inproc://frontend");
    assert (rc == 0);
    void *backend = zsocket_new (ctx, ZMQ_PUSH);
    rc = zsocket_bind (backend, "inproc://backend");
    assert (rc == 0);
    zproxy_t *proxy = zproxy_new (ctx, frontend, backend);

    //  Connect application sockets to proxy
    void *faucet = zsocket_new (ctx, ZMQ_PUSH);
    rc = zsocket_connect (faucet, "inproc://frontend");
    assert (rc == 0);
    void *sink = zsocket_new (ctx, ZMQ_PULL);
    rc = zsocket_connect (sink, "inproc://backend");
    assert (rc == 0);

    //  Send some messages and check they arrived
    zstr_send (faucet, "Hello");
    char *string = zstr_recv (sink);
    assert (streq (string, "Hello"));
    zstr_free (&string);
    
    //  Check pause/resume functionality
    zproxy_pause (proxy);
    zstr_send (faucet, "World");

    zproxy_resume (proxy);
    string = zstr_recv (sink);
    assert (streq (string, "World"));
    zstr_free (&string);
    
    //  Create capture socket, must be a PULL socket
    void *capture = zsocket_new (ctx, ZMQ_PULL);
    rc = zsocket_bind (capture, "inproc://capture");
    assert (rc == 0);

    //  Switch on capturing, check that it works
    zproxy_capture (proxy, "inproc://capture");
    zstr_send (faucet, "Hello");
    
    string = zstr_recv (sink);
    assert (streq (string, "Hello"));
    zstr_free (&string);
    
    string = zstr_recv (capture);
    assert (streq (string, "Hello"));
    zstr_free (&string);
    zproxy_destroy (&proxy);
    zctx_destroy (&ctx);

    //  @end
    printf ("OK\n");
}
开发者ID:TangCheng,项目名称:czmq,代码行数:60,代码来源:zproxy.c

示例6: main

int main (void)
{
    zvudp_t *zvudp = zvudp_new ();
    void *client = zvudp_socket (zvudp);
    zvudp_connect (zvudp, "127.0.0.1", 31000);

    //  Send test set to server
    puts ("Sending test set...");
    zstr_send (client, "START");
    int count;
    for (count = 0; count < 1000000; count++) {
        if (zctx_interrupted)
            break;
        zstr_send (client, "This is a test");
    }
    zstr_send (client, "END");

    //  Wait for server to confirm
    puts ("Waiting for server...");
    char *input = zstr_recv (client);
    if (input) {
        puts (input);
        free (input);
    }
    zvudp_destroy (&zvudp);
    return 0;
}
开发者ID:hintjens,项目名称:vtx,代码行数:27,代码来源:perfcli.c

示例7: test_tcp_pair_cli

static void
test_tcp_pair_cli (void *args, zctx_t *ctx, void *pipe)
{
    vtx_t *vtx = vtx_new (ctx);
    int rc = vtx_tcp_load (vtx, FALSE);
    assert (rc == 0);
    char *port = zstr_recv (pipe);

    void *pair = vtx_socket (vtx, ZMQ_PAIR);
    assert (pair);
    rc = vtx_connect (vtx, pair, "tcp://localhost:%s", port);
    assert (rc == 0);
    int sent = 0;
    int recd = 0;

    while (!zctx_interrupted) {
        zstr_send (pair, "ICANHAZ?");
        sent++;
        char *reply = zstr_recv_nowait (pair);
        if (reply) {
            recd++;
            free (reply);
        }
        char *end = zstr_recv_nowait (pipe);
        if (end) {
            free (end);
            zstr_send (pipe, "OK");
            break;
        }
    }
    zclock_log ("I: PAIR CLI: sent=%d recd=%d", sent, recd);
    free (port);
    vtx_destroy (&vtx);
}
开发者ID:hintjens,项目名称:vtx,代码行数:34,代码来源:vtx_test_tcp.c

示例8: client_task

static void
client_task (void *args, zctx_t *ctx, void *pipe)
{
    void *client = zsocket_new (ctx, ZMQ_DEALER);
    zsocket_connect (client, "tcp://localhost:5555");
    printf ("Setting up test...\n");
    zclock_sleep (100);

    int requests;
    int64_t start;

    printf ("Synchronous round-trip test...\n");
    start = zclock_time ();
    for (requests = 0; requests < 10000; requests++) {
        zstr_send (client, "hello");
        char *reply = zstr_recv (client);
        free (reply);
    }
    printf (" %d calls/second\n",
        (1000 * 10000) / (int) (zclock_time () - start));

    printf ("Asynchronous round-trip test...\n");
    start = zclock_time ();
    for (requests = 0; requests < 100000; requests++)
        zstr_send (client, "hello");
    for (requests = 0; requests < 100000; requests++) {
        char *reply = zstr_recv (client);
        free (reply);
    }
    printf (" %d calls/second\n",
        (1000 * 100000) / (int) (zclock_time () - start));
    zstr_send (pipe, "done");
}
开发者ID:AlexGiovanentti,项目名称:zguide,代码行数:33,代码来源:tripping.c

示例9: main

int main(int argc, char** argv) {
    zsock_t * sc = zsock_new(ZMQ_PUB);
    zsock_connect(sc, "tcp://%s:5560", argv[1]);
    while(!zsys_interrupted) {
        if(random()%1) {
            zstr_send(sc, "ON");
        } else {
            zstr_send(sc, "OFF");
        }
        sleep(1);
    }
    zsock_destroy(&sc);
}
开发者ID:jimklimov,项目名称:eaton-playground,代码行数:13,代码来源:ups.c

示例10: target_task

static void
target_task (void *args, zctx_t *ctx, void *pipe)
{
    void *subscriber = zsocket_new (ctx, ZMQ_DEALER);
    zsocket_connect (subscriber, "tcp://localhost:6001");

    zstr_send (subscriber, "Hello");
    char *question = zstr_recv (subscriber);
    char *answer = randof (2) == 0? "Yes": "No";
    printf ("%s %s\n", question, answer);
    free (question);
    zstr_send (subscriber, answer);
}
开发者ID:hintjens,项目名称:codeconnected,代码行数:13,代码来源:census2.c

示例11: send_tick_commands

static
int send_tick_commands(zloop_t *loop, int timer_id, void *arg)
{
    controller_state_t *state = arg;

    // send tick commands to actors to let them print out their stats
    zstr_send(state->subscriber, "tick");
    zstr_send(state->writer, "tick");

    int rc = zloop_timer(loop, 1000, 1, send_tick_commands, state);
    assert(rc != -1);

    return 0;
}
开发者ID:skaes,项目名称:logjam-tools,代码行数:14,代码来源:graylog-forwarder-controller.c

示例12: zsock_tx_cb

void zsock_tx_cb (struct ev_loop *loop, ev_zmq *w, int revents)
{
    static int count = 50; /* send two per invocation */

    if ((revents & EV_WRITE)) {
        if (zstr_send (w->zsock, "PING") < 0)
            fprintf (stderr, "zstr_send: %s", strerror (errno));
        if (zstr_send (w->zsock, "PING") < 0)
            fprintf (stderr, "zstr_send: %s", strerror (errno));
        if (--count == 0)
            ev_zmq_stop (loop, w);
    }
    if ((revents & EV_ERROR))
        ev_break (loop, EVBREAK_ALL);
}
开发者ID:surajpkn,项目名称:flux-core,代码行数:15,代码来源:ev.c

示例13: agent_ping_peer

static int
agent_ping_peer (const char *key, void *item, void *argument)
{
    agent_t *self = (agent_t *) argument;
    zre_peer_t *peer = (zre_peer_t *) item;
    char *identity = zre_peer_identity (peer);
    if (zclock_time () >= zre_peer_expired_at (peer)) {
        zre_log_info (self->log, ZRE_LOG_MSG_EVENT_EXIT,
                      zre_peer_endpoint (peer),
                      zre_peer_endpoint (peer));
        //  If peer has really vanished, expire it
        zstr_sendm (self->pipe, "EXIT");
        zstr_send (self->pipe, identity);
        zhash_foreach (self->peer_groups, agent_peer_delete, peer);
        zhash_delete (self->peers, identity);
    }
    else
    if (zclock_time () >= zre_peer_evasive_at (peer)) {
        //  If peer is being evasive, force a TCP ping.
        //  TODO: do this only once for a peer in this state;
        //  it would be nicer to use a proper state machine
        //  for peer management.
        zre_msg_t *msg = zre_msg_new (ZRE_MSG_PING);
        zre_peer_send (peer, &msg);
    }
    return 0;
}
开发者ID:Aluminus,项目名称:zyre,代码行数:27,代码来源:zre_node.c

示例14: zproxy_resume

void
zproxy_resume (zproxy_t *self)
{
    assert (self);
    zstr_send (self->pipe, "RESUME");
    zsocket_wait (self->pipe);
}
开发者ID:TangCheng,项目名称:czmq,代码行数:7,代码来源:zproxy.c

示例15: zproxy_pause

void
zproxy_pause (zproxy_t *self)
{
    assert (self);
    zstr_send (self->pipe, "PAUSE");
    zsocket_wait (self->pipe);
}
开发者ID:TangCheng,项目名称:czmq,代码行数:7,代码来源:zproxy.c


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