diff options
| author | C-o-r-E <can.of.tuna@gmail.com> | 2023-07-10 11:38:14 -0400 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2023-08-23 11:20:01 -0700 |
| commit | 97eb677fd74a55f80b173a0ad6a53da12aded04d (patch) | |
| tree | 7a28124b978638f7146c7f2a94fb5c5e7319e9ef | |
| parent | 52885b6e5af3174e7d367dddcb02b9f50849f191 (diff) | |
| download | nng-97eb677fd74a55f80b173a0ad6a53da12aded04d.tar.gz nng-97eb677fd74a55f80b173a0ad6a53da12aded04d.tar.bz2 nng-97eb677fd74a55f80b173a0ad6a53da12aded04d.zip | |
Follow clang-format defined style
| -rw-r--r-- | demo/pubsub_forwarder/pubsub_forwarder.c | 104 |
1 files changed, 57 insertions, 47 deletions
diff --git a/demo/pubsub_forwarder/pubsub_forwarder.c b/demo/pubsub_forwarder/pubsub_forwarder.c index dc18cc64..e79c04b0 100644 --- a/demo/pubsub_forwarder/pubsub_forwarder.c +++ b/demo/pubsub_forwarder/pubsub_forwarder.c @@ -8,79 +8,89 @@ // // Forwarder example based on https://github.com/C-o-r-E/nng_pubsub_proxy // -// This example shows how to use raw sockets to set up a forwarder or proxy for pub/sub. -// +// This example shows how to use raw sockets to set up a forwarder or proxy for +// pub/sub. +// // An example setup for running this example would involve the following: -// +// // - Run this example binary (in the background or a terminal, etc) -// - In a new terminal, run `nngcat --sub --dial "tcp://localhost:3328" --quoted` -// - In a second terminal, run `nngcat --sub --dial "tcp://localhost:3328" --quoted` -// - In a third terminal, run `for n in $(seq 0 99); do nngcat --pub --dial "tcp://localhost:3327" --data "$n"; done` +// - In a new terminal, run +// `nngcat --sub --dial "tcp://localhost:3328" --quoted` +// - In a second terminal, run +// `nngcat --sub --dial "tcp://localhost:3328" --quoted` +// - In a third terminal, run +// `for n in $(seq 0 99);` +// `do nngcat --pub --dial "tcp://localhost:3327" --data "$n";` +// `done` // #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <nng/nng.h> -#include <nng/protocol/pubsub0/sub.h> #include <nng/protocol/pubsub0/pub.h> +#include <nng/protocol/pubsub0/sub.h> #define PROXY_FRONT_URL "tcp://localhost:3327" #define PROXY_BACK_URL "tcp://localhost:3328" -void panic_on_error(int should_panic, const char* format, ...) +void +panic_on_error(int should_panic, const char *format, ...) { - if (should_panic) - { - va_list args; - va_start(args, format); - vprintf(format, args); - va_end(args); - exit(EXIT_FAILURE); - } + if (should_panic) { + va_list args; + va_start(args, format); + vprintf(format, args); + va_end(args); + exit(EXIT_FAILURE); + } } -int main() +int +main() { - nng_socket sock_front_end = NNG_SOCKET_INITIALIZER; - nng_socket sock_back_end = NNG_SOCKET_INITIALIZER; - int ret = 0; + nng_socket sock_front_end = NNG_SOCKET_INITIALIZER; + nng_socket sock_back_end = NNG_SOCKET_INITIALIZER; + int ret = 0; - /* - First we need some nng sockets. Not to be confused with network sockets - */ - ret = nng_sub0_open_raw(&sock_front_end); - panic_on_error(ret, "Failed to open front end socket\n"); + // + // First we need some nng sockets. Not to be confused with network + // sockets + // + ret = nng_sub0_open_raw(&sock_front_end); + panic_on_error(ret, "Failed to open front end socket\n"); - ret = nng_pub0_open_raw(&sock_back_end); - panic_on_error(ret, "Failed to open back end socket\n"); + ret = nng_pub0_open_raw(&sock_back_end); + panic_on_error(ret, "Failed to open back end socket\n"); - /* - Now we need to set up a listener for each socket so that they have addresses - */ + // + // Now we need to set up a listener for each socket so that they have + // addresses + // - nng_listener front_ls = NNG_LISTENER_INITIALIZER; - nng_listener back_ls = NNG_LISTENER_INITIALIZER; + nng_listener front_ls = NNG_LISTENER_INITIALIZER; + nng_listener back_ls = NNG_LISTENER_INITIALIZER; - ret = nng_listener_create(&front_ls, sock_front_end, PROXY_FRONT_URL); - panic_on_error(ret, "Failed to create front listener\n"); + ret = nng_listener_create(&front_ls, sock_front_end, PROXY_FRONT_URL); + panic_on_error(ret, "Failed to create front listener\n"); - ret = nng_listener_create(&back_ls, sock_back_end, PROXY_BACK_URL); - panic_on_error(ret, "Failed to create back listener\n"); + ret = nng_listener_create(&back_ls, sock_back_end, PROXY_BACK_URL); + panic_on_error(ret, "Failed to create back listener\n"); - ret = nng_listener_start(front_ls, 0); - panic_on_error(ret, "Failed to start front listener\n"); + ret = nng_listener_start(front_ls, 0); + panic_on_error(ret, "Failed to start front listener\n"); - ret = nng_listener_start(back_ls, 0); - panic_on_error(ret, "Failed to start back listener\n"); + ret = nng_listener_start(back_ls, 0); + panic_on_error(ret, "Failed to start back listener\n"); - /* - Finally let nng do the forwarding/proxying - */ + // + // Finally let nng do the forwarding/proxying + // - ret = nng_device(sock_front_end, sock_back_end); - panic_on_error(ret, "nng_device returned %d: %s\n", ret, nng_strerror(ret)); + ret = nng_device(sock_front_end, sock_back_end); + panic_on_error( + ret, "nng_device returned %d: %s\n", ret, nng_strerror(ret)); - printf("done"); - return 0; + printf("done"); + return 0; }
\ No newline at end of file |
