~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/tools/fg-servers/dtserver/dtserver.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2         server.c
  3 
  4         Host server for dasm-to-tina interface
  5 
  6         Author: A.J.Lacey
  7         Date  : 13-1-93
  8 
  9 */
 10 
 11 #include <sys/types.h>
 12 #include <sys/socket.h>
 13 #include <netinet/in.h>
 14 #include <stdio.h>
 15 #include <stdlib.h>
 16 #include <string.h>
 17 #include <math.h>
 18 #include <netdb.h>
 19 #include <grabdefs.h>
 20 #include <grabsrv.h>
 21 
 22 /*
 23         Definitions
 24 */
 25 
 26 #define MAX_QUEUE 3
 27 
 28 
 29 static char             buf[512];
 30 extern int              target_handle;
 31 int                             suppress;
 32 
 33 
 34 int     open_srv_socket()
 35 {
 36         struct sockaddr_in  server;
 37         struct servent     *sp;
 38         int                             sock;
 39 
 40         sp = getservbyname(DASM_SERVICE, "tcp");
 41         if (sp == NULL)
 42            {
 43                 sprintf(buf, "%s server: unknown service\n", DASM_SERVICE);
 44                 fprintf(stderr, buf);
 45                 exit(1);
 46            }
 47 
 48 /*
 49         Assign server socket addresses, service port, any address, INET family
 50 */
 51         server.sin_port = sp->s_port;
 52         server.sin_addr.s_addr = INADDR_ANY;
 53         server.sin_family = AF_INET;
 54 
 55         sock = socket(AF_INET, SOCK_STREAM, 0);
 56         if (sock < 0)
 57            {
 58                 sprintf(buf, "%s server: open socket stream", DASM_SERVICE);
 59                 perror(buf);
 60                 exit(1);
 61            }
 62 /*      
 63         Bind name to socket
 64 */
 65         if (bind(sock, (struct sockaddr *)&server, sizeof server) < 0)
 66            {
 67                 sprintf(buf,"%s server: bind socket stream", DASM_SERVICE);
 68                 perror(buf);
 69                 exit(1);
 70            }
 71 
 72         return (sock);
 73 }
 74 
 75 
 76 
 77 
 78 Grabber         *get_client_info(recsock, recieved)
 79 int              recsock;
 80 Grabber         *recieved;
 81 {
 82         int err = 0;
 83 
 84         bzero(buf, sizeof buf);
 85         if (rm_read(recsock, buf, MAX_PACKET) < 1)
 86         {
 87                 sprintf(buf, "%s server: socket reading error", DASM_SERVICE);
 88                 printf(buf);
 89                 return (NULL);
 90         }
 91         
 92         sscanf(buf, "%d,%d,%d,%d,%d\n", &(recieved->width),
 93                                                                         &(recieved->length),
 94                                                                         &(recieved->spacing),
 95                                                                         &(recieved->number),
 96                                                                         &(recieved->st_pair));
 97         return (recieved);
 98 }
 99 
100 
101 
102         
103 int             send_data(sock, params, type)
104 int             sock;
105 Grabber    *params;
106 int                     type;
107 {
108 /*
109         Allows 3 passes of incomplete packet sends before error
110 */
111 
112         char               *image;
113         unsigned int    image_size;
114         int                     data_blocks, final_blocks, amount, passes;
115         int                     err, packet_error;
116 
117         image = params->im_buffer;
118         image_size = params->width * params->length;
119         data_blocks = image_size/MAX_PACKET;
120         final_blocks = image_size%MAX_PACKET;
121         packet_error = 0;
122         err = 0;
123         amount = MAX_PACKET;
124         passes = 0;
125 
126         do
127         {
128                 do
129                 {
130                         passes++;
131                         if ((err = rm_write(sock, image, amount)) == -1)
132                            return (err);
133 
134                         else
135                         if (err != amount)
136                            {
137                                 sprintf(buf,"%s server: incomplete packet sent", DASM_SERVICE);
138                                 printf(buf);
139                                 image += err;
140                                 packet_error++;
141                                 if (packet_error == 3)
142                                    return (-3);
143                            }
144                         
145                         else
146                            {
147                                 image += amount;
148                            }
149 
150                    } while(passes < data_blocks);
151 /*
152         Reset variables for remainder write
153 */
154                 packet_error = 0;
155                 amount = final_blocks;
156 
157            } while((passes != (data_blocks + 1)) && (amount != 0));
158 
159         return (0);
160 }
161                 
162 
163 
164 int                     dgrab(status, info_p)
165 int                     status;
166 Grabber    *info_p;
167 {
168 
169         unsigned int    i, size;
170         int                     derr, send_err;
171 
172         send_err = 0;
173 
174 /*
175         Pass client info to DASM driver and grab image(s)
176 */
177         info_p->count = 0;
178 
179         if ((derr = dasmd(info_p, MONO_IM)) < 0)
180         {
181                 sprintf(buf,"%s server: DASM error %d\n", DASM_SERVICE, derr);
182                 printf(buf);
183                 return (derr);          
184         }
185 /*
186         If configuration was run then return to start
187 */
188         if (derr == CONFIG);
189         else
190         {
191 /*
192         Retrieve data from dasm and send data to client
193 */
194                 for (i = 0; i < info_p->number; i++)
195                 {
196                         if ((size = up_load(info_p)) < 0 )
197                         {
198                                 sprintf(buf,"%s server: upload error: incomplete %d bytes", DASM_SERVICE, size);
199                                 printf(buf);
200                         }
201         
202                         else
203                         if ((send_err = send_data(status, info_p, MONO_IM)) < 0)
204                         {
205                                 sprintf(buf,"%s server: data return error %d\n", DASM_SERVICE, send_err);
206                                 printf(buf);
207                         }
208                 }
209         }
210 
211         if ((derr = scsi_close(target_handle)) < 0)
212         {
213                 sprintf(buf,"%s server: scsi device DASM may have failed to close\n",DASM_SERVICE);
214                 printf(buf);
215         }
216 
217         return (send_err);
218 
219 }
220 
221 
222 
223 int                      dst_grab(status, info_p)
224 int                      status;
225 Grabber         *info_p;
226 {
227 
228         unsigned int    i, size;
229         int                     derr, send_err = 0;
230 
231         info_p->count = 0;
232 
233         if ((derr = dasmd(info_p, LEFT_IM)) < 0)
234         {
235                 sprintf(buf,"%s server: DASM error %d\n", DASM_SERVICE, derr);
236                 printf(buf);
237                 return (derr);          
238         }
239 
240         if (derr != CONFIG)
241         {
242 /*
243         Retrieve and send left image
244 */
245                 if ((size = up_load(info_p)) < 0 )
246                 {
247                         sprintf(buf,"%s server: upload error: incomplete %d bytes", DASM_SERVICE, size);
248                         printf(buf);
249                 }
250         
251                 else
252                 if ((send_err = send_data(status, info_p, LEFT_IM)) < 0)
253                 {
254                         sprintf(buf,"%s server: data return error %d\n", DASM_SERVICE, send_err);
255                         printf(buf);
256                 }
257 
258 /*
259         Grab, retrieve and send right image
260 */
261                 info_p->count = 0;
262 
263                 if ((derr = dasmd(info_p, RIGHT_IM)) < 0)
264                 {
265                         sprintf(buf,"%s server: DASM error %d\n", DASM_SERVICE, derr);
266                         printf(buf);
267                         return (derr);          
268                 }
269 
270                 if ((size = up_load(info_p)) < 0 )
271                 {
272                         sprintf(buf,"%s server: upload error: incomplete %d bytes", DASM_SERVICE, size);
273                         printf(buf);
274                 }
275         
276                 else
277                 if ((send_err = send_data(status, info_p, RIGHT_IM)) < 0)
278                 {
279                         sprintf(buf,"%s server: data return error %d\n", DASM_SERVICE, send_err);
280                         printf(buf);
281                 }
282 
283         }
284 
285         if ((derr = scsi_close(target_handle)) < 0)
286         {
287                 sprintf(buf,"%s server: scsi device DASM may have failed to close\n",DASM_SERVICE);
288                 printf(buf);
289         }
290 
291         return (send_err);
292 
293 }
294 
295 
296 
297 void    passed_params(argc, argv)
298 int     argc;
299 char   *argv[];
300 {
301         if (argc == 1)
302                 return;
303 
304         if (!strcmp(argv[1], "-s") || !strcmp(argv[1], "s"))
305                 suppress = 1;
306 }
307 
308 
309 
310 
311 main(argc, argv)
312 int argc;
313 char *argv[];
314 {
315 
316         Grabber                 info_p;
317         int                     status, s_handle, gstate;
318         int                     derr, send_err;
319              
320 
321         passed_params(argc, argv);
322         s_handle = open_srv_socket();
323         printf("%s: listening on socket %d\n", DASM_SERVICE, s_handle);
324 
325         if (listen(s_handle, MAX_QUEUE) < 0)
326            {
327                 sprintf(buf, "%s server: listen error on socket %d", DASM_SERVICE, s_handle);
328                 perror(buf);
329                 exit(1);
330            }
331 
332         for (;;)
333         {
334                 status = accept(s_handle, (struct sockaddr *)0, (int *)0);
335                 if (status < 0)
336                 {
337                         printf(buf,"%s server: accept error", DASM_SERVICE);
338                         perror(buf);
339                 }
340 
341                 else
342                 {
343                         if ((get_client_info(status, &info_p)) == NULL )
344                         {
345                                 sprintf(buf,"%s server: client info error\n", DASM_SERVICE);
346                                 printf(buf);
347                         }
348 
349                         else
350                         {
351                                 if (info_p.st_pair == MONO_GRAB)
352                                         gstate = dgrab(status, &info_p);
353 
354                                 if (info_p.st_pair == STEREO_GRAB)
355                                         gstate = dst_grab(status, &info_p);
356                         }
357                 }
358                                          
359                 close(status);
360         }
361 
362 }
363 
364 
365 
366 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.