本文整理汇总了C++中zmq_term函数的典型用法代码示例。如果您正苦于以下问题:C++ zmq_term函数的具体用法?C++ zmq_term怎么用?C++ zmq_term使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zmq_term函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: zsys_socket_limit
size_t
zsys_socket_limit (void)
{
int socket_limit;
#if (ZMQ_VERSION >= ZMQ_MAKE_VERSION (4, 1, 0))
if (s_process_ctx)
socket_limit = zmq_ctx_get (s_process_ctx, ZMQ_SOCKET_LIMIT);
else {
void *ctx = zmq_init (1);
socket_limit = zmq_ctx_get (ctx, ZMQ_SOCKET_LIMIT);
zmq_term (ctx);
}
// ZeroMQ used to report a nonsense value (2^31) which if used would
// on zmq_ctx_set (ZMQ_MAX_SOCKETS) cause an out-of-memory error. So
// if we're running on an older library, enforce a sane limit.
if (socket_limit > 65535)
socket_limit = 65535;
#else
socket_limit = 1024;
#endif
return (size_t) socket_limit;
}
示例2: zctx_destroy
void
zctx_destroy (zctx_t **self_p)
{
assert (self_p);
if (*self_p) {
zctx_t *self = *self_p;
// Destroy all sockets
if (self->sockets)
while (zlist_size (self->sockets))
zctx__socket_destroy (self, zlist_first (self->sockets));
zlist_destroy (&self->sockets);
zmutex_destroy (&self->mutex);
// ZMQ context may not yet be instantiated
if (self->context && !self->shadow)
zmq_term (self->context);
free (self);
*self_p = NULL;
}
}
示例3: catch
bool OTSocket_ZMQ_4::NewContext()
{
if (!m_bInitialized) return false;
m_HasContext = false;
if (!this->CloseSocket(true)) return false;
if (NULL != m_pzmq->context_zmq) zmq_term(m_pzmq->context_zmq);
if (NULL != m_pzmq->context_zmq) delete m_pzmq->context_zmq; m_pzmq->context_zmq = NULL;
try {
m_pzmq->context_zmq = new zmq::context_t(1,31); // Threads, Max Sockets. (31 is a sane default).
}
catch (std::exception& e) {
OTLog::vError("%s: Exception Caught: %s \n", __FUNCTION__, e.what());
OT_FAIL;
}
m_HasContext = true;
return true;
}
示例4: main
int main(int argc, char *argv[])
{
if (argc < 3) return EXIT_FAILURE;
int M = atoi(argv[1]);
int N = atoi(argv[2]);
printf("M: %d, N: %d\n", M, N);
void *ctx = zmq_init(1);
void *b = zmq_socket(ctx, ZMQ_PAIR);
zmq_connect(b, "tcp://localhost:4444");
zmq_msg_t msg;
int val[M];
long long start_time = sc_time();
int i;
for (i=0; i<N; i++) {
int *buf = (int *)malloc(M * sizeof(int));
memset(val, i, M * sizeof(int));
memcpy(buf, val, M * sizeof(int));
zmq_msg_init_data(&msg, buf, M * sizeof(int), _dealloc, NULL);
zmq_send(b, &msg, 0);
zmq_msg_close(&msg);
zmq_msg_init(&msg);
zmq_recv(b, &msg, 0);
memcpy(val, (int *)zmq_msg_data(&msg), zmq_msg_size(&msg));
zmq_msg_close(&msg);
}
long long end_time = sc_time();
printf("zmq_a: Time elapsed: %f sec\n", sc_time_diff(start_time, end_time));
zmq_close(b);
zmq_term(ctx);
return EXIT_SUCCESS;
}
示例5: main
// We will do this all in one thread to emphasize the sequence
// of events...
int main (void)
{
void *context = zmq_init (1);
void *client = zmq_socket (context, ZMQ_ROUTER);
zmq_bind (client, "ipc://routing.ipc");
void *worker = zmq_socket (context, ZMQ_REP);
zmq_setsockopt (worker, ZMQ_IDENTITY, "A", 1);
zmq_connect (worker, "ipc://routing.ipc");
// Wait for the worker to connect so that when we send a message
// with routing envelope, it will actually match the worker...
sleep (1);
// Send papa address, address stack, empty part, and request
s_sendmore (client, "A");
s_sendmore (client, "address 3");
s_sendmore (client, "address 2");
s_sendmore (client, "address 1");
s_sendmore (client, "");
s_send (client, "This is the workload");
// Worker should get just the workload
printf("begine dump worker\n");
s_dump (worker);
// We don't play with envelopes in the worker
s_send (worker, "This is the reply");
// Now dump what we got off the ROUTER socket...
printf("begine dump client\n");
s_dump (client);
zmq_close (client);
zmq_close (worker);
zmq_term (context);
return 0;
}
示例6: main
int main (void)
{
// wait_for_key("before zmq_init");
void *context = zmq_init (1);
// wait_for_key("before fork");
pid_t pid = fork();
if (pid) {
// wait_for_key("in parent");
int status;
int rpid = waitpid(pid, &status, 0);
printf("[%d] waited for pid %d, got %d status %d\n", getpid(), pid, rpid, status);
printf("[%d] Parent is exiting\n", getpid());
}
else {
zmq_term(context);
// wait_for_key("in child");
exit(0);
}
return 0;
}
示例7: main
int main (void)
{
fprintf (stderr, "test_router_mandatory_tipc running...\n");
void *ctx = zmq_init (1);
assert (ctx);
// Creating the first socket.
void *sa = zmq_socket (ctx, ZMQ_ROUTER);
assert (sa);
int rc = zmq_bind (sa, "tipc://{15560,0,0}");
assert (rc == 0);
// Sending a message to an unknown peer with the default setting
rc = zmq_send (sa, "UNKNOWN", 7, ZMQ_SNDMORE);
assert (rc == 7);
rc = zmq_send (sa, "DATA", 4, 0);
assert (rc == 4);
int mandatory = 1;
// Set mandatory routing on socket
rc = zmq_setsockopt (sa, ZMQ_ROUTER_MANDATORY, &mandatory, sizeof (mandatory));
assert (rc == 0);
// Send a message and check that it fails
rc = zmq_send (sa, "UNKNOWN", 7, ZMQ_SNDMORE | ZMQ_DONTWAIT);
assert (rc == -1 && errno == EHOSTUNREACH);
rc = zmq_close (sa);
assert (rc == 0);
rc = zmq_term (ctx);
assert (rc == 0);
return 0 ;
}
示例8: _tmain
int _tmain(int argc, _TCHAR* argv[])
{
setlocale(LC_ALL,"Chinese");
setlocale(LC_ALL,"chs");
void *m_context;
void *m_subscriber;
char m_subAddr[64];
m_context = zmq_init(1);
m_subscriber = zmq_socket(m_context,ZMQ_SUB);
char *puberIp = "127.0.0.1";
WORD port = 8585;
memset(m_subAddr,0,sizeof(m_subAddr));
sprintf_s(m_subAddr,"tcp://%s:%d",puberIp,port);
zmq_connect(m_subscriber,m_subAddr);
char *option = "642";
int ret = zmq_setsockopt(m_subscriber,ZMQ_SUBSCRIBE,"642",strlen(option));
while (1)
{
BYTE buffer[1024] = {0};
DWORD bufLen = sizeof(buffer);
DWORD gotLen = zmq_recv(m_subscriber,buffer,bufLen,0);
printf("收到发布信息:%s\n",buffer);
}
zmq_close(m_subscriber);
zmq_term(m_context);
return 0;
}
示例9: main
int main (int argc, char *argv [])
{
fprintf (stderr, "test_router_behavior running...\n");
void *ctx = zmq_init (1);
assert (ctx);
// Creating the first socket.
void *sa = zmq_socket (ctx, ZMQ_ROUTER);
assert (sa);
int rc = zmq_bind (sa, "tcp://127.0.0.1:15560");
assert (rc == 0);
// Sending a message to an unknown peer with the default behavior.
rc = zmq_send (sa, "UNKNOWN", 7, ZMQ_SNDMORE);
assert (rc == 7);
rc = zmq_send (sa, "DATA", 4, 0);
assert (rc == 4);
int behavior = 1;
// Setting the socket behavior to a new mode.
rc = zmq_setsockopt (sa, ZMQ_ROUTER_BEHAVIOR, &behavior, sizeof (behavior));
assert (rc == 0);
// Sending a message to an unknown peer with verbose behavior.
rc = zmq_send (sa, "UNKNOWN", 7, ZMQ_SNDMORE | ZMQ_DONTWAIT);
assert (rc == -1 && errno == EAGAIN);
rc = zmq_close (sa);
assert (rc == 0);
rc = zmq_term (ctx);
assert (rc == 0);
return 0 ;
}
示例10: main
int main (void)
{
void *context = zmq_init (1);
// This is where the weather server sits
void *frontend = zmq_socket (context, ZMQ_XSUB);
zmq_connect (frontend, "tcp://192.168.55.210:5556");
// This is our public endpoint for subscribers
void *backend = zmq_socket (context, ZMQ_XPUB);
zmq_bind (backend, "tcp://10.1.1.0:8100");
// Subscribe on everything
zmq_setsockopt (frontend, ZMQ_SUBSCRIBE, "", 0);
// Shunt messages out to our own subscribers
while (1) {
while (1) {
zmq_msg_t message;
int64_t more;
// Process all parts of the message
zmq_msg_init (&message);
zmq_recv (frontend, &message, 0);
size_t more_size = sizeof (more);
zmq_getsockopt (frontend, ZMQ_RCVMORE, &more, &more_size);
zmq_send (backend, &message, more? ZMQ_SNDMORE: 0);
zmq_msg_close (&message);
if (!more)
break; // Last message part
}
}
// We don't actually get here but if we did, we'd shut down neatly
zmq_close (frontend);
zmq_close (backend);
zmq_term (context);
return 0;
}
示例11: main
int main () {
void *context = zmq_init (1);
// Subscriber tells us when it's ready here
void *sync = zmq_socket (context, ZMQ_PULL);
zmq_bind (sync, "tcp://*:5564");
// We send updates via this socket
void *publisher = zmq_socket (context, ZMQ_PUB);
zmq_bind (publisher, "tcp://*:5565");
// Prevent publisher overflow from slow subscribers
uint64_t hwm = 1;
zmq_setsockopt (publisher, ZMQ_HWM, &hwm, sizeof (hwm));
// Specify swap space in bytes, this covers all subscribers
uint64_t swap = 25000000;
zmq_setsockopt (publisher, ZMQ_SWAP, &swap, sizeof (swap));
// Wait for synchronization request
char *string = s_recv (sync);
free (string);
// Now broadcast exactly 10 updates with pause
int update_nbr;
for (update_nbr = 0; update_nbr < 10; update_nbr++) {
char string [20];
sprintf (string, "Update %d", update_nbr);
s_send (publisher, string);
sleep (1);
}
s_send (publisher, "END");
sleep (1); // Give 0MQ/2.0.x time to flush output
zmq_term (context);
return 0;
}
示例12: main
int main (void)
{
void *context = zmq_init (1);
void *client = zmq_socket (context, ZMQ_ROUTER);
zmq_bind (client, "ipc://routing.ipc");
pthread_t worker;
pthread_create (&worker, NULL, worker_task_a, NULL);
pthread_create (&worker, NULL, worker_task_b, NULL);
// Wait for threads to connect, since otherwise the messages
// we send won't be routable.
sleep (1);
// Send 10 tasks scattered to A twice as often as B
int task_nbr;
srandom ((unsigned) time (NULL));
for (task_nbr = 0; task_nbr < 10; task_nbr++) {
// Send two message parts, first the address...
if (randof (3) > 0)
s_sendmore (client, "A");
else
s_sendmore (client, "B");
// And then the workload
s_send (client, "This is the workload");
}
s_sendmore (client, "A");
s_send (client, "END");
s_sendmore (client, "B");
s_send (client, "END");
zmq_close (client);
zmq_term (context);
return 0;
}
示例13: ciao_zmq_term_
// -- terminatednevn the ZMQ context for the current thread -------------
void
ciao_zmq_term_(void) {
// .. Execute once per process ...................................
pthread_once(&zmq_ll_once, make_state_key);
// .. Access the state pointer ...................................
ciao_zmq_state *state =
(ciao_zmq_state *)pthread_getspecific(zmq_ll_state_key);
// .. Finish if there is currently no state (nothing to temrinate) ..
if(state!=NULL) {
// .. Void the state for the current thread ....................
pthread_setspecific(zmq_ll_state_key, NULL);
// .. Deallocate all error records .............................
while(state->error_list != NULL) {
ciao_zmq_error_record *rec= state->error_list;
state->error_list= state->error_list->next;
free(rec);
}
// .. Close all sockets and deallocate association tables ......
while(state->socket_list !=NULL) {
ciao_zmq_socket_assoc *assoc= state->socket_list;
state->socket_list= state->socket_list->next;
zmq_close(assoc->zmq_socket);
free(assoc);
}
// .. Finally, terminate the context ...........................
zmq_term(state->zmq_context);
// .. Deallocate the state record ..............................
free(state);
}
}
示例14: main
int main(int argc, char **argv){
init_options();
parse_options(argc, argv);
if (GlobalArgs.helpflag || !GlobalArgs.index_name || !GlobalArgs.server_address){
tableserver_usage();
return 0;
}
/* init daemon */
init_process();
if (init_index() < 0){
syslog(LOG_CRIT,"MAIN ERR: unable to init index");
exit(1);
}
void *ctx = zmq_init(1);
if (!ctx){
syslog(LOG_CRIT,"MAIN ERR: unable to init zmq ctx");
exit(1);
}
/* save to global variable to be used in signal handler */
main_ctx = ctx;
if (init_server(ctx) < 0){
syslog(LOG_CRIT,"MAIN ERR: unable to init server");
exit(1);
}
subscriber(ctx);
zmq_term(ctx);
return 0;
}
示例15: worker_task_a
// We have two workers, here we copy the code, normally these would
// run on different boxes...
//
static void *
worker_task_a (void *args)
{
void *context = zmq_init (1);
void *worker = zmq_socket (context, ZMQ_DEALER);
zmq_setsockopt (worker, ZMQ_IDENTITY, "A", 1);
zmq_connect (worker, "ipc://routing.ipc");
int total = 0;
while (1) {
// We receive one part, with the workload
char *request = s_recv (worker);
int finished = (strcmp (request, "END") == 0);
free (request);
if (finished) {
printf ("A received: %d\n", total);
break;
}
total++;
}
zmq_close (worker);
zmq_term (context);
return NULL;
}