[Spice-devel] [PATCH v6 2/5] udscs: don't pass message type strings into the server.
Michal Suchanek
msuchanek at suse.de
Mon Jan 23 13:53:52 UTC 2017
The message types are defined by the protocol so the same array is
always passed into the server anyway. So define the array size to be the
number of message types and just use the array and limit directly in
udscs. If somebody adds a message type in the future the array will
contain some friendly NULLs at the end.
Signed-off-by: Michal Suchanek <msuchanek at suse.de>
---
src/udscs.c | 23 +++++++----------------
src/udscs.h | 4 ++--
src/vdagent/vdagent.c | 1 -
src/vdagentd-proto-strings.h | 3 ++-
src/vdagentd/vdagentd.c | 1 -
5 files changed, 11 insertions(+), 21 deletions(-)
diff --git a/src/udscs.c b/src/udscs.c
index fdd75a4..631f889 100644
--- a/src/udscs.c
+++ b/src/udscs.c
@@ -32,6 +32,7 @@
#include <sys/socket.h>
#include <sys/un.h>
#include "udscs.h"
+#include "vdagentd-proto-strings.h"
struct udscs_buf {
uint8_t *buf;
@@ -43,8 +44,6 @@ struct udscs_buf {
struct udscs_connection {
int fd;
- const char * const *type_to_string;
- int no_types;
int debug;
void *user_data;
#ifndef UDSCS_NO_SERVER
@@ -71,7 +70,7 @@ struct udscs_connection {
struct udscs_connection *udscs_connect(const char *socketname,
udscs_read_callback read_callback,
udscs_disconnect_callback disconnect_callback,
- const char * const type_to_string[], int no_types, int debug)
+ int debug)
{
int c;
struct sockaddr_un address;
@@ -81,8 +80,6 @@ struct udscs_connection *udscs_connect(const char *socketname,
if (!conn)
return NULL;
- conn->type_to_string = type_to_string;
- conn->no_types = no_types;
conn->debug = debug;
conn->fd = socket(PF_UNIX, SOCK_STREAM, 0);
@@ -189,9 +186,9 @@ int udscs_write(struct udscs_connection *conn, uint32_t type, uint32_t arg1,
memcpy(new_wbuf->buf + sizeof(header), data, size);
if (conn->debug) {
- if (type < conn->no_types)
+ if (type < VDAGENTD_NO_MESSAGES)
syslog(LOG_DEBUG, "%p sent %s, arg1: %u, arg2: %u, size %u",
- conn, conn->type_to_string[type], arg1, arg2, size);
+ conn, vdagentd_messages[type], arg1, arg2, size);
else
syslog(LOG_DEBUG,
"%p sent invalid message %u, arg1: %u, arg2: %u, size %u",
@@ -219,10 +216,10 @@ static void udscs_read_complete(struct udscs_connection **connp)
struct udscs_connection *conn = *connp;
if (conn->debug) {
- if (conn->header.type < conn->no_types)
+ if (conn->header.type < VDAGENTD_NO_MESSAGES)
syslog(LOG_DEBUG,
"%p received %s, arg1: %u, arg2: %u, size %u",
- conn, conn->type_to_string[conn->header.type],
+ conn, vdagentd_messages[conn->header.type],
conn->header.arg1, conn->header.arg2, conn->header.size);
else
syslog(LOG_DEBUG,
@@ -360,8 +357,6 @@ int udscs_client_fill_fds(struct udscs_connection *conn, fd_set *readfds,
struct udscs_server {
int fd;
- const char * const *type_to_string;
- int no_types;
int debug;
struct udscs_connection connections_head;
udscs_connect_callback connect_callback;
@@ -373,7 +368,7 @@ struct udscs_server *udscs_create_server(const char *socketname,
udscs_connect_callback connect_callback,
udscs_read_callback read_callback,
udscs_disconnect_callback disconnect_callback,
- const char * const type_to_string[], int no_types, int debug)
+ int debug)
{
int c;
struct sockaddr_un address;
@@ -383,8 +378,6 @@ struct udscs_server *udscs_create_server(const char *socketname,
if (!server)
return NULL;
- server->type_to_string = type_to_string;
- server->no_types = no_types;
server->debug = debug;
server->fd = socket(PF_UNIX, SOCK_STREAM, 0);
@@ -461,8 +454,6 @@ static void udscs_server_accept(struct udscs_server *server) {
}
new_conn->fd = fd;
- new_conn->type_to_string = server->type_to_string;
- new_conn->no_types = server->no_types;
new_conn->debug = server->debug;
new_conn->read_callback = server->read_callback;
new_conn->disconnect_callback = server->disconnect_callback;
diff --git a/src/udscs.h b/src/udscs.h
index 6160568..61818cf 100644
--- a/src/udscs.h
+++ b/src/udscs.h
@@ -69,7 +69,7 @@ typedef void (*udscs_disconnect_callback)(struct udscs_connection *conn);
struct udscs_connection *udscs_connect(const char *socketname,
udscs_read_callback read_callback,
udscs_disconnect_callback disconnect_callback,
- const char * const type_to_string[], int no_types, int debug);
+ int debug);
/* Close the connection, releases the corresponding resources and
* sets *connp to NULL.
@@ -135,7 +135,7 @@ struct udscs_server *udscs_create_server(const char *socketname,
udscs_connect_callback connect_callback,
udscs_read_callback read_callback,
udscs_disconnect_callback disconnect_callback,
- const char * const type_to_string[], int no_types, int debug);
+ int debug);
/* Close all the server's connections and releases the corresponding
* resources.
diff --git a/src/vdagent/vdagent.c b/src/vdagent/vdagent.c
index 3d195b1..616fc63 100644
--- a/src/vdagent/vdagent.c
+++ b/src/vdagent/vdagent.c
@@ -147,7 +147,6 @@ static int client_setup(int reconnect)
{
while (!quit) {
client = udscs_connect(vdagentd_socket, daemon_read_complete, NULL,
- vdagentd_messages, VDAGENTD_NO_MESSAGES,
debug);
if (client || !reconnect || quit) {
break;
diff --git a/src/vdagentd-proto-strings.h b/src/vdagentd-proto-strings.h
index 6e7bcee..115f67f 100644
--- a/src/vdagentd-proto-strings.h
+++ b/src/vdagentd-proto-strings.h
@@ -18,11 +18,12 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <vdagentd-proto.h>
#ifndef __VDAGENTD_PROTO_STRINGS_H
#define __VDAGENTD_PROTO_STRINGS_H
-static const char * const vdagentd_messages[] = {
+static const char * const vdagentd_messages[VDAGENTD_NO_MESSAGES] = {
"guest xorg resolution",
"monitors config",
"clipboard grab",
diff --git a/src/vdagentd/vdagentd.c b/src/vdagentd/vdagentd.c
index e2d6159..2b16ca4 100644
--- a/src/vdagentd/vdagentd.c
+++ b/src/vdagentd/vdagentd.c
@@ -965,7 +965,6 @@ int main(int argc, char *argv[])
/* Setup communication with vdagent process(es) */
server = udscs_create_server(vdagentd_socket, agent_connect,
agent_read_complete, agent_disconnect,
- vdagentd_messages, VDAGENTD_NO_MESSAGES,
debug);
if (!server) {
if (errno == EADDRINUSE) {
--
2.10.2
More information about the Spice-devel
mailing list