]>
Commit | Line | Data |
---|---|---|
5580185e | 1 | /* |
2 | * $Source$ | |
3 | * $Header$ | |
4 | */ | |
5 | ||
6 | #ifndef lint | |
7 | static char *rcsid_tcl_c = "$Header$"; | |
8 | #endif lint | |
9 | ||
10 | /************************************************************************/ | |
11 | /* | |
12 | /* tcl (test client) | |
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 simple GDB client program. This program is the client in a | |
26 | /* server/client pair. It does a start server connection and then | |
27 | /* sends characters to the server for echoing. | |
28 | /* | |
29 | /* NOTES | |
30 | /* ----- | |
31 | /* | |
32 | /* 1) For simplicity, and do demonstrate the interactive response | |
33 | /* of GDB connections, this program echoes single characters, | |
34 | /* represented as ASCII coded integers. Because of the polymorphism | |
35 | /* inherent in the send_object and receive_object functions, | |
36 | /* similar one line calls are used to transmit entire tuples | |
37 | /* (aggregates of typed fields), relations (aggregates of tuples, | |
38 | /* which are customarily represented by linked lists), etc. | |
39 | /* | |
40 | /* 2) All communication done by this program and any other | |
41 | /* GDB based program is supported across incompatible | |
42 | /* machine types. For example, this program may run on an | |
43 | /* RT/PC while the server may be running on a Vax. Since | |
44 | /* these machines use differing representations for integers, | |
45 | /* GDB must do the necessary byte order conversions. | |
46 | /* | |
47 | /* 4) Though this program is straightforward, it includes all | |
48 | /* necessary error checking of the communication | |
49 | /* path to the server. For example, this program will | |
50 | /* terminate gracefully if the server crashes or is terminated | |
51 | /* while this client is running. | |
52 | /* | |
53 | /* | |
54 | /************************************************************************/ | |
55 | ||
56 | ||
57 | #include <stdio.h> | |
58 | #include <sgtty.h> | |
59 | #include "gdb.h" | |
60 | ||
61 | struct sgttyb sgtty; | |
62 | \f | |
63 | int | |
64 | main(argc, argv) | |
65 | int argc; | |
66 | char *argv[]; | |
67 | { | |
68 | ||
69 | /*----------------------------------------------------------*/ | |
70 | /* | |
71 | /* DECLARATIONS | |
72 | /* | |
73 | /*----------------------------------------------------------*/ | |
74 | ||
75 | CONNECTION server; /* this represents the */ | |
76 | /* server*/ | |
77 | ||
78 | int data; /* the input as typed */ | |
79 | char c; /* same input as a char */ | |
80 | /* instead of an int */ | |
81 | ||
82 | /*----------------------------------------------------------*/ | |
83 | /* | |
84 | /* EXECUTION BEGINS HERE | |
85 | /* | |
86 | /* Make sure the command line specifies the name | |
87 | /* of the host on which the server program is running. | |
88 | /* | |
89 | /*----------------------------------------------------------*/ | |
90 | ||
91 | if (argc != 2) { | |
92 | /* | |
93 | * Tell 'em the syntax | |
94 | */ | |
95 | fprintf(stderr, "tcl <server-host-name:service-i.d.>\n"); | |
96 | fprintf(stderr, "\tservice-i.d. is from #port number or name from /etc/services.\n"); | |
97 | fprintf(stderr, "\tShould match name service i.d. given to tsr.\n"); | |
98 | exit (4); | |
99 | } | |
100 | ||
101 | /*----------------------------------------------------------*/ | |
102 | /* | |
103 | /* Initialize the GDB library. | |
104 | /* | |
105 | /*----------------------------------------------------------*/ | |
106 | ||
107 | gdb_init(); | |
108 | \f | |
109 | /*----------------------------------------------------------*/ | |
110 | /* | |
111 | /* Try for a connection to the server on the | |
112 | /* specified host. | |
113 | /* | |
114 | /*----------------------------------------------------------*/ | |
115 | ||
116 | printf("Attempting connection to server: %s\n", argv[1]); | |
117 | ||
118 | server = start_server_connection(argv[1], "Dummy parms"); | |
119 | ||
120 | if (server == NULL) { | |
121 | fprintf(stderr,"Could not start connection to server\n"); | |
122 | exit(8); | |
123 | } | |
124 | ||
125 | printf("Server connection started successfully.\n"); | |
126 | ||
127 | /*----------------------------------------------------------*/ | |
128 | /* | |
129 | /* Put the terminal into CBREAK mode, so that we'll | |
130 | /* see each character as it's typed. Also, turn off | |
131 | /* local character echoing, since the whole point of | |
132 | /* this program is to echo through the network. | |
133 | /* | |
134 | /*----------------------------------------------------------*/ | |
135 | ||
136 | ioctl(0, TIOCGETP, &sgtty); /* go into cbreak */ | |
137 | sgtty.sg_flags |= CBREAK; | |
138 | sgtty.sg_flags &= ~ECHO; | |
139 | ioctl(0, TIOCSETP, &sgtty); /* go into cbreak */ | |
140 | \f | |
141 | /*----------------------------------------------------------*/ | |
142 | /* | |
143 | /* Start reading from keyboard and writing to server. | |
144 | /* Send each character to the server separately, and | |
145 | /* when it is echoed, present it on the screen. <CRLF> | |
146 | /* processing is done locally. Loop until CTRL_D (EOT) | |
147 | /* is entered. | |
148 | /* | |
149 | /*----------------------------------------------------------*/ | |
150 | ||
151 | printf("Start typing data to be uppercased and echoed. ^D Exits.\n\n\n"); | |
152 | data = getchar(); | |
153 | ||
154 | #define EOT 4 | |
155 | ||
156 | while (data != EOT) { | |
157 | if (send_object(server, (char *)&data, INTEGER_T) == | |
158 | OP_CANCELLED) { | |
159 | fprintf(stderr,"\n\nSend error.\n"); | |
160 | break; | |
161 | } | |
162 | if (receive_object(server, (char *)&data, INTEGER_T) == | |
163 | OP_CANCELLED) { | |
164 | fprintf(stderr,"\n\nSend error.\n"); | |
165 | break; | |
166 | } | |
167 | c = data; | |
168 | putchar(c); | |
169 | if (c == '\r') | |
170 | putchar('\n'); | |
171 | data = getchar(); | |
172 | } | |
173 | ||
174 | /*----------------------------------------------------------*/ | |
175 | /* | |
176 | /* Put terminal back into normal line-at-a-time with | |
177 | /* echoing mode. | |
178 | /* | |
179 | /*----------------------------------------------------------*/ | |
180 | ||
181 | sgtty.sg_flags |= ECHO; | |
182 | sgtty.sg_flags &= ~CBREAK; | |
183 | ioctl(0, TIOCSETP, &sgtty); /* go into cbreak */ | |
184 | ||
185 | /*----------------------------------------------------------*/ | |
186 | /* | |
187 | /* Terminate the connection to the server. | |
188 | /* | |
189 | /*----------------------------------------------------------*/ | |
190 | ||
191 | printf("\n\nClosing connection\n\n"); | |
192 | sever_connection(server); | |
193 | return; | |
194 | } | |
195 |