]>
Commit | Line | Data |
---|---|---|
5580185e | 1 | /* |
2 | * $Source$ | |
3 | * $Header$ | |
4 | */ | |
5 | ||
6 | #ifndef lint | |
7 | static char *rcsid_tfsr_c = "$Header$"; | |
8 | #endif lint | |
9 | ||
10 | /************************************************************************/ | |
11 | /* | |
12 | /* tfsr (test forking server) | |
13 | /* -------------------------- | |
14 | /* | |
15 | /* Author: Noah Mendelsohn (IBM T.J. Watson Research and MIT Project | |
16 | /* Athena) | |
17 | /* | |
18 | /* Copyright: 1986 MIT Project Athena | |
19 | /* | |
20 | /************************************************************************/ | |
21 | /* | |
22 | /* PURPOSE | |
23 | /* ------- | |
24 | /* | |
25 | /* A GDB server program demonstrating techniques for asynchronously | |
26 | /* communicating with an arbitrary number of clients by forking | |
27 | /* a new server process for each incoming client. | |
28 | /* | |
29 | /* Each forked child receives a stream of integers, | |
30 | /* which it interprets as ASCII characters. The characters are | |
31 | /* converted to uppercase, and then sent back to the client from | |
32 | /* which they came. | |
33 | /* | |
34 | /* NOTE | |
35 | /* ---- | |
36 | /* | |
37 | /* This program is interface compatible with tsr.c. Clients | |
38 | /* cannot tell which style of server they are using. | |
39 | /* | |
40 | /************************************************************************/ | |
41 | ||
42 | #include <stdio.h> | |
43 | #include "gdb.h" | |
44 | ||
45 | ||
46 | int | |
47 | main(argc, argv) | |
48 | int argc; | |
49 | char *argv[]; | |
50 | { | |
51 | /*----------------------------------------------------------*/ | |
52 | /* | |
53 | /* LOCAL VARIABLES | |
54 | /* | |
55 | /*----------------------------------------------------------*/ | |
56 | ||
57 | CONNECTION client; /* talk on this to client */ | |
58 | ||
59 | int data; /* receive data here */ | |
60 | ||
61 | \f /*----------------------------------------------------------*/ | |
62 | /* | |
63 | /* EXECUTION BEGINS HERE | |
64 | /* | |
65 | /* Check parameters | |
66 | /* | |
67 | /*----------------------------------------------------------*/ | |
68 | ||
69 | if (argc != 2) { | |
70 | fprintf(stderr,"Correct form is %s <servicename>\n", | |
71 | argv[0]); | |
72 | exit(4); | |
73 | } | |
74 | ||
75 | /*----------------------------------------------------------*/ | |
76 | /* | |
77 | /* Initialize | |
78 | /* | |
79 | /*----------------------------------------------------------*/ | |
80 | ||
81 | gdb_init(); /* set up gdb */ | |
82 | ||
83 | /*----------------------------------------------------------*/ | |
84 | /* | |
85 | /* Now, turn ourselves into a forking server. | |
86 | /* | |
87 | /*----------------------------------------------------------*/ | |
88 | ||
89 | client = create_forking_server(argv[1],NULL); | |
90 | fprintf(stderr,"forked\n"); | |
91 | ||
92 | /*----------------------------------------------------------*/ | |
93 | /* | |
94 | /* Here we are in the child process for each client. | |
95 | /* Echo the characters. | |
96 | /* | |
97 | /*----------------------------------------------------------*/ | |
98 | ||
99 | while (TRUE) { | |
100 | if (receive_object(client, &data, INTEGER_T) == | |
101 | OP_CANCELLED) { | |
102 | fprintf(stderr,"receive error\n"); | |
103 | exit(4); | |
104 | } | |
105 | if (data >= 'a' && data <= 'z') | |
106 | data += 'A'-'a'; /* upcase the response */ | |
107 | if (send_object(client, &data, INTEGER_T) == | |
108 | OP_CANCELLED) { | |
109 | fprintf(stderr,"send error\n"); | |
110 | exit(4); | |
111 | } | |
112 | } | |
113 | } |