[Spice-devel] [PATCH v2 1/3] vdagent: Group the client and server functions together
This will simplify selectively disabling the server-side code. Signed-off-by: Francois Gouget--- src/udscs.c | 478 ++-- src/udscs.h | 128 +--- 2 files changed, 314 insertions(+), 292 deletions(-) I separated the reordering from the addition of the #ifdefs as suggested by Victor Toso: http://lists.freedesktop.org/archives/spice-devel/2015-November/023457.html diff --git a/src/udscs.c b/src/udscs.c index 288aca2..732db33 100644 --- a/src/udscs.c +++ b/src/udscs.c @@ -66,86 +66,6 @@ struct udscs_connection { struct udscs_connection *prev; }; -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; -udscs_read_callback read_callback; -udscs_disconnect_callback disconnect_callback; -}; - -static void udscs_do_write(struct udscs_connection **connp); -static void udscs_do_read(struct udscs_connection **connp); - - -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 c; -struct sockaddr_un address; -struct udscs_server *server; - -server = calloc(1, sizeof(*server)); -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); -if (server->fd == -1) { -syslog(LOG_ERR, "creating unix domain socket: %m"); -free(server); -return NULL; -} - -address.sun_family = AF_UNIX; -snprintf(address.sun_path, sizeof(address.sun_path), "%s", socketname); -c = bind(server->fd, (struct sockaddr *), sizeof(address)); -if (c != 0) { -syslog(LOG_ERR, "bind %s: %m", socketname); -free(server); -return NULL; -} - -c = listen(server->fd, 5); -if (c != 0) { -syslog(LOG_ERR, "listen: %m"); -free(server); -return NULL; -} - -server->connect_callback = connect_callback; -server->read_callback = read_callback; -server->disconnect_callback = disconnect_callback; - -return server; -} - -void udscs_destroy_server(struct udscs_server *server) -{ -struct udscs_connection *conn, *next_conn; - -if (!server) -return; - -conn = server->connections_head.next; -while (conn) { -next_conn = conn->next; -udscs_destroy_connection(); -conn = next_conn; -} -close(server->fd); -free(server); -} - struct udscs_connection *udscs_connect(const char *socketname, udscs_read_callback read_callback, udscs_disconnect_callback disconnect_callback, @@ -225,131 +145,17 @@ void udscs_destroy_connection(struct udscs_connection **connp) *connp = NULL; } -struct ucred udscs_get_peer_cred(struct udscs_connection *conn) -{ -return conn->peer_cred; -} - -int udscs_server_fill_fds(struct udscs_server *server, fd_set *readfds, -fd_set *writefds) +void udscs_set_user_data(struct udscs_connection *conn, void *data) { -struct udscs_connection *conn; -int nfds = server->fd + 1; - -if (!server) -return -1; - -FD_SET(server->fd, readfds); - -conn = server->connections_head.next; -while (conn) { -int conn_nfds = udscs_client_fill_fds(conn, readfds, writefds); -if (conn_nfds > nfds) -nfds = conn_nfds; - -conn = conn->next; -} - -return nfds; +conn->user_data = data; } -int udscs_client_fill_fds(struct udscs_connection *conn, fd_set *readfds, -fd_set *writefds) +void *udscs_get_user_data(struct udscs_connection *conn) { if (!conn) -return -1; - -FD_SET(conn->fd, readfds); -if (conn->write_buf) -FD_SET(conn->fd, writefds); - -return conn->fd + 1; -} - -static void udscs_server_accept(struct udscs_server *server) { -struct udscs_connection *new_conn, *conn; -struct sockaddr_un address; -socklen_t length = sizeof(address); -int r, fd; - -fd = accept(server->fd, (struct sockaddr *), ); -if (fd == -1) { -if (errno == EINTR) -return; -syslog(LOG_ERR, "accept: %m"); -return; -} - -new_conn = calloc(1, sizeof(*conn)); -if (!new_conn) { -syslog(LOG_ERR, "out of memory, disconnecting new client"); -close(fd); -return; -} - -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; - -length =
Re: [Spice-devel] [PATCH v2 1/3] vdagent: Group the client and server functions together
On Fri, Nov 13, 2015 at 05:26:34PM +0100, Francois Gouget wrote: > On Fri, 13 Nov 2015, Victor Toso wrote: > [...] > > PS: Now it seems to be correctly threaded in patchwork, thanks! > > https://patchwork.freedesktop.org/series/745/ > > Is there a reference to Spice's patchwork page somewhere? It seems that patchwork for Spice was never really used till now... I'm taking a closer look to it for a few days as there is an ongoing work on Freedesktop instance of patchwork. https://patchwork.freedesktop.org/project/Spice/patches/ Let me know if you have any experience/comments about it. ___ Spice-devel mailing list Spice-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/spice-devel
Re: [Spice-devel] [PATCH v2 1/3] vdagent: Group the client and server functions together
Hi, On Fri, Nov 13, 2015 at 04:26:16PM +0100, Francois Gouget wrote: > This will simplify selectively disabling the server-side code. Thanks for splitting the PATCH. If nobody complains I'll be pushing the vdagent patches shortly. PS: Now it seems to be correctly threaded in patchwork, thanks! https://patchwork.freedesktop.org/series/745/ Cheers, Victor Toso > Signed-off-by: Francois Gouget> --- > src/udscs.c | 478 > ++-- > src/udscs.h | 128 +--- > 2 files changed, 314 insertions(+), 292 deletions(-) > > I separated the reordering from the addition of the #ifdefs as suggested > by Victor Toso: > http://lists.freedesktop.org/archives/spice-devel/2015-November/023457.html > > diff --git a/src/udscs.c b/src/udscs.c > index 288aca2..732db33 100644 > --- a/src/udscs.c > +++ b/src/udscs.c > @@ -66,86 +66,6 @@ struct udscs_connection { > struct udscs_connection *prev; > }; > > -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; > -udscs_read_callback read_callback; > -udscs_disconnect_callback disconnect_callback; > -}; > - > -static void udscs_do_write(struct udscs_connection **connp); > -static void udscs_do_read(struct udscs_connection **connp); > - > - > -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 c; > -struct sockaddr_un address; > -struct udscs_server *server; > - > -server = calloc(1, sizeof(*server)); > -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); > -if (server->fd == -1) { > -syslog(LOG_ERR, "creating unix domain socket: %m"); > -free(server); > -return NULL; > -} > - > -address.sun_family = AF_UNIX; > -snprintf(address.sun_path, sizeof(address.sun_path), "%s", socketname); > -c = bind(server->fd, (struct sockaddr *), sizeof(address)); > -if (c != 0) { > -syslog(LOG_ERR, "bind %s: %m", socketname); > -free(server); > -return NULL; > -} > - > -c = listen(server->fd, 5); > -if (c != 0) { > -syslog(LOG_ERR, "listen: %m"); > -free(server); > -return NULL; > -} > - > -server->connect_callback = connect_callback; > -server->read_callback = read_callback; > -server->disconnect_callback = disconnect_callback; > - > -return server; > -} > - > -void udscs_destroy_server(struct udscs_server *server) > -{ > -struct udscs_connection *conn, *next_conn; > - > -if (!server) > -return; > - > -conn = server->connections_head.next; > -while (conn) { > -next_conn = conn->next; > -udscs_destroy_connection(); > -conn = next_conn; > -} > -close(server->fd); > -free(server); > -} > - > struct udscs_connection *udscs_connect(const char *socketname, > udscs_read_callback read_callback, > udscs_disconnect_callback disconnect_callback, > @@ -225,131 +145,17 @@ void udscs_destroy_connection(struct udscs_connection > **connp) > *connp = NULL; > } > > -struct ucred udscs_get_peer_cred(struct udscs_connection *conn) > -{ > -return conn->peer_cred; > -} > - > -int udscs_server_fill_fds(struct udscs_server *server, fd_set *readfds, > -fd_set *writefds) > +void udscs_set_user_data(struct udscs_connection *conn, void *data) > { > -struct udscs_connection *conn; > -int nfds = server->fd + 1; > - > -if (!server) > -return -1; > - > -FD_SET(server->fd, readfds); > - > -conn = server->connections_head.next; > -while (conn) { > -int conn_nfds = udscs_client_fill_fds(conn, readfds, writefds); > -if (conn_nfds > nfds) > -nfds = conn_nfds; > - > -conn = conn->next; > -} > - > -return nfds; > +conn->user_data = data; > } > > -int udscs_client_fill_fds(struct udscs_connection *conn, fd_set *readfds, > -fd_set *writefds) > +void *udscs_get_user_data(struct udscs_connection *conn) > { > if (!conn) > -return -1; > - > -FD_SET(conn->fd, readfds); > -if (conn->write_buf) > -FD_SET(conn->fd, writefds); > - > -return conn->fd + 1; > -} > - > -static void udscs_server_accept(struct udscs_server *server) { > -struct udscs_connection *new_conn, *conn; > -struct sockaddr_un address; > -socklen_t length = sizeof(address); > -int r, fd; > - > -fd = accept(server->fd, (struct sockaddr *), );
Re: [Spice-devel] [PATCH v2 1/3] vdagent: Group the client and server functions together
On Fri, 13 Nov 2015, Victor Toso wrote: [...] > PS: Now it seems to be correctly threaded in patchwork, thanks! > https://patchwork.freedesktop.org/series/745/ Is there a reference to Spice's patchwork page somewhere? -- Francois Gouget___ Spice-devel mailing list Spice-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/spice-devel