summaryrefslogtreecommitdiffstats
path: root/select
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>1998-12-14 21:17:52 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>1998-12-14 21:17:52 +0000
commitc46e5b6a1f3d55946a6f3965a9b8b9e98d32e47c (patch)
treef3627e0859eb9bad262e16784ee91af8e144e553 /select
parentchanged version to 4.0.0 (diff)
downloadnetwork-demos-c46e5b6a1f3d55946a6f3965a9b8b9e98d32e47c.tar.bz2
New files from Eric Norum to test the select code.
Diffstat (limited to 'select')
-rw-r--r--select/Makefile63
-rw-r--r--select/init.c57
-rw-r--r--select/test.c131
3 files changed, 251 insertions, 0 deletions
diff --git a/select/Makefile b/select/Makefile
new file mode 100644
index 0000000..ef706cb
--- /dev/null
+++ b/select/Makefile
@@ -0,0 +1,63 @@
+#
+# $Id$
+#
+
+SAMPLE=selectTest
+PGM=${ARCH}/$(SAMPLE).exe
+
+MANAGERS=io event semaphore
+
+# C source names, if any, go here -- minus the .c
+C_PIECES= init test
+C_FILES=$(C_PIECES:%=%.c)
+C_O_FILES=$(C_PIECES:%=${ARCH}/%.o)
+
+H_FILES=
+
+DOCTYPES=
+DOCS=$(DOCTYPES:%=$(SAMPLE).%)
+
+SRCS=$(DOCS) $(C_FILES) $(CC_FILES) $(H_FILES) $(S_FILES)
+OBJS=$(C_O_FILES) $(CC_O_FILES) $(S_O_FILES)
+
+PRINT_SRCS=$(DOCS)
+
+PGM=${ARCH}/$(SAMPLE).exe
+
+include $(RTEMS_MAKEFILE_PATH)/Makefile.inc
+include $(RTEMS_CUSTOM)
+include $(PROJECT_ROOT)/make/leaf.cfg
+
+#
+# (OPTIONAL) Add local stuff here using +=
+#
+
+DEFINES +=
+CPPFLAGS +=
+CFLAGS +=
+CFLAGS_LD += -Wl,--defsym -Wl,HeapSize=0xC0000
+CFLAGS_OPTIMIZE_V +=
+CFLAGS_DEBUG_V += -v -qrtems_debug
+
+LD_PATHS +=
+LD_LIBS +=
+
+#
+# Add your list of files to delete here. The config files
+# already know how to delete some stuff, so you may want
+# to just run 'make clean' first to see what gets missed.
+# 'make clobber' already includes 'make clean'
+#
+
+CLEAN_ADDITIONS +=
+CLOBBER_ADDITIONS +=
+
+all: ${ARCH} $(SRCS) $(PGM)
+
+${PGM}: $(OBJS) $(LINK_FILES)
+ $(make-exe)
+
+# Install the program(s), appending _g or _p as appropriate.
+# for include files, just use $(INSTALL)
+install: all
+ $(INSTALL_VARIANT) -m 555 ${PGM} ${PROJECT_RELEASE}/tests
diff --git a/select/init.c b/select/init.c
new file mode 100644
index 0000000..93e0487
--- /dev/null
+++ b/select/init.c
@@ -0,0 +1,57 @@
+/*
+ * RTEMS configuration/initialization
+ *
+ * This program may be distributed and used for any purpose.
+ * I ask only that you:
+ * 1. Leave this author information intact.
+ * 2. Document any changes you make.
+ *
+ * W. Eric Norum
+ * Saskatchewan Accelerator Laboratory
+ * University of Saskatchewan
+ * Saskatoon, Saskatchewan, CANADA
+ * eric@skatter.usask.ca
+ *
+ * $Id$
+ */
+
+#include <bsp.h>
+
+#define CONFIGURE_TEST_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_TEST_NEEDS_CLOCK_DRIVER
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_EXECUTIVE_RAM_SIZE (512*1024)
+#define CONFIGURE_MAXIMUM_SEMAPHORES 20
+#define CONFIGURE_MAXIMUM_TASKS 20
+
+#define CONFIGURE_MICROSECONDS_PER_TICK 10486
+
+#define CONFIGURE_INIT_TASK_STACK_SIZE (10*1024)
+#define CONFIGURE_INIT_TASK_PRIORITY 120
+#define CONFIGURE_INIT_TASK_INITIAL_MODES (RTEMS_PREEMPT | \
+ RTEMS_NO_TIMESLICE | \
+ RTEMS_NO_ASR | \
+ RTEMS_INTERRUPT_LEVEL(0))
+
+#define CONFIGURE_INIT
+rtems_task Init (rtems_task_argument argument);
+
+#include <confdefs.h>
+
+#include <stdio.h>
+#include <rtems/rtems_bsdnet.h>
+#include "../networkconfig.h"
+
+/*
+ * RTEMS Startup Task
+ */
+rtems_task
+Init (rtems_task_argument ignored)
+{
+ int doSocket(void);
+
+ rtems_bsdnet_initialize_network ();
+ doSocket ();
+ exit (0);
+}
diff --git a/select/test.c b/select/test.c
new file mode 100644
index 0000000..1d5475c
--- /dev/null
+++ b/select/test.c
@@ -0,0 +1,131 @@
+/*
+ * Test RTEMS networking
+ *
+ * This program may be distributed and used for any purpose.
+ * I ask only that you:
+ * 1. Leave this author information intact.
+ * 2. Document any changes you make.
+ *
+ * W. Eric Norum
+ * Saskatchewan Accelerator Laboratory
+ * University of Saskatchewan
+ * Saskatoon, Saskatchewan, CANADA
+ * eric@skatter.usask.ca
+ *
+ * $Id$
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <rtems.h>
+#include <rtems/rtems_bsdnet.h>
+#include <rtems/error.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+#define BASE_PORT 24742
+#define CLIENT_COUNT 2
+
+static void
+echoServer (unsigned short port)
+{
+ int s, s1;
+ struct sockaddr_in myAddr, farAddr;
+ int addrlen;
+ rtems_id tid;
+ rtems_task_priority my_priority;
+ rtems_status_code sc;
+ char c = 'a';
+ fd_set clientfdset;
+ int clientCount, clientfd[CLIENT_COUNT];
+ int topfd = 0;
+
+ FD_ZERO (&clientfdset);
+ printf ("Create socket.\n");
+ s = socket (AF_INET, SOCK_STREAM, 0);
+ if (s < 0)
+ rtems_panic ("Can't create socket: %s", strerror (errno));
+ myAddr.sin_family = AF_INET;
+ myAddr.sin_port = htons (port);
+ myAddr.sin_addr.s_addr = INADDR_ANY;
+ memset (myAddr.sin_zero, '\0', sizeof myAddr.sin_zero);
+ printf ("Bind socket.\n");
+ if (bind (s, (struct sockaddr *)&myAddr, sizeof myAddr) < 0)
+ rtems_panic ("Can't bind socket: %s", strerror (errno));
+ printf ("Listen.\n");
+ if (listen (s, 2) < 0)
+ rtems_panic ("Can't listen on socket: %s", strerror (errno));
+
+ /*
+ * Accumulate clients
+ */
+ for (clientCount = 0 ; clientCount < CLIENT_COUNT ; clientCount++) {
+ printf ("Accept.\n");
+ addrlen = sizeof farAddr;
+ s1 = accept (s, (struct sockaddr *)&farAddr, &addrlen);
+ if (s1 < 0)
+ rtems_panic ("Can't accept connection: %s", strerror (errno));
+ else
+ printf ("ACCEPTED:%lX\n", ntohl (farAddr.sin_addr.s_addr));
+ FD_SET (s1, &clientfdset);
+ if (s1 > topfd)
+ topfd = s1;
+ clientfd[clientCount] = s1;
+ }
+
+ /*
+ * Run clients
+ */
+ for (;;) {
+ fd_set readfdset;
+ struct timeval tv;
+ int n;
+ int i;
+
+ tv.tv_sec = 5;
+ tv.tv_usec = 0;
+ readfdset = clientfdset;
+ n = select (topfd + 1, &readfdset, NULL, NULL, &tv);
+ if (n < 0) {
+ printf ("Select() error: %s\n", strerror (errno));
+ return;
+ }
+ if (n == 0) {
+ printf ("Timeout\n");
+ continue;
+ }
+
+ printf ("Activity on %d file descriptor%s.\n", n, n == 1 ? "" : "s");
+ for (i = 0 ; n && (i < CLIENT_COUNT) ; i++) {
+ int fd = clientfd[i];
+ if (FD_ISSET (fd, &readfdset)) {
+ char buf[200];
+ int nread;
+
+ printf ("Activity on file descriptor %d.\n", fd);
+ n--;
+ nread = read (fd, buf, sizeof buf);
+ if (nread < 0) {
+ printf ("Read error %s.\n", strerror (errno));
+ return;
+ }
+ if (nread == 0) {
+ printf ("EOF\n");
+ FD_CLR (fd, &clientfdset);
+ if (--clientCount == 0)
+ return;
+ }
+ printf ("Read %d.\n", nread);
+ }
+ }
+ }
+}
+
+void
+doSocket (void)
+{
+ echoServer (BASE_PORT);
+}