local_lat.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MPL-2.0 */
2 
3 #include "../include/zmq.h"
4 #include <stdio.h>
5 #include <stdlib.h>
6 
7 int main (int argc, char *argv[])
8 {
9  const char *bind_to;
10  int roundtrip_count;
11  size_t message_size;
12  void *ctx;
13  void *s;
14  int rc;
15  int i;
16  zmq_msg_t msg;
17 
18  if (argc != 4) {
19  printf ("usage: local_lat <bind-to> <message-size> "
20  "<roundtrip-count>\n");
21  return 1;
22  }
23  bind_to = argv[1];
24  message_size = atoi (argv[2]);
25  roundtrip_count = atoi (argv[3]);
26 
27  ctx = zmq_init (1);
28  if (!ctx) {
29  printf ("error in zmq_init: %s\n", zmq_strerror (errno));
30  return -1;
31  }
32 
33  s = zmq_socket (ctx, ZMQ_REP);
34  if (!s) {
35  printf ("error in zmq_socket: %s\n", zmq_strerror (errno));
36  return -1;
37  }
38 
39  rc = zmq_bind (s, bind_to);
40  if (rc != 0) {
41  printf ("error in zmq_bind: %s\n", zmq_strerror (errno));
42  return -1;
43  }
44 
45  rc = zmq_msg_init (&msg);
46  if (rc != 0) {
47  printf ("error in zmq_msg_init: %s\n", zmq_strerror (errno));
48  return -1;
49  }
50 
51  for (i = 0; i != roundtrip_count; i++) {
52  rc = zmq_recvmsg (s, &msg, 0);
53  if (rc < 0) {
54  printf ("error in zmq_recvmsg: %s\n", zmq_strerror (errno));
55  return -1;
56  }
57  if (zmq_msg_size (&msg) != message_size) {
58  printf ("message of incorrect size received\n");
59  return -1;
60  }
61  rc = zmq_sendmsg (s, &msg, 0);
62  if (rc < 0) {
63  printf ("error in zmq_sendmsg: %s\n", zmq_strerror (errno));
64  return -1;
65  }
66  }
67 
68  rc = zmq_msg_close (&msg);
69  if (rc != 0) {
70  printf ("error in zmq_msg_close: %s\n", zmq_strerror (errno));
71  return -1;
72  }
73 
74  zmq_sleep (1);
75 
76  rc = zmq_close (s);
77  if (rc != 0) {
78  printf ("error in zmq_close: %s\n", zmq_strerror (errno));
79  return -1;
80  }
81 
82  rc = zmq_ctx_term (ctx);
83  if (rc != 0) {
84  printf ("error in zmq_ctx_term: %s\n", zmq_strerror (errno));
85  return -1;
86  }
87 
88  return 0;
89 }
zmq_strerror
const ZMQ_EXPORT char * zmq_strerror(int errnum_)
Definition: zmq.cpp:96
s
XmlRpcServer s
zmq_sendmsg
ZMQ_EXPORT int zmq_sendmsg(void *s_, zmq_msg_t *msg_, int flags_)
Definition: zmq.cpp:372
errno
int errno
zmq_msg_size
ZMQ_EXPORT size_t zmq_msg_size(const zmq_msg_t *msg_)
Definition: zmq.cpp:647
message_size
static size_t message_size
Definition: inproc_lat.cpp:18
roundtrip_count
static int roundtrip_count
Definition: inproc_lat.cpp:19
main
int main(int argc, char *argv[])
Definition: local_lat.cpp:7
zmq_msg_t
Definition: zmq.h:218
ZMQ_REP
#define ZMQ_REP
Definition: zmq.h:262
zmq_bind
ZMQ_EXPORT int zmq_bind(void *s_, const char *addr_)
Definition: zmq.cpp:299
zmq_socket
ZMQ_EXPORT void * zmq_socket(void *, int type_)
Definition: zmq.cpp:230
zmq_msg_init
ZMQ_EXPORT int zmq_msg_init(zmq_msg_t *msg_)
Definition: zmq.cpp:587
zmq_close
ZMQ_EXPORT int zmq_close(void *s_)
Definition: zmq.cpp:241
i
int i
Definition: gmock-matchers_test.cc:764
zmq_recvmsg
ZMQ_EXPORT int zmq_recvmsg(void *s_, zmq_msg_t *msg_, int flags_)
Definition: zmq.cpp:481
zmq_init
ZMQ_EXPORT void * zmq_init(int io_threads_)
Definition: zmq.cpp:196
zmq_sleep
ZMQ_EXPORT void zmq_sleep(int seconds_)
Definition: zmq_utils.cpp:23
zmq_ctx_term
ZMQ_EXPORT int zmq_ctx_term(void *context_)
Definition: zmq.cpp:128
zmq_msg_close
ZMQ_EXPORT int zmq_msg_close(zmq_msg_t *msg_)
Definition: zmq.cpp:625


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:55