本文整理汇总了C++中zmq_close函数的典型用法代码示例。如果您正苦于以下问题:C++ zmq_close函数的具体用法?C++ zmq_close怎么用?C++ zmq_close使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zmq_close函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: main
int main (void)
{
setup_test_environment();
void *ctx = zmq_ctx_new ();
assert (ctx);
void *sb = zmq_socket (ctx, ZMQ_REP);
assert (sb);
int rc = zmq_bind (sb, "inproc://a");
assert (rc == 0);
rc = zmq_unbind (sb, "inproc://a");
assert (rc == 0);
rc = zmq_close (sb);
assert (rc == 0);
rc = zmq_ctx_term (ctx);
assert (rc == 0);
return 0;
}
示例3: main
int main (void)
{
setup_test_environment ();
void *ctx = zmq_ctx_new ();
assert (ctx);
void *sock = zmq_socket (ctx, ZMQ_PUB);
assert (sock);
int rc = zmq_connect (sock, "tcp://localhost:1234");
assert (rc == 0);
rc = zmq_connect (sock, "tcp://[::1]:1234");
assert (rc == 0);
rc = zmq_connect (sock, "tcp://localhost:invalid");
assert (rc == -1);
rc = zmq_connect (sock, "tcp://in val id:1234");
assert (rc == -1);
rc = zmq_connect (sock, "tcp://");
assert (rc == -1);
rc = zmq_connect (sock, "tcp://192.168.0.200:*");
assert (rc == -1);
rc = zmq_connect (sock, "invalid://localhost:1234");
assert (rc == -1);
assert (errno == EPROTONOSUPPORT);
rc = zmq_close (sock);
assert (rc == 0);
rc = zmq_ctx_term (ctx);
assert (rc == 0);
return 0;
}
示例4: main
int main(void)
{
void *context = zmq_ctx_new();
//Socket to connect to Server
void *requester = zmq_socket(context, ZMQ_REQ);
zmq_connect(requester, "tcp://localhost:8888");
int request_nbr;
for(request_nbr = 0; request_nbr != 10; request_nbr++)
{
s_send(requester, "Hello");
char* string = s_recv(requester);
printf("Received reply %d [%s] \n", request_nbr, string);
free(string);
}
zmq_close(requester);
zmq_ctx_destroy(context);
return 0;
}
示例5: create_sub_socket
int create_sub_socket(void* ctx) {
std::stringstream conn;
conn << "tcp://" << g_sip << ":" << g_port_sub;
void * sub = zmq_socket(ctx, ZMQ_SUB);
int rc = zmq_connect(sub, conn.str().c_str());
assert(rc == 0);
if (rc != 0) {
std::cerr << "Error Connect to " << conn.str() << " errno " << errno << std::endl;
zmq_close(sub);
exit(EXIT_FAILURE);
}
char temp[256] = { 0 };
sprintf(temp, "%s ", g_sn);
printf("Subscribe id: %s\n", temp);
rc = zmq_setsockopt(sub, ZMQ_SUBSCRIBE, temp, strlen(temp));
assert(rc == 0);
rc = zmq_setsockopt(sub, ZMQ_SUBSCRIBE, "ALL ", strlen("ALL "));
assert(rc == 0);
g_sub_socket = sub;
return 0;
}
示例6: redirect_count
//********************************************************************************
// Function: redirect_count
//
// Description: Recieve Control Plane redirect count.
//********************************************************************************
static int32_t redirect_count(void)
{
void *context = zmq_ctx_new ();
void *requester = zmq_socket(context, ZMQ_REQ);
int32_t timeo{};
zmq_setsockopt(requester, ZMQ_LINGER, (void*) &timeo, sizeof(timeo));
char buffer[64];
sprintf(buffer, "tcp://localhost:%d", TCPLANE_SERVICE);
zmq_connect(requester, buffer);
sprintf(buffer, "%d", redirectCount);
zmq_send(requester, buffer, strlen(buffer), 0);
size_t size = timed_read(requester, buffer, sizeof(buffer), READ_TIMEOUT);
if(size)
size = atoi(buffer);
zmq_close(requester);
zmq_ctx_destroy(context);
return size;
}
示例7: main
int main (int argc, char const *argv[]) {
void* context = zmq_ctx_new();
//create a SUB socket
void* subscriber = zmq_socket(context, ZMQ_SUB);
const char* filter;
if(argc > 1) {
filter = argv[1];
} else {
filter = "Company1|";
}
printf("Collecting stock information from the server.\n");
int conn = zmq_connect(subscriber, "tcp://localhost:4040");
// must set a subscription for SUB socket
conn = zmq_setsockopt(subscriber, ZMQ_SUBSCRIBE, filter, strlen(filter));
int i = 0;
for(i = 0; i < 10; i++) {
zmq_msg_t reply;
zmq_msg_init(&reply);
// receive the message, previous message is deallocated
zmq_msg_recv(&reply, subscriber, 0);
int length = zmq_msg_size(&reply);
char* value = malloc(length + 1);
memcpy(value, zmq_msg_data(&reply), length);
zmq_msg_close(&reply);
printf("%s\n", value);
free(value);
}
zmq_close(subscriber);
zmq_ctx_destroy(context);
return 0;
}
示例8: main
void main(){
fprintf(stdout,"##### Client-1 is running - C Broker Test #####\n");
void *context = zmq_ctx_new ();
void *requester = zmq_socket (context, ZMQ_PUSH);
zmq_connect (requester, "tcp://127.0.0.1:5559");
char *str_message="i am client-1";
int request_number;
//sending 1000000 requests from client
for (request_number = 1; request_number <= 1000000; request_number++) {
zstr_send (requester, str_message);
}
zmq_close (requester);
zmq_ctx_destroy (context);
}
示例9: req_socket_monitor
// REQ socket monitor thread
static void req_socket_monitor (void *ctx)
{
zmq_event_t event;
std::string ep ;
int rc;
void *s = zmq_socket (ctx, ZMQ_PAIR);
assert (s);
rc = zmq_connect (s, "inproc://monitor.req");
assert (rc == 0);
while (!read_msg(s, event, ep)) {
assert (ep == addr);
switch (event.event) {
case ZMQ_EVENT_CONNECTED:
assert (event.value > 0);
req_socket_events |= ZMQ_EVENT_CONNECTED;
req2_socket_events |= ZMQ_EVENT_CONNECTED;
break;
case ZMQ_EVENT_CONNECT_DELAYED:
assert (event.value != 0);
req_socket_events |= ZMQ_EVENT_CONNECT_DELAYED;
break;
case ZMQ_EVENT_CLOSE_FAILED:
assert (event.value != 0);
req_socket_events |= ZMQ_EVENT_CLOSE_FAILED;
break;
case ZMQ_EVENT_CLOSED:
assert (event.value != 0);
req_socket_events |= ZMQ_EVENT_CLOSED;
break;
case ZMQ_EVENT_DISCONNECTED:
assert (event.value != 0);
req_socket_events |= ZMQ_EVENT_DISCONNECTED;
break;
}
}
zmq_close (s);
}
示例10: assert
bool CZMQAbstractPublishNotifier::Initialize(void *pcontext)
{
assert(!psocket);
// check if address is being used by other publish notifier
std::multimap<std::string, CZMQAbstractPublishNotifier*>::iterator i = mapPublishNotifiers.find(address);
if (i==mapPublishNotifiers.end())
{
psocket = zmq_socket(pcontext, ZMQ_PUB);
if (!psocket)
{
zmqError("Failed to create socket");
return false;
}
int rc = zmq_bind(psocket, address.c_str());
if (rc!=0)
{
zmqError("Failed to bind address");
zmq_close(psocket);
return false;
}
// register this notifier for the address, so it can be reused for other publish notifier
mapPublishNotifiers.insert(std::make_pair(address, this));
return true;
}
else
{
LogPrint(BCLog::ZMQ, "zmq: Reusing socket for address %s\n", address);
psocket = i->second->psocket;
mapPublishNotifiers.insert(std::make_pair(address, this));
return true;
}
}
示例11: zmq_socket
void Executor::work()
{
void *socket = zmq_socket(vcontext, ZMQ_REP);
zmq_msg_t zMsg;
char *cstring = NULL;
size_t msgSize = 0;
zmq_connect(socket, "inproc://storageWorkers");
while(vstop==false)
{
zmq_msg_init(&zMsg);
zmq_msg_recv(&zMsg, socket, 0);
msgSize = zmq_msg_size(&zMsg);
cstring = new char[msgSize+1];
memcpy(cstring, zmq_msg_data(&zMsg), msgSize);
zmq_msg_close(&zMsg);
cstring[msgSize] = '\0';
std::string str(cstring);
delete cstring;
Message* msg = vmsgFactory->parse(str);
Action *action = vactionFactory->parse(*msg);
delete msg;
msg = action->execute();
delete action;
msgSize = msg->toString().size()+1;
zmq_msg_init_size(&zMsg, msgSize);
memcpy(zmq_msg_data(&zMsg), msg->toString().c_str(), msgSize);
delete msg;
zmq_msg_send(&zMsg, socket, 0);
zmq_msg_close(&zMsg);
}
zmq_close(socket);
}
示例12: 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 ;
}
示例13: subscriber_thread_main
static void subscriber_thread_main (void *pvoid)
{
const proxy_hwm_cfg_t *cfg = (proxy_hwm_cfg_t *) pvoid;
const int idx = cfg->thread_idx;
void *subsocket = zmq_socket (cfg->context, ZMQ_SUB);
assert (subsocket);
set_hwm (subsocket);
TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (subsocket, ZMQ_SUBSCRIBE, 0, 0));
TEST_ASSERT_SUCCESS_ERRNO (
zmq_connect (subsocket, cfg->backend_endpoint[idx]));
// Receive message_count messages
uint64_t rxsuccess = 0;
bool success = true;
while (success) {
zmq_msg_t msg;
int rc = zmq_msg_init (&msg);
assert (rc == 0);
rc = zmq_msg_recv (&msg, subsocket, 0);
if (rc != -1) {
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg));
rxsuccess++;
}
if (rxsuccess == message_count)
break;
}
// Cleanup
zmq_close (subsocket);
printf ("subscriber thread ended\n");
}
示例14: _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;
}
示例15: worker_routine
// worker thread function
static void* worker_routine (void *context)
{
// socket to talk to dispatcher
void* receiver = zmq_socket(context, ZMQ_REP);
if (!receiver)
{
dzlog_error("create socket to talk to dispatcher failed, err: %s", zmq_strerror(errno));
return NULL;
}
if (zmq_connect(receiver, "inproc://workers") != 0)
{
dzlog_error("worker thread connect worker_socket failed, err: %s", zmq_strerror(errno));
return NULL;
}
dzlog_info("worker thread run ...");
while (1)
{
zmq_msg_t request;
zmq_msg_init(&request);
zmq_recvmsg(receiver, &request, 0);
printf("Recv Hello\n");
zmq_msg_close(&request);
sleep(1);
zmq_msg_t reply;
zmq_msg_init_size(&reply, 5);
memcpy(zmq_msg_data (&reply), "World", 5);
zmq_sendmsg(receiver, &reply, 0);
zmq_msg_close(&reply);
}
zmq_close (receiver);
return NULL;
}