2011-03-20 19:18:19 +01:00
|
|
|
/****************************************************************************
|
2017-06-23 19:23:43 +02:00
|
|
|
* examples/nettest/nettest_target1.c
|
2011-03-20 19:18:19 +01:00
|
|
|
*
|
2017-06-23 20:21:13 +02:00
|
|
|
* Copyright (C) 2007, 2009-2011, 2015, 2017 Gregory Nutt. All rights reserved.
|
2011-12-13 18:56:14 +01:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2011-03-20 19:18:19 +01:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-01-21 01:12:27 +01:00
|
|
|
#include "config.h"
|
2011-03-20 19:18:19 +01:00
|
|
|
|
2015-08-27 19:46:42 +02:00
|
|
|
#include <sys/wait.h>
|
2011-03-20 19:18:19 +01:00
|
|
|
#include <stdint.h>
|
2015-08-26 18:35:40 +02:00
|
|
|
#include <stdlib.h>
|
2011-03-20 19:18:19 +01:00
|
|
|
#include <stdio.h>
|
2015-08-26 18:35:40 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sched.h>
|
2011-03-20 19:18:19 +01:00
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include "nettest.h"
|
|
|
|
|
2017-06-24 03:14:39 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_EXAMPLES_NETTEST_LOOPBACK
|
|
|
|
static int server_child(int argc, char *argv[])
|
|
|
|
{
|
2017-06-25 17:15:27 +02:00
|
|
|
nettest_server();
|
2017-06-24 03:14:39 +02:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-08-26 17:06:41 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* nettest_main
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int main(int argc, FAR char *argv[])
|
|
|
|
{
|
2015-08-27 19:46:42 +02:00
|
|
|
#ifdef CONFIG_EXAMPLES_NETTEST_LOOPBACK
|
2015-08-26 18:35:40 +02:00
|
|
|
pid_t child;
|
2015-08-27 19:46:42 +02:00
|
|
|
#ifdef CONFIG_SCHED_WAITPID
|
|
|
|
int statloc;
|
|
|
|
#endif
|
2015-08-26 18:35:40 +02:00
|
|
|
#endif
|
|
|
|
|
2017-06-23 20:21:13 +02:00
|
|
|
/* Parse any command line options */
|
|
|
|
|
2017-06-25 17:15:27 +02:00
|
|
|
nettest_cmdline(argc, argv);
|
2017-06-23 20:21:13 +02:00
|
|
|
|
2015-08-26 17:06:41 +02:00
|
|
|
#ifdef CONFIG_EXAMPLES_NETTEST_INIT
|
|
|
|
/* Initialize the network */
|
|
|
|
|
2017-06-23 19:40:02 +02:00
|
|
|
nettest_initialize();
|
2015-08-26 17:06:41 +02:00
|
|
|
#endif
|
2011-03-20 19:18:19 +01:00
|
|
|
|
2015-08-26 18:35:40 +02:00
|
|
|
#if defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK)
|
|
|
|
/* Then perform the server side of the test on a child task */
|
|
|
|
|
2017-06-24 02:12:34 +02:00
|
|
|
child = task_create("Nettest Child", CONFIG_EXAMPLES_NETTEST_DAEMON_PRIORITY,
|
|
|
|
CONFIG_EXAMPLES_NETTEST_DAEMON_STACKSIZE, server_child,
|
2015-08-26 18:35:40 +02:00
|
|
|
NULL);
|
|
|
|
if (child < 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: Failed to server daemon\n");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-08-27 19:46:42 +02:00
|
|
|
usleep(500*1000);
|
2015-08-26 18:35:40 +02:00
|
|
|
|
|
|
|
#elif defined(CONFIG_EXAMPLES_NETTEST_SERVER)
|
|
|
|
/* Then perform the server side of the test on this thread */
|
2015-08-26 17:06:41 +02:00
|
|
|
|
2017-06-25 17:15:27 +02:00
|
|
|
nettest_server();
|
2015-08-26 18:35:40 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(CONFIG_EXAMPLES_NETTEST_SERVER) || \
|
|
|
|
defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK)
|
|
|
|
/* Then perform the client side of the test on this thread */
|
2015-08-26 17:06:41 +02:00
|
|
|
|
2017-06-25 17:15:27 +02:00
|
|
|
nettest_client();
|
2011-03-20 19:18:19 +01:00
|
|
|
#endif
|
|
|
|
|
2015-08-27 19:46:42 +02:00
|
|
|
#if defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK) && defined(CONFIG_SCHED_WAITPID)
|
|
|
|
printf("main: Waiting for the server to exit\n");
|
2020-01-02 13:09:50 +01:00
|
|
|
waitpid(child, &statloc, 0);
|
2015-08-27 19:46:42 +02:00
|
|
|
#endif
|
|
|
|
|
2015-08-26 18:35:40 +02:00
|
|
|
return EXIT_SUCCESS;
|
2011-03-20 19:18:19 +01:00
|
|
|
}
|