pkarashchenko commented on code in PR #1625: URL: https://github.com/apache/nuttx-apps/pull/1625#discussion_r1126340402
########## examples/nng_test/pubsub.c: ########## @@ -0,0 +1,141 @@ +/**************************************************************************** + * apps/examples/nng_test/pubsub.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <time.h> +#include <unistd.h> +#include <pthread.h> +#include <fcntl.h> +#include <errno.h> +#include <debug.h> + +#include <nng/nng.h> +#include <nng/protocol/pubsub0/pub.h> +#include <nng/protocol/pubsub0/sub.h> + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +void fatal(FAR const char *func, int rv) +{ + fprintf(stderr, "%s: %s\n", func, nng_strerror(rv)); +} + +FAR char *date(void) +{ + time_t now = time(&now); + FAR struct tm *info = localtime(&now); + FAR char *text = asctime(info); + text[strlen(text) - 1] = '\0'; + return text; +} + +FAR void *client_thread(pthread_addr_t pvarg) +{ + nng_socket sock; + int rv; + + sleep(2); + + if ((rv = nng_sub0_open(&sock)) != 0) + { + fatal("nng_sub0_open", rv); + return NULL; + } + + /* subscribe to everything (empty means all topics) */ + + if ((rv = nng_setopt(sock, NNG_OPT_SUB_SUBSCRIBE, "", 0)) != 0) + { + fatal("nng_setopt", rv); + return NULL; Review Comment: should we call `nng_sub0_close` or anything similar on failure path here and other places? ########## netutils/nng/.gitignore: ########## @@ -0,0 +1,2 @@ + Review Comment: ```suggestion ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org