acassis commented on code in PR #3341: URL: https://github.com/apache/nuttx-apps/pull/3341#discussion_r2701553816
########## sensors/netsensor/netsensor_main.c: ########## @@ -0,0 +1,246 @@ +/**************************************************************************** + * apps/sensors/netsensor/netsensor_main.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for asyslogditional 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 <nuttx/config.h> + +#include <fcntl.h> +#include <poll.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <syslog.h> + +#include <arpa/inet.h> +#include <netinet/in.h> +#include <sys/socket.h> + +#include <getopt.h> + +#include <uORB/uORB.h> + +#include "helptext.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define DEFAULT_PORT (5555) +#define DEFAULT_QLEN (5) + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static void print_usage(FILE *sink) { fprintf(sink, HELP_TEXT); } + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int main(int argc, char **argv) +{ + int err; + int netfd; + int sock; + ssize_t brecvd; + const struct orb_metadata *meta; + struct sockaddr_in addr; /* TODO: IPv6 support */ Review Comment: @linguini1 not an issue, but normally structs and complex types are defined early inside a function, I think this is just a convention that Greg created, but in some cases it avoid misalignment, i.e. it you have an uint8_t followed by a struct definition. Maybe others here have a better explanation why this convention is used, since the C compiler don't care much about the variables position ########## sensors/netsensor/netsensor_main.c: ########## @@ -0,0 +1,246 @@ +/**************************************************************************** + * apps/sensors/netsensor/netsensor_main.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for asyslogditional 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 <nuttx/config.h> + +#include <fcntl.h> +#include <poll.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <syslog.h> + +#include <arpa/inet.h> +#include <netinet/in.h> +#include <sys/socket.h> + +#include <getopt.h> + +#include <uORB/uORB.h> + +#include "helptext.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define DEFAULT_PORT (5555) +#define DEFAULT_QLEN (5) + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static void print_usage(FILE *sink) { fprintf(sink, HELP_TEXT); } + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int main(int argc, char **argv) +{ + int err; + int netfd; + int sock; + ssize_t brecvd; + const struct orb_metadata *meta; + struct sockaddr_in addr; /* TODO: IPv6 support */ Review Comment: @linguini1 not an issue, but normally structs and complex types are defined early inside a function, I think this is just a convention that Greg created, but in some cases it avoids misalignment, i.e. it you have an uint8_t followed by a struct definition. Maybe others here have a better explanation why this convention is used, since the C compiler don't care much about the variables position -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
