本文整理汇总了C++中zsocket_destroy函数的典型用法代码示例。如果您正苦于以下问题:C++ zsocket_destroy函数的具体用法?C++ zsocket_destroy怎么用?C++ zsocket_destroy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zsocket_destroy函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read_serial
void read_serial(void * cvoid, zctx_t * context, void * pipe) {
char * buf;
serialconfig_t * config = (serialconfig_t*)cvoid;
FILE * in = config->in; // fopen("/dev/ttyO1", "r");
size_t nbytes=2047;
// Prepare our context and publisher
buf = (char *) malloc(nbytes+1) ;
fprintf(stderr, "bound\n");
// first line is always garbage
getline(&buf, &nbytes, in);
child_handshake(pipe);
zsocket_destroy(context, pipe);
void* socket = zsocket_new(context, ZMQ_PUB);
zsocket_bind(socket, "inproc://raw_serial");
while ( getline(&buf, &nbytes, in) != -1 ) {
#ifdef DEBUG
puts("line:");
puts(buf);
#endif
zmsg_t * msg = zmsg_new();
zmsg_pushstr(msg, buf); // does buf need to be copied?
zmsg_send(&msg, socket);
}
fprintf(stderr, "error reading from stdin\n");
zsocket_destroy(context, socket);
}
示例2: s_can_connect
// Checks whether client can connect to server
static bool
s_can_connect (zctx_t *ctx, void **server, void **client)
{
int port_nbr = zsocket_bind (*server, "tcp://127.0.0.1:*");
assert (port_nbr > 0);
int rc = zsocket_connect (*client, "tcp://127.0.0.1:%d", port_nbr);
assert (rc == 0);
// Give the connection time to fail if that's the plan
zclock_sleep (200);
// By default PUSH sockets block if there's no peer
zsock_set_sndtimeo (*server, 200);
zstr_send (*server, "Hello, World");
zpoller_t *poller = zpoller_new (*client, NULL);
bool success = (zpoller_wait (poller, 400) == *client);
zpoller_destroy (&poller);
zsocket_destroy (ctx, *client);
zsocket_destroy (ctx, *server);
*server = zsocket_new (ctx, ZMQ_PUSH);
assert (*server);
*client = zsocket_new (ctx, ZMQ_PULL);
assert (*client);
return success;
}
示例3: zyre_node_new
static zyre_node_t *
zyre_node_new (zctx_t *ctx, void *pipe)
{
zyre_node_t *self = (zyre_node_t *) zmalloc (sizeof (zyre_node_t));
self->ctx = ctx;
self->pipe = pipe;
self->inbox = zsocket_new (ctx, ZMQ_ROUTER);
if (self->inbox == NULL) {
free (self);
return NULL; // Interrupted 0MQ call
}
self->port = zsocket_bind (self->inbox, "tcp://*:*");
if (self->port < 0) {
zsocket_destroy(self->ctx, self->inbox);
free (self);
return NULL; // Interrupted 0MQ call
}
self->beacon = zbeacon_new (self->ctx, ZRE_DISCOVERY_PORT);
if (!self->beacon) {
zsocket_destroy(self->ctx, self->inbox);
free (self);
return NULL; // Exhausted process sockets
}
self->uuid = zuuid_new ();
self->peers = zhash_new ();
self->peer_groups = zhash_new ();
self->own_groups = zhash_new ();
self->headers = zhash_new ();
zhash_autofree (self->headers);
return self;
}
示例4: test_zmq
static void test_zmq (flux_reactor_t *reactor)
{
zctx_t *zctx;
void *zs[2];
flux_watcher_t *r, *w;
ok ((zctx = zctx_new ()) != NULL,
"zmq: created zmq context");
zs[0] = zsocket_new (zctx, ZMQ_PAIR);
zs[1] = zsocket_new (zctx, ZMQ_PAIR);
ok (zs[0] && zs[1]
&& zsocket_bind (zs[0], "inproc://test_zmq") == 0
&& zsocket_connect (zs[1], "inproc://test_zmq") == 0,
"zmq: connected ZMQ_PAIR sockets over inproc");
r = flux_zmq_watcher_create (reactor, zs[0], FLUX_POLLIN, zmqreader, NULL);
w = flux_zmq_watcher_create (reactor, zs[1], FLUX_POLLOUT, zmqwriter, NULL);
ok (r != NULL && w != NULL,
"zmq: nonblocking reader and writer created");
flux_watcher_start (r);
flux_watcher_start (w);
ok (flux_reactor_run (reactor, 0) == 0,
"zmq: reactor ran to completion after %d messages", zmqwriter_msgcount);
flux_watcher_stop (r);
flux_watcher_stop (w);
flux_watcher_destroy (r);
flux_watcher_destroy (w);
zsocket_destroy (zctx, zs[0]);
zsocket_destroy (zctx, zs[1]);
zctx_destroy (&zctx);
}
示例5: printf
PoolFrontend::~PoolFrontend() {
printf("PoolFrontend stopped.\n");
zsocket_destroy(mCtx, mRouter);
zsocket_destroy(mCtx, mDealer);
zctx_destroy(&mCtx);
}
示例6: zre_peer_connect
void
zre_peer_connect (zre_peer_t *self, char *reply_to, char *endpoint)
{
// If already connected, destroy old socket and start again
if (self->connected)
zsocket_destroy (self->ctx, self->mailbox);
// Create new outgoing socket (drop any messages in transit)
self->mailbox = zsocket_new (self->ctx, ZMQ_DEALER);
// Set our caller 'From' identity so that receiving node knows
// who each message came from.
zsocket_set_identity (self->mailbox, reply_to);
// Set a high-water mark that allows for reasonable activity
zsocket_set_sndhwm (self->mailbox, PEER_EXPIRED * 100);
// Send messages immediately or return EAGAIN
zsocket_set_sndtimeo (self->mailbox, 0);
// Connect through to peer node
zsocket_connect (self->mailbox, "tcp://%s", endpoint);
self->endpoint = strdup (endpoint);
self->connected = true;
self->ready = false;
}
示例7: prob_disconnect
void
prob_disconnect(prob_client_t pc)
{
if (zsocket_disconnect(pc->zocket, "%s", pc->file) != 0) Warning(info, "Could not disconnect from zocket %s", pc->file);
zsocket_destroy(pc->ctx, pc->zocket);
zctx_destroy(&(pc->ctx));
}
示例8: do_heartbeat
static gboolean
do_heartbeat (GPPWorker *self)
{
GPPWorkerPrivate *priv = GET_PRIV (self);
if (--priv->liveness == 0) {
g_warning ("W: heartbeat failure, can't reach queue\n");
g_warning ("W: reconnecting in %zd msec...\n", priv->interval);
g_source_remove (priv->frontend_source);
priv->frontend_source = 0;
g_io_channel_unref (priv->frontend_channel);
if (priv->interval < INTERVAL_MAX)
priv->interval *= 2;
zsocket_destroy (priv->ctx, priv->frontend);
g_timeout_add (priv->interval, (GSourceFunc) do_start, self);
return FALSE;
}
zframe_t *frame = zframe_new (PPP_HEARTBEAT, 1);
zframe_send (&frame, priv->frontend, 0);
/* We need to do that for some reason ... */
check_socket_activity (priv->frontend_channel, G_IO_IN, self);
return TRUE;
}
示例9: s_can_connect
// Checks whether client can connect to server
static bool
s_can_connect (zctx_t *ctx, void **server, void **client)
{
int port_nbr = zsocket_bind (*server, "tcp://127.0.0.1:*");
assert (port_nbr > 0);
int rc = zsocket_connect (*client, "tcp://127.0.0.1:%d", port_nbr);
assert (rc == 0);
zstr_send (*server, "Hello, World");
zpoller_t *poller = zpoller_new (*client, NULL);
bool success = (zpoller_wait (poller, 200) == *client);
zpoller_destroy (&poller);
zsocket_destroy (ctx, *client);
zsocket_destroy (ctx, *server);
*server = zsocket_new (ctx, ZMQ_PUSH);
*client = zsocket_new (ctx, ZMQ_PULL);
return success;
}
示例10: closeZMQ
/* closeZMQ will destroy the context and
* associated socket
*/
static void closeZMQ(instanceData* pData) {
errmsg.LogError(0, NO_ERRCODE, "closeZMQ called");
if(s_context && pData->socket) {
if(pData->socket != NULL) {
zsocket_destroy(s_context, pData->socket);
}
}
}
示例11: test_line
char * test_line() {
zctx_t *context = zctx_new();
lineconfig_t config;
config.line_id = 2;
config_t base = { "uuid", "inproc:broker", "inproc:portwatcher",
"inproc:registration", "http://something.com" };
config.base_config = &base;
void * line_in = zsocket_new(context, ZMQ_PUB);
zsocket_bind (line_in, "inproc://line");
// filter(identity, serial_reader, remote, context);
zclock_log("pre-fork");
void * pipe = zthread_fork(context, line_listener, &config);
// TODO a real test
zstr_send(pipe, "ping");
char * result = zstr_recv(pipe);
mu_assert_str("pong response", "pong", result);
free(result);
// do some channel switching
int i,j;
for(i=0;i<100;i++) {
// first channel
for(j=0;j<3; j++) {
val_msg(line_in, "foo", 12);
}
for(j=0;j<3;j++) {
val_msg(line_in, "bar", 99);
}
}
zstr_send(line_in, "DESTROY");
// temp
printf("destroy message sent\n");
result = zstr_recv(pipe);
mu_assert_str("destroy response", "ok", result);
free(result);
zsocket_destroy(context,pipe);
printf("freed pipe\n");
zsocket_destroy(context, line_in);
zctx_destroy(&context);
return NULL;
}
示例12: s_mdp_client_connect_to_broker
void s_mdp_client_connect_to_broker (mdp_client_t *self)
{
if (self->client)
zsocket_destroy (self->ctx, self->client);
self->client = zsocket_new (self->ctx, ZMQ_DEALER);
zmq_connect (self->client, self->broker);
if (self->verbose)
zclock_log ("I: connecting to broker at %s...", self->broker);
}
示例13: client_task
static void
client_task (void *args)
{
client_state* state = (client_state*) args;
void *frontend = zsocket_new (state->context, ZMQ_DEALER);
zsocket_set_identity (frontend, state->identity);
zsocket_connect (frontend,state->server_url);
void *backend = zsocket_new (state->context, ZMQ_DEALER);
zsocket_bind (backend, "inproc://backend");
zthread_fork (state->context, worker_task, state);
client_loop(state, frontend, backend);
zsocket_destroy(state->context, &frontend);
zsocket_destroy(state->context, &backend);
zctx_destroy (&state->context);
}
示例14: zsocket_destroy
void *_rrwrk_create_socket(zctx_t *ctx, void *socket, int type)
{
if (socket) {
zsocket_destroy(ctx, socket); //** Destroy existing socket
}
socket = zsocket_new(ctx, type);
assert(socket);
return socket;
}
示例15: collabclient_sessionReconnect
void collabclient_sessionReconnect( void* ccvp )
{
#ifdef BUILD_COLLAB
cloneclient_t* cc = (cloneclient_t*)ccvp;
zsocket_destroy( cc->ctx, cc->snapshot );
zsocket_destroy( cc->ctx, cc->subscriber );
zsocket_destroy( cc->ctx, cc->publisher );
collabclient_remakeSockets( cc );
cc->publisher_sendseq = 1;
FontView* fv = FontViewFindUI( FontViewFind_byCollabPtr, cc );
if( fv )
{
collabclient_sessionJoin( cc, fv );
}
#endif
}