本文整理汇总了C++中zsys_error函数的典型用法代码示例。如果您正苦于以下问题:C++ zsys_error函数的具体用法?C++ zsys_error怎么用?C++ zsys_error使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zsys_error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: s_create_socket
static zsock_t *
s_create_socket (char *type_name, char *endpoints)
{
// This array matches ZMQ_XXX type definitions
assert (ZMQ_PAIR == 0);
char *type_names [] = {
"PAIR", "PUB", "SUB", "REQ", "REP",
"DEALER", "ROUTER", "PULL", "PUSH",
"XPUB", "XSUB", type_name
};
// We always match type at least at end of table
int index;
for (index = 0; strneq (type_name, type_names [index]); index++) ;
if (index > ZMQ_XSUB) {
zsys_error ("zproxy: invalid socket type '%s'", type_name);
return NULL;
}
zsock_t *sock = zsock_new (index);
if (sock) {
if (zsock_attach (sock, endpoints, true)) {
zsys_error ("zproxy: invalid endpoints '%s'", endpoints);
zsock_destroy (&sock);
}
}
return sock;
}
示例2: s_zdir_watch_subscribe
static void
s_zdir_watch_subscribe (zdir_watch_t *watch, const char *path)
{
if (watch->verbose)
zsys_info ("zdir_watch: Subscribing to directory path: %s", path);
zdir_watch_sub_t *sub = (zdir_watch_sub_t *) zmalloc (sizeof (zdir_watch_sub_t));
sub->dir = zdir_new (path, NULL);
if (!sub->dir) {
if (watch->verbose)
zsys_error ("zdir_watch: Unable to create zdir for path: %s", path);
zsock_signal (watch->pipe, 1);
return;
}
int rc = zhash_insert (watch->subs, path, sub);
if (rc) {
if (watch->verbose)
zsys_error ("zdir_watch: Unable to insert path '%s' into subscription list", path);
zsock_signal (watch->pipe, 1);
return;
}
void *item = zhash_freefn (watch->subs, path, s_sub_free);
if (item != sub) {
if (watch->verbose)
zsys_error ("zdir_watch: Unable to set free fn for path %s", path);
zsock_signal (watch->pipe, 1);
return;
}
if (watch->verbose)
zsys_info ("zdir_watch: Successfully subscribed to %s", path);
zsock_signal (watch->pipe, 0);
}
示例3: zsys_shutdown
// atexit or manual termination for the process
void
zsys_shutdown (void)
{
if (!s_initialized) {
return;
}
s_initialized = false;
// The atexit handler is called when the main function exits;
// however we may have zactor threads shutting down and still
// trying to close their sockets. So if we suspect there are
// actors busy (s_open_sockets > 0), then we sleep for a few
// hundred milliseconds to allow the actors, if any, to get in
// and close their sockets.
ZMUTEX_LOCK (s_mutex);
size_t busy = s_open_sockets;
ZMUTEX_UNLOCK (s_mutex);
if (busy)
zclock_sleep (200);
// No matter, we are now going to shut down
// Print the source reference for any sockets the app did not
// destroy properly.
ZMUTEX_LOCK (s_mutex);
s_sockref_t *sockref = (s_sockref_t *) zlist_pop (s_sockref_list);
while (sockref) {
assert (sockref->filename);
zsys_error ("dangling '%s' socket created at %s:%d",
zsys_sockname (sockref->type),
sockref->filename, (int) sockref->line_nbr);
zmq_close (sockref->handle);
free (sockref);
sockref = (s_sockref_t *) zlist_pop (s_sockref_list);
}
zlist_destroy (&s_sockref_list);
ZMUTEX_UNLOCK (s_mutex);
// Close logsender socket if opened (don't do this in critical section)
if (s_logsender) {
zsys_close (s_logsender, NULL, 0);
s_logsender = NULL;
}
if (s_open_sockets == 0)
zmq_term (s_process_ctx);
else
zsys_error ("dangling sockets: cannot terminate ZMQ safely");
ZMUTEX_DESTROY (s_mutex);
// Free dynamically allocated properties
free (s_interface);
free (s_logident);
#if defined (__UNIX__)
closelog (); // Just to be pedantic
#endif
}
示例4: s_on_read_timer
static int
s_on_read_timer (zloop_t *loop, int timer_id, void *arg)
{
zdir_watch_t *watch = (zdir_watch_t *) arg;
void *data;
for (data = zhash_first (watch->subs); data != NULL; data = zhash_next (watch->subs))
{
zdir_watch_sub_t *sub = (zdir_watch_sub_t *) data;
zdir_t *new_dir = zdir_new (zdir_path (sub->dir), NULL);
if (!new_dir) {
if (watch->verbose)
zsys_error ("zdir_watch: Unable to create new zdir for path %s", zdir_path (sub->dir));
continue;
}
// Determine if anything has changed.
zlist_t *diff = zdir_diff (sub->dir, new_dir, "");
// Do memory management before error handling...
zdir_destroy (&sub->dir);
sub->dir = new_dir;
if (!diff) {
if (watch->verbose)
zsys_error ("zdir_watch: Unable to create diff for path %s", zdir_path (sub->dir));
continue;
}
if (zlist_size (diff) > 0) {
if (watch->verbose) {
zdir_patch_t *patch = (zdir_patch_t *) zlist_first (diff);
zsys_info ("zdir_watch: Found %d changes in %s:", zlist_size (diff), zdir_path (sub->dir));
while (patch)
{
zsys_info ("zdir_watch: %s %s", zfile_filename (zdir_patch_file (patch), NULL), zdir_patch_op (patch) == ZDIR_PATCH_CREATE? "created": "deleted");
patch = (zdir_patch_t *) zlist_next (diff);
}
}
if (zsock_send (watch->pipe, "sp", zdir_path (sub->dir), diff) != 0) {
if (watch->verbose)
zsys_error ("zdir_watch: Unable to send patch list for path %s", zdir_path (sub->dir));
zlist_destroy (&diff);
}
// Successfully sent `diff` list - now owned by receiver
}
else {
zlist_destroy (&diff);
}
}
return 0;
}
示例5: s_self_create_socket
static zsock_t *
s_self_create_socket (self_t *self, char *type_name, char *endpoints, proxy_socket selected_socket)
{
// This array matches ZMQ_XXX type definitions
assert (ZMQ_PAIR == 0);
char *type_names [] = {
"PAIR", "PUB", "SUB", "REQ", "REP",
"DEALER", "ROUTER", "PULL", "PUSH",
"XPUB", "XSUB", type_name
};
// We always match type at least at end of table
int index;
for (index = 0; strneq (type_name, type_names [index]); index++) ;
if (index > ZMQ_XSUB) {
zsys_error ("zproxy: invalid socket type '%s'", type_name);
return NULL;
}
zsock_t *sock = zsock_new (index);
if (sock) {
#if (ZMQ_VERSION_MAJOR == 4)
if (self->domain [selected_socket]) {
// Apply authentication domain
zsock_set_zap_domain (sock, self->domain [selected_socket]);
}
if (self->auth_type [selected_socket] == AUTH_PLAIN) {
// Enable plain authentication
zsock_set_plain_server (sock, 1);
}
else
if (self->auth_type [selected_socket] == AUTH_CURVE) {
// Apply certificate keys
char *public_key = self->public_key [selected_socket];
assert(public_key);
char *secret_key = self->secret_key [selected_socket];
assert(secret_key);
zsock_set_curve_publickey (sock, public_key);
zsock_set_curve_secretkey (sock, secret_key);
// Enable curve authentication
zsock_set_curve_server (sock, 1);
}
#endif
if (zsock_attach (sock, endpoints, true)) {
zsys_error ("zproxy: invalid endpoints '%s'", endpoints);
zsock_destroy (&sock);
}
}
return sock;
}
示例6: someactor_recv_api
static void
someactor_recv_api (someactor_t *self)
{
// Get the whole message of the pipe in one go
zmsg_t *request = zmsg_recv (self->pipe);
if (!request)
return; // Interrupted
char *command = zmsg_popstr (request);
if (streq (command, "START"))
zsock_signal (self->pipe, someactor_start (self));
else
if (streq (command, "STOP"))
zsock_signal (self->pipe, someactor_stop (self));
else
if (streq (command, "VERBOSE")) {
self->verbose = true;
zsock_signal (self->pipe, 0);
}
else
if (streq (command, "$TERM"))
// The $TERM command is send by zactor_destroy() method
self->terminated = true;
else {
zsys_error ("invalid command '%s'", command);
assert (false);
}
}
示例7: zloop_timer
int
zloop_timer (zloop_t *self, size_t delay, size_t times, zloop_timer_fn handler, void *arg)
{
assert (self);
// Catch excessive use of timers
if (self->max_timers && zlistx_size (self->timers) == self->max_timers) {
zsys_error ("zloop: timer limit reached (max=%d)", self->max_timers);
return -1;
}
int timer_id = s_next_timer_id (self);
s_timer_t *timer = s_timer_new (timer_id, delay, times, handler, arg);
if (timer) {
timer->list_handle = zlistx_add_end (self->timers, timer);
if (!timer->list_handle) {
s_timer_destroy (&timer);
return -1;
}
if (self->verbose)
zsys_debug ("zloop: register timer id=%d delay=%d times=%d",
timer_id, (int) delay, (int) times);
return timer_id;
}
else
return -1;
}
示例8: server_connect
static void
server_connect (server_t *self, const char *endpoint)
{
zsock_t *remote = zsock_new (ZMQ_DEALER);
assert (remote); // No recovery if exhausted
// Never block on sending; we use an infinite HWM and buffer as many
// messages as needed in outgoing pipes. Note that the maximum number
// is the overall tuple set size.
zsock_set_sndhwm (remote, 0);
if (zsock_connect (remote, "%s", endpoint)) {
zsys_error ("bad zgossip endpoint '%s'", endpoint);
zsock_destroy (&remote);
return;
}
// Send HELLO and then PUBLISH for each tuple we have
zgossip_msg_send_hello (remote);
tuple_t *tuple = (tuple_t *) zhash_first (self->tuples);
while (tuple) {
int rc = zgossip_msg_send_publish (remote, tuple->key, tuple->value, 0);
assert (rc == 0);
tuple = (tuple_t *) zhash_next (self->tuples);
}
// Now monitor this remote for incoming messages
engine_handle_socket (self, remote, remote_handler);
zlist_append (self->remotes, remote);
}
示例9: Java_org_zeromq_czmq_Zsys__1_1error
JNIEXPORT void JNICALL
Java_org_zeromq_czmq_Zsys__1_1error (JNIEnv *env, jclass c, jstring format)
{
char *format_ = (char *) (*env)->GetStringUTFChars (env, format, NULL);
zsys_error (format_);
(*env)->ReleaseStringUTFChars (env, format, format_);
}
示例10: server_method
static zmsg_t *
server_method (server_t *self, const char *method, zmsg_t *msg)
{
// Connect to a remote
zmsg_t *reply = NULL;
if (streq (method, "CONNECT")) {
char *endpoint = zmsg_popstr (msg);
assert (endpoint);
server_connect (self, endpoint);
zstr_free (&endpoint);
}
else
if (streq (method, "PUBLISH")) {
char *key = zmsg_popstr (msg);
char *value = zmsg_popstr (msg);
server_accept (self, key, value);
zstr_free (&key);
zstr_free (&value);
}
else
if (streq (method, "STATUS")) {
// Return number of tuples we have stored
reply = zmsg_new ();
assert (reply);
zmsg_addstr (reply, "STATUS");
zmsg_addstrf (reply, "%d", (int) zhashx_size (self->tuples));
}
else
zsys_error ("unknown zgossip method '%s'", method);
return reply;
}
示例11: 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);
}
示例12: s_self_configure
static void
s_self_configure (self_t *self, int port_nbr)
{
assert (port_nbr);
self->port_nbr = port_nbr;
s_self_prepare_udp (self);
zstr_send (self->pipe, self->hostname);
if (streq (self->hostname, ""))
zsys_error ("No broadcast interface found, (ZSYS_INTERFACE=%s)", zsys_interface ());
}
示例13: zsys_set_max_sockets
void
zsys_set_max_sockets (size_t max_sockets)
{
zsys_init ();
ZMUTEX_LOCK (s_mutex);
// If the app is misusing this method, burn it with fire
if (s_open_sockets)
zsys_error ("zsys_max_sockets() is not valid after creating sockets");
assert (s_open_sockets == 0);
s_max_sockets = max_sockets ? max_sockets : zsys_socket_limit ();
ZMUTEX_UNLOCK (s_mutex);
}
示例14: 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;
}
示例15: s_upstream_handle_pipe
static void
s_upstream_handle_pipe (upstream_t *self)
{
char *command = zstr_recv (self->pipe);
if (streq (command, "$TERM")) {
self->terminated = true;
}
else
if (streq (command, "CONNECT")) {
char *endpoint = zstr_recv (self->pipe);
int rc = zsock_connect (self->push, "%s", endpoint);
if (rc != -1)
self->connected = true;
zstr_free (&endpoint);
zsock_bsend (self->pipe, "2", rc);
}
else
if (streq (command, "BIND")) {
char *endpoint = zstr_recv (self->pipe);
int rc = zsock_bind (self->push, "%s", endpoint);
if (rc != -1)
self->connected = true;
zstr_free (&endpoint);
zsock_bsend (self->pipe, "2", rc);
}
else
if (streq (command, "SET_SIZE")) {
int64_t size;
zsock_brecv (self->pipe, "8", &size);
self->size = size;
}
else
if (streq (command, "GET_SIZE")) {
zsock_bsend (self->pipe, "8", self->size);
}
else
if (streq (command, "SET_VARIANCE")) {
int64_t variance;
zsock_brecv (self->pipe, "8", &variance);
self->variance = variance;
}
else
if (streq (command, "GET_VARIANCE")) {
zsock_bsend (self->pipe, "8", self->variance);
}
else {
zsys_error ("upstream: invalid command: %s", command);
assert (false);
}
zstr_free (&command);
}