本文整理汇总了C++中s_recv函数的典型用法代码示例。如果您正苦于以下问题:C++ s_recv函数的具体用法?C++ s_recv怎么用?C++ s_recv使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了s_recv函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(){
void* context = zmq_init(1);
void* receiver = zmq_socket(context, ZMQ_PULL);
zmq_bind(receiver, "tcp://*:5558");
//wait for start of batch
char *string = s_recv(receiver);
free(string);
//start clock
int64_t start_time = s_clock();
//process 100
int tasks_nbr;
for( tasks_nbr = 0; tasks_nbr < 100; tasks_nbr++){
char* string = s_recv(receiver);
if((tasks_nbr / 10)*10 == tasks_nbr){
printf(":");
} else{
printf(".");
}
fflush(stdout);
}
printf("Total elapsed time: %d msec\n",
(int)(s_clock() - start_time));
zmq_close(receiver);
zmq_term(context);
return 0;
}
示例2: worker_task
static void *
worker_task (void *args)
{
void *context = zmq_ctx_new ();
void *worker = zmq_socket (context, ZMQ_REQ);
s_set_id (worker); // Set a printable identity
zmq_connect (worker, "ipc://backend.ipc");
// Tell broker we're ready for work
s_send (worker, "READY");
while (1) {
// Read and save all frames until we get an empty frame
// In this example there is only 1 but it could be more
char *identity = s_recv (worker);
char *empty = s_recv (worker);
assert (*empty == 0);
free (empty);
// Get request, send reply
char *request = s_recv (worker);
printf ("Worker: %s\n", request);
free (request);
s_sendmore (worker, identity);
s_sendmore (worker, "");
s_send (worker, "OK");
free (identity);
}
zmq_close (worker);
zmq_ctx_destroy (context);
return NULL;
}
示例3: worker_thread
// Worker using REQ socket to do LRU routing
//
static void *
worker_thread (void *arg) {
zmq::context_t context(1);
zmq::socket_t worker (context, ZMQ_REQ);
s_set_id (worker); // Makes tracing easier
worker.connect("ipc://backend.ipc");
// Tell backend we're ready for work
s_send (worker, "READY");
while (1) {
// Read and save all frames until we get an empty frame
// In this example there is only 1 but it could be more
std::string address = s_recv (worker);
{
std::string empty = s_recv (worker);
assert (empty.size() == 0);
}
// Get request, send reply
std::string request = s_recv (worker);
std::cout << "Worker: " << request << std::endl;
s_sendmore (worker, address);
s_sendmore (worker, "");
s_send (worker, "OK");
}
return (NULL);
}
示例4: main
int main(int argc, char* argv[]) {
zmq::context_t context(1);
zmq::socket_t subscriber(context, ZMQ_SUB);
subscriber.connect("tcp://localhost:5561");
subscriber.setsockopt(ZMQ_SUBSCRIBE, "", 0);
zmq::socket_t syncclient(context, ZMQ_REQ);
syncclient.connect("tcp://localhost:5562");
s_send(syncclient, "");
s_recv(syncclient);
std::cout << "Connected to subscriber" << std::endl;
int update_nbr = 0;
while(1) {
if (s_recv(subscriber).compare("END") == 0) {
std::cout << "FINE" << std::endl;
break;
}
update_nbr++;
}
std::cout << "Received " << update_nbr << "updates" << std::endl;
return 0;
}
示例5: worker_thread
// Worker using REQ socket to do LRU routing
//
static void *
worker_thread (void *args) {
void *context = zmq_init (1);
void *worker = zmq_socket (context, ZMQ_REQ);
s_set_id (worker); // Makes tracing easier
zmq_connect (worker, "ipc://backend.ipc");
// Tell broker we're ready for work
s_send (worker, "READY");
while (1) {
// Read and save all frames until we get an empty frame
// In this example there is only 1 but it could be more
char *address = s_recv (worker);
char *empty = s_recv (worker);
assert (*empty == 0);
free (empty);
// Get request, send reply
char *request = s_recv (worker);
printf ("Worker: %s\n", request);
free (request);
s_sendmore (worker, address);
s_sendmore (worker, "");
s_send (worker, "OK");
free (address);
}
zmq_close (worker);
zmq_term (context);
return NULL;
}
示例6: str_recv_from
void str_recv_from (void *s_, char **ptr_content_, char **ptr_address_)
{
*ptr_address_ = s_recv (s_);
assert (ptr_address_);
*ptr_content_ = s_recv (s_);
assert (ptr_content_);
}
示例7: main
int
main (void)
{
void *context;
void *subscriber1;
void *subscriber2;
char *filter;
int i;
int ok;
context = zmq_ctx_new ();
subscriber1 = zmq_socket (context, ZMQ_SUB);
printf ("connecting...\n");
ok = zmq_connect (subscriber1, "tcp://localhost:5000");
assert (ok == 0);
subscriber2 = zmq_socket (context, ZMQ_SUB);
ok = zmq_connect (subscriber2, "tcp://localhost:5001");
assert (ok == 0);
printf ("connected.\n");
printf ("set filters...\n");
filter = "filter1";
ok = zmq_setsockopt (subscriber1,
ZMQ_SUBSCRIBE,
filter,
strlen (filter));
assert (ok == 0);
filter = "filter2";
ok = zmq_setsockopt (subscriber2,
ZMQ_SUBSCRIBE,
filter,
strlen (filter));
assert (ok == 0);
printf ("filters set.\n");
printf ("receiving messages...\n");
for (i = 0; i < 3; i++)
{
char *msg = s_recv (subscriber1);
printf ("%s\n", msg);
free (msg);
}
for (i = 0; i < 3; i++)
{
char *msg = s_recv (subscriber2);
printf ("%s\n", msg);
free (msg);
}
zmq_close (subscriber1);
zmq_close (subscriber2);
zmq_ctx_destroy (context);
return 0;
}
示例8: main
int main(int argc, char *argv[])
{
void *ctx, *handler, *thread, *server, *client;
const char *domain, *connect_addr;
int optval;
domain = argc > 1 ? argv[1] : "test";
connect_addr = strcmp(domain, "fail") ? "tcp://127.0.0.1:9000" : "tcp://127.0.0.1:9001";
assert((ctx = zmq_ctx_new()));
/* Start ZAP handler thread. */
assert((handler = zmq_socket(ctx, ZMQ_REP)));
assert(!(zmq_bind(handler, "inproc://zeromq.zap.01")));
assert((thread = zmq_threadstart(zap_handler, handler)));
/* Bind server. */
assert((server = zmq_socket(ctx, ZMQ_DEALER)));
assert(!(zmq_setsockopt(server, ZMQ_ZAP_DOMAIN, domain, strlen(domain))));
assert(!zmq_bind(server, "tcp://127.0.0.1:9000"));
/* Connect client. */
assert((client = zmq_socket(ctx, ZMQ_DEALER)));
optval = 200;
assert(!(zmq_setsockopt(client, ZMQ_RECONNECT_IVL, &optval, sizeof(optval))));
optval = 5000;
assert(!(zmq_setsockopt(client, ZMQ_RECONNECT_IVL_MAX, &optval, sizeof(optval))));
optval = 30000;
assert(!(zmq_setsockopt(client, ZMQ_SNDTIMEO, &optval, sizeof(optval))));
optval = 1;
assert(!(zmq_setsockopt(client, ZMQ_IMMEDIATE, &optval, sizeof(optval))));
assert(!zmq_connect(client, connect_addr));
/* Bounce test. */
s_send(client, "Hello, Server!");
assert(!strcmp(s_recv(server), "Hello, Server!"));
s_send(server, "Hello, Client!");
assert(!strcmp(s_recv(client), "Hello, Client!"));
/* Cleanup. */
assert(!zmq_disconnect(client, connect_addr));
assert(!zmq_close(client));
assert(!zmq_unbind(server, "tcp://127.0.0.1:9000"));
assert(!zmq_close(server));
assert(!zmq_term(ctx));
zmq_threadclose(thread);
return 0;
}
示例9: RMessage
// pubRequest by one of the Satellites, this Server just forwards it by publishing it
bool ReefServer::pubRequest(RMessage& msg){
msg = RMessage();
bool retBool;
std::string tagsStr = s_recv(rep); //receive message tags
std::string bodyStr = s_recv(rep); //receive messagebody
CJsonArray tagsArray = jsonToArray(tagsStr); //parse Tags
tagsInitMessage(msg, tagsArray); //initiate msg with the tags
tagsArray.Clear();
retBool = checkInterestAndProcess(msg, bodyStr);
s_sendmore(publisher, ""); //send empty envelope
s_sendmore(publisher, tagsStr); //receive tag-part of message and publish it
s_send(publisher, bodyStr); //receive body-part of message and publish it
return retBool;
}
示例10: main
int main(void)
{
//Create ZMQ Socket
void *context = zmq_ctx_new();
//Socket to receive messages
void *receiver = zmq_socket(context, ZMQ_PULL);
zmq_bind(receiver, "tcp://*:5558");
//Socket to control workers
void *controller = zmq_socket(context, ZMQ_PUB);
zmq_bind(controller, "tcp://*:5559");
//Waiting for start
char *string = s_recv(receiver);
free(string);
//Start clock
int64_t start_time = s_clock();
//Process messages
int task_nbr;
for(task_nbr = 0; task_nbr < 100; task_nbr++)
{
char *string = s_recv(receiver);
free(string);
if((task_nbr / 10) * 10 == task_nbr)
{
printf(":");
}
else
{
printf(".");
}
fflush(stdout);
}
printf("Total elapsed time: %d msec\n", (int)(s_clock()-start_time));
//Send Kille signal
s_send(controller, "KILL");
zmq_close(receiver);
zmq_close(controller);
zmq_ctx_destroy(context);
return 0;
}
示例11: worker_thread
static void *
worker_thread (void *arg) {
zmq::context_t * context = (zmq::context_t *)arg;
zmq::socket_t worker (*context, ZMQ_REQ);
// We use a string identity for ease here
s_set_id (worker);
worker.connect("ipc://routing.ipc");
int total = 0;
while (1) {
// Tell the router we're ready for work
s_send (worker, "ready");
// Get workload from router, until finished
std::string workload = s_recv (worker);
int finished = (workload.compare("END") == 0);
if (finished) {
std::cout << "Processed: " << total << " tasks" << std::endl;
break;
}
total++;
// Do some random work
s_sleep(within (100) + 1);
}
return (NULL);
}
示例12: main
int main (int argc, char *argv [])
{
// Socket to talk to server
printf ("Collecting updates from weather server…\n");
void *context = zmq_ctx_new ();
void *subscriber = zmq_socket (context, ZMQ_SUB);
int rc = zmq_connect (subscriber, "tcp://localhost:5556");
assert (rc == 0);
// Subscribe to zipcode, default is NYC, 10001
char *filter = (argc > 1)? argv [1]: "10001 ";
rc = zmq_setsockopt (subscriber, ZMQ_SUBSCRIBE,
filter, strlen (filter));
assert (rc == 0);
// Process 100 updates
int update_nbr;
long total_temp = 0;
for (update_nbr = 0; update_nbr < 100; update_nbr++) {
char *string = s_recv (subscriber);
int zipcode, temperature, relhumidity;
sscanf (string, "%d %d %d",
&zipcode, &temperature, &relhumidity);
total_temp += temperature;
free (string);
}
printf ("Average temperature for zipcode '%s' was %dF\n",
filter, (int) (total_temp / update_nbr));
zmq_close (subscriber);
zmq_ctx_destroy (context);
return 0;
}
示例13: test_plain_vanilla_socket
void test_plain_vanilla_socket ()
{
// Unauthenticated messages from a vanilla socket shouldn't be received
struct sockaddr_in ip4addr;
fd_t s;
unsigned short int port;
int rc = sscanf (my_endpoint, "tcp://127.0.0.1:%hu", &port);
TEST_ASSERT_EQUAL_INT (1, rc);
ip4addr.sin_family = AF_INET;
ip4addr.sin_port = htons (port);
#if defined(ZMQ_HAVE_WINDOWS) && (_WIN32_WINNT < 0x0600)
ip4addr.sin_addr.s_addr = inet_addr ("127.0.0.1");
#else
inet_pton (AF_INET, "127.0.0.1", &ip4addr.sin_addr);
#endif
s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
rc = connect (s, (struct sockaddr *) &ip4addr, sizeof (ip4addr));
TEST_ASSERT_GREATER_THAN_INT (-1, rc);
// send anonymous ZMTP/1.0 greeting
send (s, "\x01\x00", 2, 0);
// send sneaky message that shouldn't be received
send (s, "\x08\x00sneaky\0", 9, 0);
int timeout = 250;
zmq_setsockopt (server, ZMQ_RCVTIMEO, &timeout, sizeof (timeout));
char *buf = s_recv (server);
if (buf != NULL) {
printf ("Received unauthenticated message: %s\n", buf);
TEST_ASSERT_NULL (buf);
}
close (s);
}
示例14: main
int main(void)
{
void *context = zmq_ctx_new();
void *socket = zmq_socket(context, ZMQ_REP);
zmq_bind(socket, "tcp://*:5555");
s_catch_signals();
#if 1
while (1) {
// Blocking read will exit on a signal
char buffer[255];
zmq_recv(socket, buffer, 255, 0);
if (s_interrupted) {
printf("W: interrupt received, killing server...\n");
break;
}
}
#else
while (!s_interrupted) {
char *message = s_recv(socket);
if (!message) {
break;
}
}
#endif
zmq_close(socket);
zmq_ctx_destroy(context);
#ifdef _MSC_VER
system("pause");
#endif
return 0;
}
示例15: replay
void replay(void *arg) {
void *slave = zmq_socket(arg, ZMQ_REQ);
/*
if (done % 2) {
zmq_connect (slave, "tcp://localhost:5562");
}
else {
zmq_connect (slave, "tcp://localhost:5563");
}*/
zmq_connect (slave, "tcp://localhost:5562");
char *string;
char buf[1024];
sprintf(buf, "%d", rand());
s_send(slave, buf);
string = s_recv(slave);
if (strcmp(string , buf) != 0) {
debug_puts("ERROR");
}
free(string);
pthread_mutex_lock(&lock);
done++;
pthread_mutex_unlock(&lock);
zmq_close(slave);
}