annotate rvinterf/lowlevel/localsock.c @ 184:4714fdfca39c

fc-tmsh compiles!
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 24 Nov 2013 08:40:44 +0000
parents 7ab6b29e76bb
children ec040f521cc2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
171
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
177
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
2 * This rvinterf module handles the local UNIX domain socket interface
171
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 */
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <sys/types.h>
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <sys/socket.h>
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <sys/un.h>
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <stdio.h>
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <string.h>
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <strings.h>
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include <stdlib.h>
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 #include <unistd.h>
177
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
13 #include "../localsock.h"
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
14 #include "client.h"
171
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15
177
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
16 static char sockpath[] = "/tmp/rvinterf_socket";
171
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17
177
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
18 int listener;
171
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19
177
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
20 extern struct client *client_head;
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
21 extern int max_fd;
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
22
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
23 create_listener_socket()
171
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 {
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 /* local socket binding voodoo copied from osmocon */
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 struct sockaddr_un local;
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 unsigned int namelen;
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 int rc;
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29
177
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
30 listener = socket(AF_UNIX, SOCK_STREAM, 0);
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
31 if (listener < 0) {
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
32 perror("socket(AF_UNIX, SOCK_STREAM, 0)");
171
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 exit(1);
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 }
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 local.sun_family = AF_UNIX;
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 strncpy(local.sun_path, sockpath, sizeof(local.sun_path));
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 local.sun_path[sizeof(local.sun_path) - 1] = '\0';
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 unlink(local.sun_path);
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 /* we use the same magic that X11 uses in Xtranssock.c for
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 * calculating the proper length of the sockaddr */
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 #if defined(BSD44SOCKETS) || defined(__UNIXWARE__)
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 local.sun_len = strlen(local.sun_path);
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 #endif
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 #if defined(BSD44SOCKETS) || defined(SUN_LEN)
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 namelen = SUN_LEN(&local);
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 #else
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 namelen = strlen(local.sun_path) +
177
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
50 offsetof(struct sockaddr_un, sun_path) + 1;
171
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 #endif
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52
177
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
53 rc = bind(listener, (struct sockaddr *) &local, namelen);
171
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 if (rc != 0) {
177
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
55 perror("bind on local socket");
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
56 exit(1);
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
57 }
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
58 rc = listen(listener, 3);
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
59 if (rc != 0) {
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
60 perror("listen");
171
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 exit(1);
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 }
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63
177
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
64 if (listener > max_fd)
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
65 max_fd = listener;
171
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 return(0);
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 }
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68
177
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
69 static void
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
70 prep_for_length_rx(cli)
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
71 struct client *cli;
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
72 {
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
73 cli->rx_state = 0;
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
74 cli->rx_ptr = cli->rx_buf;
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
75 cli->rx_left = 2;
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
76 }
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
77
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
78 static void
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
79 prep_for_message_rx(cli)
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
80 struct client *cli;
171
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
81 {
177
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
82 cli->rx_state = 1;
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
83 cli->rx_ptr = cli->rx_buf;
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
84 cli->rx_left = cli->rx_msglen;
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
85 }
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
86
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
87 handle_listener_select()
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
88 {
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
89 struct sockaddr_un un_addr;
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
90 socklen_t len;
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
91 int rc;
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
92 struct client *newcli;
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
93
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
94 len = sizeof(un_addr);
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
95 rc = accept(listener, (struct sockaddr *) &un_addr, &len);
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
96 if (rc < 0) {
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
97 perror("rvinterf: accept");
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
98 exit(1);
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
99 }
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
100 newcli = malloc(sizeof(struct client));
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
101 if (!newcli) {
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
102 perror("rvinterf: malloc for new client");
171
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
103 exit(1);
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
104 }
177
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
105 bzero(newcli, sizeof(struct client));
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
106 newcli->fd = rc;
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
107 newcli->next = client_head;
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
108 client_head = newcli;
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
109 prep_for_length_rx(newcli);
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
110 return(0);
171
4d8e4c58df71 rvtdump: implemented Tx extension hack, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
111 }
177
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
112
178
7ab6b29e76bb rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 177
diff changeset
113 send_local_msg_to_client(cli, msg)
7ab6b29e76bb rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 177
diff changeset
114 struct client *cli;
7ab6b29e76bb rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 177
diff changeset
115 char *msg;
7ab6b29e76bb rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 177
diff changeset
116 {
7ab6b29e76bb rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 177
diff changeset
117 int len, len1;
7ab6b29e76bb rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 177
diff changeset
118 u_char hdr[3];
7ab6b29e76bb rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 177
diff changeset
119
7ab6b29e76bb rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 177
diff changeset
120 len = strlen(msg);
7ab6b29e76bb rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 177
diff changeset
121 len1 = len + 1;
7ab6b29e76bb rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 177
diff changeset
122 hdr[0] = len1 >> 8;
7ab6b29e76bb rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 177
diff changeset
123 hdr[1] = len1 & 0xFF;
7ab6b29e76bb rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 177
diff changeset
124 hdr[2] = RVI2CLI_LOCAL_CMD_RESP;
7ab6b29e76bb rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 177
diff changeset
125 write(cli->fd, hdr, 3);
7ab6b29e76bb rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 177
diff changeset
126 write(cli->fd, msg, len);
7ab6b29e76bb rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 177
diff changeset
127 }
7ab6b29e76bb rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 177
diff changeset
128
177
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
129 void
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
130 handle_client_select(cli)
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
131 struct client *cli;
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
132 {
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
133 int cc;
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
134
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
135 cc = read(cli->fd, cli->rx_ptr, cli->rx_left);
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
136 if (cc <= 0) {
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
137 /* normal client exit condition */
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
138 close_socket: cli->rx_state = 2;
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
139 return;
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
140 }
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
141 cli->rx_ptr += cc;
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
142 cli->rx_left -= cc;
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
143 if (cli->rx_left)
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
144 return;
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
145 /* got the thing, process it */
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
146 if (cli->rx_state) {
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
147 prep_for_length_rx(cli);
178
7ab6b29e76bb rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 177
diff changeset
148 process_msg_from_client(cli);
177
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
149 } else {
178
7ab6b29e76bb rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 177
diff changeset
150 cli->rx_msglen = cli->rx_buf[0] << 8 | cli->rx_buf[1];
177
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
151 if (cli->rx_msglen < 1 || cli->rx_msglen > LOCALSOCK_MAX_MSG) {
178
7ab6b29e76bb rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 177
diff changeset
152 send_local_msg_to_client(cli,
7ab6b29e76bb rvinterf: forwarding of Rx packets to clients implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 177
diff changeset
153 "-Invalid length, closing socket");
177
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
154 goto close_socket;
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
155 }
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
156 prep_for_message_rx(cli);
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
157 }
fef035264dd4 rvinterf: beginning of local socket handling
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 173
diff changeset
158 }