source: network-demos/ttcp/rtems_ttcp.c @ 0c9330e

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 0c9330e was 0c9330e, checked in by Joel Sherrill <joel.sherrill@…>, on 08/21/98 at 13:22:35

KA9Q -> FreeBSD changes from Eric Norum

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