FreeCalypso > hg > freecalypso-tools
comparison rfcal/cmu200/session.c @ 195:db9ee7745cdd
fc-cmu200d: socket handling skeleton added
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 24 Apr 2017 01:43:02 +0000 |
parents | |
children | 47d56330609d |
comparison
equal
deleted
inserted
replaced
194:31d43f0e469a | 195:db9ee7745cdd |
---|---|
1 /* | |
2 * This module contains the code that handles a single local socket | |
3 * connection session. | |
4 */ | |
5 | |
6 #include <ctype.h> | |
7 #include <stdio.h> | |
8 #include <stdlib.h> | |
9 #include <string.h> | |
10 #include <strings.h> | |
11 | |
12 extern int activesock; | |
13 | |
14 handle_command() | |
15 { | |
16 char readbuf[256], linebuf[256]; | |
17 int cc, pos; | |
18 | |
19 for (pos = 0; ; ) { | |
20 cc = read(activesock, readbuf, sizeof readbuf); | |
21 if (cc <= 0) { | |
22 printf("Client program closed connection\n"); | |
23 return(1); | |
24 } | |
25 if (pos + cc > sizeof linebuf) { | |
26 send_socket_response("-Command too long\n"); | |
27 return(1); | |
28 } | |
29 bcopy(readbuf, linebuf + pos, cc); | |
30 pos += cc; | |
31 if (linebuf[pos-1] == '\n') | |
32 break; | |
33 } | |
34 linebuf[pos-1] = '\0'; | |
35 printf("Client command: %s\n", linebuf); | |
36 /* actual command handling will go here */ | |
37 return(0); | |
38 } | |
39 | |
40 handle_session() | |
41 { | |
42 int rc; | |
43 | |
44 send_socket_response("+CMU200 interface daemon ready\n"); | |
45 for (;;) { | |
46 rc = handle_command(); | |
47 if (rc) | |
48 break; | |
49 } | |
50 close(activesock); | |
51 } |