source: network-demos/ttcp/rtems_ttcp.c @ cd8aff0

4.11network-demos-4-10-branchnetwork-demos-4-8-branchnetwork-demos-4-9-branch
Last change on this file since cd8aff0 was 6a19a29, checked in by Joel Sherrill <joel.sherrill@…>, on 06/21/07 at 18:00:35

2007-06-21 Joel Sherrill <joel.sherrill@…>

  • rtems_ttcp.c, ttcp_orig/ttcp.c: Now compiles reasonably cleanly with CVS head.
  • Property mode set to 100644
File size: 4.9 KB
Line 
1/*
2 * A collection of hacks, glue, and patches to
3 * provide a `UNIX-like' environment to ttcp.
4 *
5 * Some of the code here may migrate to the libc
6 * support routines some day.  Some of the more sleazy
7 * hacks should never make it outside this file!
8 *
9 * This program may be distributed and used for any purpose.
10 * I ask only that you:
11 *      1. Leave this author information intact.
12 *      2. Document any changes you make.
13 *
14 * W. Eric Norum
15 * Saskatchewan Accelerator Laboratory
16 * University of Saskatchewan
17 * Saskatoon, Saskatchewan, CANADA
18 * eric@skatter.usask.ca
19 *
20 *  $Id$
21 */
22
23#include <stdio.h>
24#include <string.h>
25#include <ctype.h>
26#include <rtems.h>
27#include <rtems/rtems_bsdnet.h>
28#include <rtems/error.h>
29#include <sys/types.h>
30#include <sys/socket.h>
31#include <netinet/in.h>
32#include <netdb.h>
33#include <sys/time.h>
34#include <stdlib.h>
35#include <signal.h>
36
37/*
38 * Glue between UNIX-style ttcp code and RTEMS
39 */
40int rtems_ttcp_main (int argc, char **argv);
41
42static int
43select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
44{
45  rtems_panic ("select()");
46  return 0;
47}
48
49#define _SYS_RESOURCE_H_
50#define RUSAGE_SELF     0               /* calling process */
51#define RUSAGE_CHILDREN -1              /* terminated child processes */
52struct rusage {
53        struct timeval ru_utime;        /* user time used */
54        struct timeval ru_stime;        /* system time used */
55        int ru_maxrss;          /* maximum resident set size */
56        int ru_ixrss;           /* currently 0 */
57        int ru_idrss;           /* integral resident set size */
58        int ru_isrss;           /* currently 0 */
59        int ru_minflt;          /* page faults not requiring physical I/O */
60        int ru_majflt;          /* page faults requiring physical I/O */
61        int ru_nswap;           /* swaps */
62        int ru_inblock;         /* block input operations */
63        int ru_oublock;         /* block output operations */
64        int ru_msgsnd;          /* messages sent */
65        int ru_msgrcv;          /* messages received */
66        int ru_nsignals;        /* signals received */
67        int ru_nvcsw;           /* voluntary context switches */
68        int ru_nivcsw;          /* involuntary context switches */
69};
70int
71getrusage(int ignored, struct rusage *ru)
72{
73        rtems_clock_time_value now;
74        static struct rusage nullUsage;
75
76        rtems_clock_get (RTEMS_CLOCK_GET_TIME_VALUE, &now);
77        *ru = nullUsage;
78        ru->ru_stime.tv_sec  = now.seconds;
79        ru->ru_stime.tv_usec = now.microseconds;
80        ru->ru_utime.tv_sec  = 0;
81        ru->ru_utime.tv_usec = 0;
82        return 0;
83}
84
85static void
86rtems_ttcp_exit (int code)
87{
88        rtems_task_wake_after( RTEMS_MILLISECONDS_TO_TICKS(1000) );
89        rtems_bsdnet_show_mbuf_stats ();
90        rtems_bsdnet_show_if_stats ();
91        rtems_bsdnet_show_ip_stats ();
92        rtems_bsdnet_show_tcp_stats ();
93        exit (code);
94}
95
96/*
97 * Task to run UNIX ttcp command
98 */
99char *__progname;
100static void
101ttcpTask (rtems_task_argument arg)
102{
103        int code;
104        int argc;
105        char arg0[10];
106        char *argv[20];
107        char linebuf[200];
108
109        for (;;) {
110                char *cp;
111
112                /*
113                 * Set up first argument
114                 */
115                argc = 1;
116                strcpy (arg0, "ttcp");
117                argv[0] = __progname = arg0;
118
119#if (defined (WRITE_TEST_ONLY))
120                strcpy (linebuf, "-s -t crux");
121#elif (defined (READ_TEST_ONLY))
122                strcpy (linebuf, "-s -r");
123#else
124                /*
125                 * Read a line
126                 */
127                printf (">>> %s ", argv[0]);
128                fflush (stdout);
129                fgets (linebuf, sizeof linebuf, stdin);
130#endif
131
132                /*
133                 * Break line into arguments
134                 */
135                cp = linebuf;
136                for (;;) {
137                        while (isspace (*cp))
138                                *cp++ = '\0';
139                        if (*cp == '\0')
140                                break;
141                        if (argc >= ((sizeof argv / sizeof argv[0]) - 1)) {
142                                printf ("Too many arguments.\n");
143                                argc = 0;
144                                break;
145                        }
146                        argv[argc++] = cp;
147                        while (!isspace (*cp)) {
148                                if (*cp == '\0')
149                                        break;
150                                cp++;
151                        }
152                }
153                if (argc > 1) {
154                        argv[argc] = NULL;
155                        break;
156                }
157                printf ("You must give some arguments!\n");
158                printf ("At the very least, you must provide\n");
159                printf ("         -r\n");
160                printf ("or\n");
161                printf ("         -t destination.internet.address\n");
162        }
163        code = rtems_ttcp_main (argc, argv);
164        rtems_ttcp_exit (code);
165}
166
167/*
168 * Test network throughput
169 */
170void
171test_network (void)
172{
173        rtems_id tid;
174        rtems_status_code sc;
175        rtems_time_of_day now;
176        rtems_task_priority my_priority;
177
178        /*
179         * Set up time-of-day clock
180         */
181        now.year = 1997;
182        now.month = 1;
183        now.day = 1;
184        now.hour = 0;
185        now.minute = 0;
186        now.second = 0;
187        now.ticks = 0;
188        sc = rtems_clock_set (&now);
189        if (sc != RTEMS_SUCCESSFUL) {
190                printf ("Can't set date/time; %s\n", rtems_status_text (sc));
191                return;
192        }
193
194        /*
195         * Spawn test task
196         */
197        rtems_task_set_priority (RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &my_priority);
198        sc = rtems_task_create (rtems_build_name ('T', 'T', 'C', 'P'),
199                        my_priority,
200                        32*1024,
201                        RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0),
202                        RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL,
203                        &tid);
204        if (sc != RTEMS_SUCCESSFUL) {
205                printf ("Can't create task; %s\n", rtems_status_text (sc));
206                return;
207        }
208        sc = rtems_task_start (tid, ttcpTask, 0);
209        if (sc != RTEMS_SUCCESSFUL) {
210                printf ("Can't start task; %s\n", rtems_status_text (sc));
211                return;
212        }
213        rtems_task_suspend (RTEMS_SELF);
214}
215
216#define main            rtems_ttcp_main
217#define exit(code)      close(fd),rtems_ttcp_exit(code)
218
219#include "ttcp_orig/ttcp.c"
Note: See TracBrowser for help on using the repository browser.