本文整理汇总了C++中zmq_send函数的典型用法代码示例。如果您正苦于以下问题:C++ zmq_send函数的具体用法?C++ zmq_send怎么用?C++ zmq_send使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zmq_send函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_block_on_send_no_peers
void test_block_on_send_no_peers (void *ctx)
{
void *sc = zmq_socket (ctx, ZMQ_REQ);
assert (sc);
int timeout = 100;
int rc = zmq_setsockopt (sc, ZMQ_SNDTIMEO, &timeout, sizeof (timeout));
assert (rc == 0);
rc = zmq_send (sc, 0, 0, ZMQ_DONTWAIT);
assert (rc == -1);
assert (errno == EAGAIN);
rc = zmq_send (sc, 0, 0, 0);
assert (rc == -1);
assert (errno == EAGAIN);
rc = zmq_close (sc);
assert (rc == 0);
}
示例2: main
int main (int argc, char *argv [])
{
const char *host;
int message_size;
int message_count;
void *handle;
int eid;
int counter;
void *out_buf;
int rc;
/* Parse command line arguments. */
if (argc != 4) {
printf ("usage: c_remote_thr <hostname> <message-size> "
"<message-count>\n");
return 1;
}
host = argv [1];
message_size = atoi (argv [2]);
message_count = atoi (argv [3]);
/* Create 0MQ transport. */
handle = zmq_create (host);
/* Create the wiring. */
eid = zmq_create_exchange (handle, "E", ZMQ_SCOPE_LOCAL, NULL,
ZMQ_STYLE_LOAD_BALANCING);
assert (eid != -1);
rc = zmq_bind (handle, "E", "Q", NULL, NULL);
assert (rc != -1);
/* Create message data to send. */
out_buf = malloc (message_size);
assert (out_buf);
for (counter = 0; counter != message_count + 1; counter ++)
zmq_send (handle, eid, out_buf, message_size, ZMQ_TRUE);
/* Wait till all messages are sent. */
#ifdef ZMQ_HAVE_WINDOWS
Sleep (5000);
#else
sleep (5);
#endif
/* Destroy 0MQ transport. */
zmq_destroy (handle);
/* Clean up. */
free (out_buf);
return 0;
}
示例3: zmqdrv_send
static void
zmqdrv_send(zmq_drv_t *drv, ErlIOVec *ev)
{
ErlDrvBinary* bin = ev->binv[1];
char* bytes = bin->orig_bytes;
uint32_t idx = ntohl(*(uint32_t*)(bytes+1));
zmq_sock_info* si = drv->get_socket_info(idx);
uint32_t flags = ntohl(*(uint32_t*)(bytes+5));
void* data = (void *)(bytes + 9);
size_t size = bin->orig_size - 9;
if (idx > drv->zmq_socket_count || !si) {
zmqdrv_error_code(drv, ENODEV);
return;
}
#ifdef ZMQDRV_DEBUG
uint32_t events;
size_t events_size = sizeof(events);
zmq_getsockopt(si->socket, ZMQ_EVENTS, &events, &events_size);
zmqdrv_fprintf("sending %p [idx=%d] %lu bytes (events=%d)\r\n", si->socket, idx, size, events);
#endif
if (si->out_caller != 0) {
// There's still an unwritten message pending
zmqdrv_error_code(drv, EBUSY);
return;
}
// Increment the reference count on binary so that zmq can
// take ownership of it.
driver_binary_inc_refc(bin);
if (zmq_msg_init_data(&si->out_msg, data, size, &zmq_free_binary, bin)) {
zmqdrv_error_code(drv, zmq_errno());
driver_binary_dec_refc(bin);
return;
}
if (zmq_send(si->socket, &si->out_msg, flags | ZMQ_NOBLOCK) == 0) {
zmqdrv_ok(drv);
zmqdrv_ready_input((ErlDrvData)drv, (ErlDrvEvent)si->fd);
} else {
int e = zmq_errno();
if (e == EAGAIN) {
// No msg returned to caller - make him wait until async
// send succeeds
si->out_caller = driver_caller(drv->port);
return;
}
zmqdrv_error_code(drv, e);
}
zmq_msg_close(&si->out_msg);
}
示例4: reply_config
void reply_config()
{
//zmq_msg_t reply;
std::stringstream config_s;
config_s << config;
int reply_size = config_s.str().size();
zmq_send(zmq_responder,
config_s.str().c_str(),
reply_size,
0);
}
示例5: logevent
/* Send formatted message to url */
int
logevent(const char *url, const char *message)
{
int rc, result;
void *ctx, *socket;
zmq_msg_t query;
zmq_pollitem_t items[1];
/* Send the message */
rc = zmq_msg_init_size(&query, strlen(message));
assert(rc == 0);
memcpy(zmq_msg_data(&query), message, strlen(message));
ctx = zmq_init (1, 1, ZMQ_POLL);
assert(ctx);
socket = zmq_socket(ctx, ZMQ_REQ);
assert(socket);
rc = zmq_connect(socket, url);
assert(rc == 0);
rc = zmq_send(socket, &query, 0);
assert(rc == 0);
zmq_msg_close(&query);
/* Wait for a reply */
rc = zmq_msg_init(&query);
assert(rc == 0);
items[0].socket = socket;
items[0].events = ZMQ_POLLIN;
rc = my_zmqpoll(items, 1, SEND_TIMEOUT);
assert(rc >= 0);
rc = zmq_recv(socket, &query, ZMQ_NOBLOCK);
if (rc == -1 && errno == EAGAIN) {
result = 0;
} else {
assert(rc == 0);
zmq_msg_close(&query);
result = 1;
}
/* Clean up - FIXME: random SEGV on zmq_term
zmq_close(socket);
zmq_term(ctx);
*/
return result;
}
示例6: endFrame
void endFrame()
{
dataCache_t * temp = dataCacheHead;
rI2CTX_beginFrame();
while(temp != NULL)
{
/*
printf("%d ",temp->decParam.index);
switch(temp->decParam.type)
{
case rI2C_INT8: printf("\tINT8 %d\n",*(int8_t*)(temp->decParam.val));break;
case rI2C_UINT8: printf("\tUINT8 %d\n",*(uint8_t*)(temp->decParam.val));break;
case rI2C_INT16: printf("\tINT16 %d\n",*(int16_t*)(temp->decParam.val));break;
case rI2C_UINT16: printf("\tUINT16 %d\n",*(uint16_t*)(temp->decParam.val));break;
case rI2C_INT32: printf("\tINT32 %d\n",*(int32_t*)(temp->decParam.val));break;
case rI2C_UINT32: printf("\tUINT32 %d\n",*(uint32_t*)(temp->decParam.val));break;
case rI2C_INT64: printf("\tINT64 %"PRId64"\n",*(int64_t*)(temp->decParam.val));break;
case rI2C_UINT64: printf("\tUINT64 %"PRId64"\n",*(uint64_t*)(temp->decParam.val));break;
case rI2C_FLOAT: printf("\tFLOAT %f\n",*(float*)(temp->decParam.val));break;
case rI2C_DOUBLE: printf("\tDOUBLE %f\n",*(double*)(temp->decParam.val));break;
}*/
switch(temp->decParam.type)
{
case rI2C_INT8: rI2CTX_addParameter_int8(temp->decParam.index, *(int8_t*)(temp->decParam.val));break;
case rI2C_UINT8: rI2CTX_addParameter_uint8(temp->decParam.index,*(uint8_t*)(temp->decParam.val));break;
case rI2C_INT16: rI2CTX_addParameter_int16(temp->decParam.index,*(int16_t*)(temp->decParam.val));break;
case rI2C_UINT16: rI2CTX_addParameter_uint16(temp->decParam.index,*(uint16_t*)(temp->decParam.val));break;
case rI2C_INT32: rI2CTX_addParameter_int32(temp->decParam.index,*(int32_t*)(temp->decParam.val));break;
case rI2C_UINT32: rI2CTX_addParameter_uint32(temp->decParam.index,*(uint32_t*)(temp->decParam.val));break;
case rI2C_INT64: rI2CTX_addParameter_int64(temp->decParam.index,*(int64_t*)(temp->decParam.val));break;
case rI2C_UINT64: rI2CTX_addParameter_uint64(temp->decParam.index,*(uint64_t*)(temp->decParam.val));break;
case rI2C_FLOAT: rI2CTX_addParameter_float(temp->decParam.index,*(float*)(temp->decParam.val));break;
case rI2C_DOUBLE: rI2CTX_addParameter_double(temp->decParam.index,*(double*)(temp->decParam.val));break;
}
temp = temp->next;
}
rI2CTX_endFrame();
if((rI2CTX_bufferPos + strlen(nodeName) + strlen(nodeName)) < sizeof(buffer)){
char * t = "telemetry ";
memcpy(&buffer,t,strlen(t));
memcpy(buffer + strlen(t),nodeName,strlen(nodeName));
memcpy(buffer + strlen(t) + strlen(nodeName), &rI2CTX_buffer,rI2CTX_bufferPos + strlen(t) + strlen(nodeName));
zmq_send(pubTelemetry, buffer, rI2CTX_bufferPos+strlen(t)+strlen(nodeName), 0);
}else{
printf("ZMQ TX buffer too small.\n");
}
}
示例7: while
void *run(void *arg)
{
int ret;
char buf[256];
while (1) {
zmq_recv(rep, buf, sizeof(buf), 0);
printf("rep recv: %s\n", buf);
ret = zmq_send(rep, "rep recv done", 16, 0);
assert(ret == 16);
}
}
示例8: main
int main (int argc, char *argv [])
{
const char *bind_to;
int roundtrip_count;
int message_size;
void *ctx;
void *s;
int rc;
int i;
zmq_msg_t msg;
if (argc != 4) {
printf ("usage: local_lat <bind-to> <message-size> "
"<roundtrip-count>\n");
return 1;
}
bind_to = argv [1];
message_size = atoi (argv [2]);
roundtrip_count = atoi (argv [3]);
ctx = zmq_init (1, 1, 0);
assert (ctx);
s = zmq_socket (ctx, ZMQ_REP);
assert (s);
rc = zmq_bind (s, bind_to);
assert (rc == 0);
rc = zmq_msg_init (&msg);
assert (rc == 0);
for (i = 0; i != roundtrip_count; i++) {
rc = zmq_recv (s, &msg, 0);
assert (rc == 0);
assert (zmq_msg_size (&msg) == message_size);
rc = zmq_send (s, &msg, 0);
assert (rc == 0);
}
rc = zmq_msg_close (&msg);
assert (rc == 0);
zmq_sleep (1);
rc = zmq_close (s);
assert (rc == 0);
rc = zmq_term (ctx);
assert (rc == 0);
return 0;
}
示例9: while
void Chat::run()
{
char buff[1024] = { 0 };
zmq_pollitem_t items[3] = { 0 };
items[0].socket = subscriber_;
items[0].events = ZMQ_POLLIN;
items[1].socket = gate_;
items[1].events = ZMQ_POLLIN;
items[2].fd = STDIN_FILENO;
items[2].events = ZMQ_POLLIN;
while(true)
{
int len;
int ret = zmq_poll(items, 3, -1);
if (items[0].revents & ZMQ_POLLIN)
{
len = zmq_recv(items[0].socket, buff, sizeof(buff), 0);
if (len > 0)
{
buff[len] = 0;
std::cout << buff << std::endl;
}
else
{
std::cerr << zmq_strerror(errno);
}
}
if (items[1].revents & ZMQ_POLLIN)
{
len = zmq_recv(items[1].socket, buff, sizeof(buff), 0);
if (len > 0)
{
handle_gate((Action*)buff);
}
else
{
std::cerr << zmq_strerror(errno);
}
}
if (items[2].revents & ZMQ_POLLIN)
{
std::cin.getline(buff, sizeof(buff));
zmq_send(publisher_, buff, std::cin.gcount(), 0);
}
}
}
示例10: LOG_DEBUG
void Statistic::reporter()
{
LOG_DEBUG("Initializing inproc://%s statistic reporter", _statname.c_str());
_publisher = stack_data.stats_aggregator->get_internal_publisher(_statname);
std::vector<std::string> new_value;
while (_stat_q.pop(new_value))
{
LOG_DEBUG("Send new value for statistic %s, size %d", _statname.c_str(), new_value.size());
std::string status = "OK";
// If there's no message, just send the envelope and status line.
if (new_value.empty())
{
zmq_send(_publisher, _statname.c_str(), _statname.length(), ZMQ_SNDMORE);
zmq_send(_publisher, status.c_str(), status.length(), 0);
}
else
{
// Otherwise send the envelope, status line, and body, remembering to set SNDMORE on all
// but the last section.
zmq_send(_publisher, _statname.c_str(), _statname.length(), ZMQ_SNDMORE);
zmq_send(_publisher, status.c_str(), status.length(), ZMQ_SNDMORE);
std::vector<std::string>::iterator it;
for (it = new_value.begin(); it + 1 != new_value.end(); ++it)
{
zmq_send(_publisher, it->c_str(), it->length(), ZMQ_SNDMORE);
}
zmq_send(_publisher, it->c_str(), it->length(), 0);
}
}
}
示例11: main
int main(int argc, char * argv[])
{
void * pCtx = NULL;
void * pSock = NULL;
//使用tcp协议进行通信,需要连接的目标机器IP地址为192.168.1.2
//通信使用的网络端口 为7766
const char * pAddr = "tcp://127.0.0.1:7766";//"tcp://192.168.1.198:7766";
//创建context
if ((pCtx = zmq_ctx_new()) == NULL)
{
return 0;
}
//创建socket
if ((pSock = zmq_socket(pCtx, ZMQ_DEALER)) == NULL)
{
zmq_ctx_destroy(pCtx);
return 0;
}
int iSndTimeout = 5000;// millsecond
//设置接收超时
if (zmq_setsockopt(pSock, ZMQ_RCVTIMEO, &iSndTimeout, sizeof(iSndTimeout)) < 0)
{
zmq_close(pSock);
zmq_ctx_destroy(pCtx);
return 0;
}
//连接目标IP192.168.1.2,端口7766
if (zmq_connect(pSock, pAddr) < 0)
{
zmq_close(pSock);
zmq_ctx_destroy(pCtx);
return 0;
}
//循环发送消息
while (1)
{
static int i = 0;
char szMsg[1024] = { 0 };
sprintf_s(szMsg, "hello world : %3d", i++);
printf("Enter to send...\n");
if (zmq_send(pSock, szMsg, sizeof(szMsg), 0) < 0)
{
fprintf(stderr, "send message faild\n");
continue;
}
printf("send message : [%s] succeed\n", szMsg);
getchar();
}
return 0;
}
示例12: main
int main(int argc, char *argv[])
{
if (argc < 2) return EXIT_FAILURE;
int N = atoi(argv[1]);
printf("N: %d\n", N);
void *ctx = zmq_init(1);
void *server = zmq_socket(ctx, ZMQ_REQ); // Server
assert(server);
int rc;
rc = zmq_connect(server, "tcp://localhost:8889"); // Actively connect to subscribers
assert(rc == 0);
int *val = (int *)calloc(N, sizeof(int));
zmq_msg_t msg;
long long start_time = sc_time();
// Send
int *buf = (int *)calloc(N, sizeof(int));
memcpy(buf, val, N * sizeof(int));
zmq_msg_init_data(&msg, buf, N * sizeof(int), _dealloc, NULL);
zmq_send(server, &msg, 0);
zmq_msg_close(&msg);
// Receive
zmq_msg_init(&msg);
zmq_recv(server, &msg, 0);
memcpy(val, (int *)zmq_msg_data(&msg), zmq_msg_size(&msg));
zmq_msg_close(&msg);
long long end_time = sc_time();
printf("%s: Time elapsed: %f sec\n", argv[0], sc_time_diff(start_time, end_time));
#ifdef __DEBUG__
int i;
printf("%s [ ", argv[0]);
for (i=0; i<N; ++i) {
printf("%d ", val[i]);
}
printf("]\n");
#endif
free(val);
zmq_close(server);
zmq_term(ctx);
return EXIT_SUCCESS;
}
示例13: zmq_send
void ZmqAppender::append(const log4cplus::spi::InternalLoggingEvent& event)
{
if (m_responder != NULL)
{
log4cplus::tostringstream oss;
layout->formatAndAppend(oss, event);
tstring formattedEvent = oss.str();
zmq_send(m_responder, formattedEvent.c_str(), formattedEvent.length(), 0);
char controlByte;
zmq_recv(m_responder, &controlByte, 1, 0);
}
}
示例14: strcpy
void Heartbeat::report_newcomer(const std::string& peer_id, const std::string& peer_ip)
{
Action action;
action.type_ = JOIN;
strcpy(action.id_, peer_id.c_str());
strcpy(action.ip_, peer_ip.c_str());
int ret = zmq_send(gate_, (void*)&action, sizeof(action), 0);
if (ret < 0)
{
zmq_strerror(errno);
}
}
示例15: main
int main(void)
{
void *ctx = zmq_ctx_new();
void *sock = zmq_socket(ctx, ZMQ_ROUTER);
int rc = zmq_bind(sock, "tcp://127.0.0.1:5555");
assert(0 == rc);
char buf[128];
int recvBytes = 0;
while (1) {
// recv id
recvBytes = zmq_recv(sock, buf, sizeof(buf), 0);
if (0 < recvBytes) {
// send it back
printf("recv id bytes=%d\n", recvBytes);
zmq_send(sock, buf, recvBytes, ZMQ_SNDMORE);
}
// delimiter emtpy frame
recvBytes = zmq_recv(sock, buf, sizeof(buf), 0);
assert(0 == recvBytes);
recvBytes = zmq_recv(sock, buf, sizeof(buf), 0);
// actual message
if (0 < recvBytes) {
// send it back
buf[recvBytes] = '\0';
printf("recv msg %s, bytes=%d\n", buf, recvBytes);
zmq_send(sock, "", 0, ZMQ_SNDMORE);
zmq_send(sock, buf, recvBytes, 0);
}
}
zmq_close(sock);
zmq_ctx_destroy(ctx);
return 0;
}