source: network-demos/ttcp/rtems_ttcp.c @ 7ba2ac5

4.11netdemos-4-5-branchnetwork-demos-4-10-branchnetwork-demos-4-6-branchnetwork-demos-4-7-branchnetwork-demos-4-8-branchnetwork-demos-4-9-branchrtems-4-5-branch
Last change on this file since 7ba2ac5 was 7ba2ac5, checked in by Joel Sherrill <joel.sherrill@…>, on 08/21/98 at 13:26:06

Added CVS Id Strings which were missing

  • Property mode set to 100644
File size: 5.1 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 <ctype.h>
25#include <rtems.h>
26#include <rtems/rtems_bsdnet.h>
27#include <rtems/error.h>
28#include <sys/types.h>
29#include <sys/socket.h>
30#include <netinet/in.h>
31#include <netdb.h>
32#include <sys/time.h>
33
34/*
35 * Glue between UNIX-style ttcp code and RTEMS
36 */
37int rtems_ttcp_main (int argc, char **argv);
38
39static int
40select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
41{
42        rtems_panic ("select()");
43}
44
45static void
46(*signal(int sig, void (*func)()))()
47{
48        return 0;;
49}
50
51int
52gettimeofday (struct timeval *tp, struct timezone *tzp)
53{
54        rtems_clock_time_value now;
55
56        rtems_clock_get (RTEMS_CLOCK_GET_TIME_VALUE, &now);
57        tp->tv_sec = now.seconds;
58        tp->tv_usec = now.microseconds;
59        return 0;
60}
61
62#define _SYS_RESOURCE_H_
63#define RUSAGE_SELF     0               /* calling process */
64#define RUSAGE_CHILDREN -1              /* terminated child processes */
65struct rusage {
66        struct timeval ru_utime;        /* user time used */
67        struct timeval ru_stime;        /* system time used */
68        int ru_maxrss;          /* maximum resident set size */
69        int ru_ixrss;           /* currently 0 */
70        int ru_idrss;           /* integral resident set size */
71        int ru_isrss;           /* currently 0 */
72        int ru_minflt;          /* page faults not requiring physical I/O */
73        int ru_majflt;          /* page faults requiring physical I/O */
74        int ru_nswap;           /* swaps */
75        int ru_inblock;         /* block input operations */
76        int ru_oublock;         /* block output operations */
77        int ru_msgsnd;          /* messages sent */
78        int ru_msgrcv;          /* messages received */
79        int ru_nsignals;        /* signals received */
80        int ru_nvcsw;           /* voluntary context switches */
81        int ru_nivcsw;          /* involuntary context switches */
82};
83int
84getrusage(int ignored, struct rusage *ru)
85{
86        rtems_clock_time_value now;
87        static struct rusage nullUsage;
88
89        rtems_clock_get (RTEMS_CLOCK_GET_TIME_VALUE, &now);
90        *ru = nullUsage;
91        ru->ru_stime.tv_sec  = now.seconds;
92        ru->ru_stime.tv_usec = now.microseconds;
93        ru->ru_utime.tv_sec  = 0;
94        ru->ru_utime.tv_usec = 0;
95        return 0;
96}
97
98static void
99rtems_ttcp_exit (int code)
100{
101        rtems_bsdnet_show_mbuf_stats ();
102        rtems_bsdnet_show_if_stats ();
103        rtems_bsdnet_show_ip_stats ();
104        rtems_bsdnet_show_tcp_stats ();
105        exit (code);
106}
107
108/*
109 * Task to run UNIX ttcp command
110 */
111char *__progname;
112static void
113ttcpTask (rtems_task_argument arg)
114{
115        int code;
116        int argc;
117        char arg0[10];
118        char *argv[20];
119        char linebuf[200];
120
121        for (;;) {
122                char *cp;
123
124                /*
125                 * Set up first argument
126                 */
127                argc = 1;
128                strcpy (arg0, "ttcp");
129                argv[0] = __progname = arg0;
130
131#if (defined (WRITE_TEST_ONLY))
132                strcpy (linebuf, "-s -t crux");
133#elif (defined (READ_TEST_ONLY))
134                strcpy (linebuf, "-s -r");
135#else
136                /*
137                 * Read a line
138                 */
139                printf (">>> %s ", argv[0]);
140                fflush (stdout);
141                fgets (linebuf, sizeof linebuf, stdin);
142#endif
143
144                /*
145                 * Break line into arguments
146                 */
147                cp = linebuf;
148                for (;;) {
149                        while (isspace (*cp))
150                                *cp++ = '\0';
151                        if (*cp == '\0')
152                                break;
153                        if (argc >= ((sizeof argv / sizeof argv[0]) - 1)) {
154                                printf ("Too many arguments.\n");
155                                argc = 0;
156                                break;
157                        }
158                        argv[argc++] = cp;
159                        while (!isspace (*cp)) {
160                                if (*cp == '\0')
161                                        break;
162                                cp++;
163                        }
164                }
165                if (argc > 1) {
166                        argv[argc] = NULL;
167                        break;
168                }
169                printf ("You must give some arguments!\n");
170                printf ("At the very least, you must provide\n");
171                printf ("         -r\n");
172                printf ("or\n");
173                printf ("         -t destination.internet.address\n");
174        }
175        code = rtems_ttcp_main (argc, argv);
176        rtems_ttcp_exit (code);
177}
178
179/*
180 * Test network throughput
181 */
182void
183test_network (void)
184{
185        rtems_id tid;
186        rtems_status_code sc;
187        rtems_time_of_day now;
188        rtems_task_priority my_priority;
189
190        /*
191         * Set up time-of-day clock
192         */
193        now.year = 1997;
194        now.month = 1;
195        now.day = 1;
196        now.hour = 0;
197        now.minute = 0;
198        now.second = 0;
199        now.ticks = 0;
200        sc = rtems_clock_set (&now);
201        if (sc != RTEMS_SUCCESSFUL) {
202                printf ("Can't set date/time; %s\n", rtems_status_text (sc));
203                return;
204        }
205
206        /*
207         * Spawn test task
208         */
209        rtems_task_set_priority (RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &my_priority);
210        sc = rtems_task_create (rtems_build_name ('T', 'T', 'C', 'P'),
211                        my_priority,
212                        32*1024,
213                        RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0),
214                        RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL,
215                        &tid);
216        if (sc != RTEMS_SUCCESSFUL) {
217                printf ("Can't create task; %s\n", rtems_status_text (sc));
218                return;
219        }
220        sc = rtems_task_start (tid, ttcpTask, 0);
221        if (sc != RTEMS_SUCCESSFUL) {
222                printf ("Can't start task; %s\n", rtems_status_text (sc));
223                return;
224        }
225        rtems_task_suspend (RTEMS_SELF);
226}
227
228#define main            rtems_ttcp_main
229#define exit(code)      close(fd),rtems_ttcp_exit(code)
230#define read_timer      rtems_read_timer
231
232#include "ttcp_orig/ttcp.c"
Note: See TracBrowser for help on using the repository browser.