[Spice-devel] [linux-vdagent PATCH 2/4] vdagent-virtio-port: rename port parameter to vport

Hans de Goede hdegoede at redhat.com
Wed Mar 23 12:31:06 PDT 2011


The chunks being send over the vdagent virtio port are multiplexed and
contain a member inside there header called port, rename all port function
parameters to vport, since they refer to a vdagent-virtio-port, and not a
port in the meaning it has inside of a chunk.
---
 vdagent-virtio-port.c |  206 ++++++++++++++++++++++++------------------------
 vdagent-virtio-port.h |   12 ++--
 vdagentd.c            |   22 +++---
 3 files changed, 120 insertions(+), 120 deletions(-)

diff --git a/vdagent-virtio-port.c b/vdagent-virtio-port.c
index a4411e5..0b723f8 100644
--- a/vdagent-virtio-port.c
+++ b/vdagent-virtio-port.c
@@ -58,46 +58,46 @@ struct vdagent_virtio_port {
     vdagent_virtio_port_disconnect_callback disconnect_callback;
 };
 
-static void vdagent_virtio_port_do_write(struct vdagent_virtio_port **portp);
-static void vdagent_virtio_port_do_read(struct vdagent_virtio_port **portp);
+static void vdagent_virtio_port_do_write(struct vdagent_virtio_port **vportp);
+static void vdagent_virtio_port_do_read(struct vdagent_virtio_port **vportp);
 
 struct vdagent_virtio_port *vdagent_virtio_port_create(const char *portname,
     vdagent_virtio_port_read_callback read_callback,
     vdagent_virtio_port_disconnect_callback disconnect_callback,
     FILE *errfile)
 {
-    struct vdagent_virtio_port *port;
+    struct vdagent_virtio_port *vport;
 
-    port = calloc(1, sizeof(*port));
-    if (!port)
+    vport = calloc(1, sizeof(*vport));
+    if (!vport)
         return 0;
 
-    port->errfile = errfile;
-    port->fd = open(portname, O_RDWR);
-    if (port->fd == -1) {
-        fprintf(port->errfile, "open %s: %s\n", portname, strerror(errno));
-        free(port);
+    vport->errfile = errfile;
+    vport->fd = open(portname, O_RDWR);
+    if (vport->fd == -1) {
+        fprintf(vport->errfile, "open %s: %s\n", portname, strerror(errno));
+        free(vport);
         return NULL;
     }    
 
-    port->read_callback = read_callback;
-    port->disconnect_callback = disconnect_callback;
+    vport->read_callback = read_callback;
+    vport->disconnect_callback = disconnect_callback;
 
-    return port;
+    return vport;
 }
 
-void vdagent_virtio_port_destroy(struct vdagent_virtio_port **portp)
+void vdagent_virtio_port_destroy(struct vdagent_virtio_port **vportp)
 {
     struct vdagent_virtio_port_buf *wbuf, *next_wbuf;
-    struct vdagent_virtio_port *port = *portp;
+    struct vdagent_virtio_port *vport = *vportp;
 
-    if (!port)
+    if (!vport)
         return;
 
-    if (port->disconnect_callback)
-        port->disconnect_callback(port);
+    if (vport->disconnect_callback)
+        vport->disconnect_callback(vport);
 
-    wbuf = port->write_buf;
+    wbuf = vport->write_buf;
     while (wbuf) {
         next_wbuf = wbuf->next;
         free(wbuf->buf);
@@ -105,41 +105,41 @@ void vdagent_virtio_port_destroy(struct vdagent_virtio_port **portp)
         wbuf = next_wbuf;
     }
 
-    free(port->message_data);
+    free(vport->message_data);
 
-    close(port->fd);
-    free(port);
-    *portp = NULL;
+    close(vport->fd);
+    free(vport);
+    *vportp = NULL;
 }
 
-int vdagent_virtio_port_fill_fds(struct vdagent_virtio_port *port,
+int vdagent_virtio_port_fill_fds(struct vdagent_virtio_port *vport,
         fd_set *readfds, fd_set *writefds)
 {
-    if (!port)
+    if (!vport)
         return -1;
 
-    FD_SET(port->fd, readfds);
-    if (port->write_buf)
-        FD_SET(port->fd, writefds);
+    FD_SET(vport->fd, readfds);
+    if (vport->write_buf)
+        FD_SET(vport->fd, writefds);
 
-    return port->fd + 1;
+    return vport->fd + 1;
 }
 
-void vdagent_virtio_port_handle_fds(struct vdagent_virtio_port **portp,
+void vdagent_virtio_port_handle_fds(struct vdagent_virtio_port **vportp,
         fd_set *readfds, fd_set *writefds)
 {
-    if (!*portp)
+    if (!*vportp)
         return;
 
-    if (FD_ISSET((*portp)->fd, readfds))
-        vdagent_virtio_port_do_read(portp);
+    if (FD_ISSET((*vportp)->fd, readfds))
+        vdagent_virtio_port_do_read(vportp);
 
-    if (*portp && FD_ISSET((*portp)->fd, writefds))
-        vdagent_virtio_port_do_write(portp);
+    if (*vportp && FD_ISSET((*vportp)->fd, writefds))
+        vdagent_virtio_port_do_write(vportp);
 }
 
 int vdagent_virtio_port_write(
-        struct vdagent_virtio_port *port,
+        struct vdagent_virtio_port *vport,
         uint32_t port_nr,
         uint32_t message_type,
         uint32_t message_opaque,
@@ -176,13 +176,13 @@ int vdagent_virtio_port_write(
     memcpy(new_wbuf->buf + sizeof(chunk_header) + sizeof(message_header),
            data, data_size);
 
-    if (!port->write_buf) {
-        port->write_buf = new_wbuf;
+    if (!vport->write_buf) {
+        vport->write_buf = new_wbuf;
         return 0;
     }
 
     /* maybe we should limit the write_buf stack depth ? */
-    wbuf = port->write_buf;
+    wbuf = vport->write_buf;
     while (wbuf->next)
         wbuf = wbuf->next;
 
@@ -191,44 +191,44 @@ int vdagent_virtio_port_write(
     return 0;
 }
 
-void vdagent_virtio_port_flush(struct vdagent_virtio_port **portp)
+void vdagent_virtio_port_flush(struct vdagent_virtio_port **vportp)
 {
-    while (*portp && (*portp)->write_buf)
-        vdagent_virtio_port_do_write(portp);
+    while (*vportp && (*vportp)->write_buf)
+        vdagent_virtio_port_do_write(vportp);
 }
 
-static void vdagent_virtio_port_do_chunk(struct vdagent_virtio_port **portp)
+static void vdagent_virtio_port_do_chunk(struct vdagent_virtio_port **vportp)
 {
     int avail, read, pos = 0;
-    struct vdagent_virtio_port *port = *portp;
+    struct vdagent_virtio_port *vport = *vportp;
 
-    if (port->message_header_read < sizeof(port->message_header)) {
-        read = sizeof(port->message_header) - port->message_header_read;
-        if (read > port->chunk_header.size) {
-            read = port->chunk_header.size;
+    if (vport->message_header_read < sizeof(vport->message_header)) {
+        read = sizeof(vport->message_header) - vport->message_header_read;
+        if (read > vport->chunk_header.size) {
+            read = vport->chunk_header.size;
         }
-        memcpy((uint8_t *)&port->message_header + port->message_header_read,
-               port->chunk_data, read);
-        port->message_header_read += read;
-        if (port->message_header_read == sizeof(port->message_header) &&
-                port->message_header.size) {
-            port->message_data = malloc(port->message_header.size);
-            if (!port->message_data) {
-                fprintf(port->errfile, "out of memory, disconnecting virtio\n");
-                vdagent_virtio_port_destroy(portp);
+        memcpy((uint8_t *)&vport->message_header + vport->message_header_read,
+               vport->chunk_data, read);
+        vport->message_header_read += read;
+        if (vport->message_header_read == sizeof(vport->message_header) &&
+                vport->message_header.size) {
+            vport->message_data = malloc(vport->message_header.size);
+            if (!vport->message_data) {
+                fprintf(vport->errfile, "out of memory, disconnecting virtio\n");
+                vdagent_virtio_port_destroy(vportp);
                 return;
             }
         }
         pos = read;
     }
 
-    if (port->message_header_read == sizeof(port->message_header)) {
-        read  = port->message_header.size - port->message_data_pos;
-        avail = port->chunk_header.size - pos;
+    if (vport->message_header_read == sizeof(vport->message_header)) {
+        read  = vport->message_header.size - vport->message_data_pos;
+        avail = vport->chunk_header.size - pos;
 
         if (avail > read) {
-            fprintf(port->errfile, "chunk larger then message, lost sync?\n");
-            vdagent_virtio_port_destroy(portp);
+            fprintf(vport->errfile, "chunk larger then message, lost sync?\n");
+            vdagent_virtio_port_destroy(vportp);
             return;
         }
 
@@ -236,101 +236,101 @@ static void vdagent_virtio_port_do_chunk(struct vdagent_virtio_port **portp)
             read = avail;
 
         if (read) {
-            memcpy(port->message_data + port->message_data_pos,
-                   port->chunk_data + pos, read);
-            port->message_data_pos += read;
+            memcpy(vport->message_data + vport->message_data_pos,
+                   vport->chunk_data + pos, read);
+            vport->message_data_pos += read;
         }
 
-        if (port->message_data_pos == port->message_header.size) {
-            if (port->read_callback) {
-                int r = port->read_callback(port, &port->chunk_header,
-                                    &port->message_header, port->message_data);
+        if (vport->message_data_pos == vport->message_header.size) {
+            if (vport->read_callback) {
+                int r = vport->read_callback(vport, &vport->chunk_header,
+                                 &vport->message_header, vport->message_data);
                 if (r == -1) {
-                    vdagent_virtio_port_destroy(portp);
+                    vdagent_virtio_port_destroy(vportp);
                     return;
                 }
             }
-            port->message_header_read = 0;
-            port->message_data_pos = 0;
-            free(port->message_data);
-            port->message_data = NULL;
+            vport->message_header_read = 0;
+            vport->message_data_pos = 0;
+            free(vport->message_data);
+            vport->message_data = NULL;
         }
     }
 }
 
-static void vdagent_virtio_port_do_read(struct vdagent_virtio_port **portp)
+static void vdagent_virtio_port_do_read(struct vdagent_virtio_port **vportp)
 {
     ssize_t n;
     size_t to_read;
     uint8_t *dest;
-    struct vdagent_virtio_port *port = *portp;
+    struct vdagent_virtio_port *vport = *vportp;
 
-    if (port->chunk_header_read < sizeof(port->chunk_header)) {
-        to_read = sizeof(port->chunk_header) - port->chunk_header_read;
-        dest = (uint8_t *)&port->chunk_header + port->chunk_header_read;
+    if (vport->chunk_header_read < sizeof(vport->chunk_header)) {
+        to_read = sizeof(vport->chunk_header) - vport->chunk_header_read;
+        dest = (uint8_t *)&vport->chunk_header + vport->chunk_header_read;
     } else {
-        to_read = port->chunk_header.size - port->chunk_data_pos;
-        dest = port->chunk_data + port->chunk_data_pos;
+        to_read = vport->chunk_header.size - vport->chunk_data_pos;
+        dest = vport->chunk_data + vport->chunk_data_pos;
     }
 
-    n = read(port->fd, dest, to_read);
+    n = read(vport->fd, dest, to_read);
     if (n < 0) {
         if (errno == EINTR)
             return;
-        fprintf(port->errfile, "reading from vdagent virtio port: %s\n",
+        fprintf(vport->errfile, "reading from vdagent virtio port: %s\n",
                 strerror(errno));
     }
     if (n <= 0) {
-        vdagent_virtio_port_destroy(portp);
+        vdagent_virtio_port_destroy(vportp);
         return;
     }
 
-    if (port->chunk_header_read < sizeof(port->chunk_header)) {
-        port->chunk_header_read += n;
-        if (port->chunk_header_read == sizeof(port->chunk_header)) {
-            if (port->chunk_header.size > VD_AGENT_MAX_DATA_SIZE) {
-                fprintf(port->errfile, "chunk size too large\n");
-                vdagent_virtio_port_destroy(portp);
+    if (vport->chunk_header_read < sizeof(vport->chunk_header)) {
+        vport->chunk_header_read += n;
+        if (vport->chunk_header_read == sizeof(vport->chunk_header)) {
+            if (vport->chunk_header.size > VD_AGENT_MAX_DATA_SIZE) {
+                fprintf(vport->errfile, "chunk size too large\n");
+                vdagent_virtio_port_destroy(vportp);
                 return;
             }
         }
     } else {
-        port->chunk_data_pos += n;
-        if (port->chunk_data_pos == port->chunk_header.size) {
-            vdagent_virtio_port_do_chunk(portp);
-            port->chunk_header_read = 0;
-            port->chunk_data_pos = 0;
+        vport->chunk_data_pos += n;
+        if (vport->chunk_data_pos == vport->chunk_header.size) {
+            vdagent_virtio_port_do_chunk(vportp);
+            vport->chunk_header_read = 0;
+            vport->chunk_data_pos = 0;
         }
     }
 }
 
-static void vdagent_virtio_port_do_write(struct vdagent_virtio_port **portp)
+static void vdagent_virtio_port_do_write(struct vdagent_virtio_port **vportp)
 {
     ssize_t n;
     size_t to_write;
-    struct vdagent_virtio_port *port = *portp;
+    struct vdagent_virtio_port *vport = *vportp;
 
-    struct vdagent_virtio_port_buf* wbuf = port->write_buf;
+    struct vdagent_virtio_port_buf* wbuf = vport->write_buf;
     if (!wbuf) {
-        fprintf(port->errfile,
+        fprintf(vport->errfile,
                 "do_write called on a port without a write buf ?!\n");
         return;
     }
 
     to_write = wbuf->size - wbuf->pos;
-    n = write(port->fd, wbuf->buf + wbuf->pos, to_write);
+    n = write(vport->fd, wbuf->buf + wbuf->pos, to_write);
     if (n < 0) {
         if (errno == EINTR)
             return;
-        fprintf(port->errfile, "writing to vdagent virtio port: %s\n",
+        fprintf(vport->errfile, "writing to vdagent virtio port: %s\n",
                 strerror(errno));
-        vdagent_virtio_port_destroy(portp);
+        vdagent_virtio_port_destroy(vportp);
         return;
     }
 
     wbuf->pos += n;
     if (wbuf->pos == wbuf->size) {
-        port->write_buf = wbuf->next;
+        vport->write_buf = wbuf->next;
         free(wbuf->buf);
         free(wbuf);
     }
diff --git a/vdagent-virtio-port.h b/vdagent-virtio-port.h
index 4589700..1242e94 100644
--- a/vdagent-virtio-port.h
+++ b/vdagent-virtio-port.h
@@ -35,7 +35,7 @@ struct vdagent_virtio_port;
    to close the port can be indicated be returning -1 from the callback,
    in other cases return 0. */
 typedef int (*vdagent_virtio_port_read_callback)(
-    struct vdagent_virtio_port *port,
+    struct vdagent_virtio_port *vport,
     VDIChunkHeader *chunk_header,
     VDAgentMessage *message_header,
     uint8_t *data);
@@ -58,21 +58,21 @@ struct vdagent_virtio_port *vdagent_virtio_port_create(const char *portname,
     FILE *errfile);
     
 /* The contents of portp will be made NULL */
-void vdagent_virtio_port_destroy(struct vdagent_virtio_port **portp);
+void vdagent_virtio_port_destroy(struct vdagent_virtio_port **vportp);
 
 
 /* Given a vdagent_virtio_port fill the fd_sets pointed to by readfds and
    writefds for select() usage.
 
    Return value: value of the highest fd + 1 */
-int vdagent_virtio_port_fill_fds(struct vdagent_virtio_port *port,
+int vdagent_virtio_port_fill_fds(struct vdagent_virtio_port *vport,
         fd_set *readfds, fd_set *writefds);
 
 /* Handle any events flagged by select for the given vdagent_virtio_port.
    Note the port may be destroyed (when disconnected) by this call
    in this case the disconnect calllback will get called before the
    destruction and the contents of connp will be made NULL */
-void vdagent_virtio_port_handle_fds(struct vdagent_virtio_port **portp,
+void vdagent_virtio_port_handle_fds(struct vdagent_virtio_port **vportp,
         fd_set *readfds, fd_set *writefds);
 
 
@@ -80,13 +80,13 @@ void vdagent_virtio_port_handle_fds(struct vdagent_virtio_port **portp,
 
    Returns 0 on success -1 on error (only happens when malloc fails) */
 int vdagent_virtio_port_write(
-        struct vdagent_virtio_port *port,
+        struct vdagent_virtio_port *vport,
         uint32_t port_nr,
         uint32_t message_type,
         uint32_t message_opaque,
         const uint8_t *data,
         uint32_t data_size);
 
-void vdagent_virtio_port_flush(struct vdagent_virtio_port **portp);
+void vdagent_virtio_port_flush(struct vdagent_virtio_port **vportp);
 
 #endif
diff --git a/vdagentd.c b/vdagentd.c
index 9f9843a..8bc79e6 100644
--- a/vdagentd.c
+++ b/vdagentd.c
@@ -66,7 +66,7 @@ static int retval = 0;
 
 /* utility functions */
 /* vdagentd <-> spice-client communication handling */
-static void send_capabilities(struct vdagent_virtio_port *port,
+static void send_capabilities(struct vdagent_virtio_port *vport,
     uint32_t request)
 {
     VDAgentAnnounceCapabilities *caps;
@@ -86,13 +86,13 @@ static void send_capabilities(struct vdagent_virtio_port *port,
     VD_AGENT_SET_CAPABILITY(caps->caps, VD_AGENT_CAP_REPLY);
     VD_AGENT_SET_CAPABILITY(caps->caps, VD_AGENT_CAP_CLIPBOARD_BY_DEMAND);
 
-    vdagent_virtio_port_write(port, VDP_CLIENT_PORT,
+    vdagent_virtio_port_write(vport, VDP_CLIENT_PORT,
                               VD_AGENT_ANNOUNCE_CAPABILITIES, 0,
                               (uint8_t *)caps, size);
     free(caps);
 }
 
-static void do_client_monitors(struct vdagent_virtio_port *port, int port_nr,
+static void do_client_monitors(struct vdagent_virtio_port *vport, int port_nr,
     VDAgentMessage *message_header, VDAgentMonitorsConfig *new_monitors)
 {
     VDAgentReply reply;
@@ -124,11 +124,11 @@ static void do_client_monitors(struct vdagent_virtio_port *port, int port_nr,
     /* Acknowledge reception of monitors config to spice server / client */
     reply.type  = VD_AGENT_MONITORS_CONFIG;
     reply.error = VD_AGENT_SUCCESS;
-    vdagent_virtio_port_write(port, port_nr, VD_AGENT_REPLY, 0,
+    vdagent_virtio_port_write(vport, port_nr, VD_AGENT_REPLY, 0,
                               (uint8_t *)&reply, sizeof(reply));
 }
 
-static void do_client_capabilities(struct vdagent_virtio_port *port,
+static void do_client_capabilities(struct vdagent_virtio_port *vport,
     VDAgentMessage *message_header,
     VDAgentAnnounceCapabilities *caps)
 {
@@ -147,10 +147,10 @@ static void do_client_capabilities(struct vdagent_virtio_port *port,
     }
     memcpy(capabilities, caps->caps, capabilities_size * sizeof(uint32_t));
     if (caps->request)
-        send_capabilities(port, 0);
+        send_capabilities(vport, 0);
 }
 
-static void do_client_clipboard(struct vdagent_virtio_port *port,
+static void do_client_clipboard(struct vdagent_virtio_port *vport,
     VDAgentMessage *message_header, uint8_t *message_data)
 {
     uint32_t type = 0, opaque = 0, size = 0;
@@ -193,7 +193,7 @@ static void do_client_clipboard(struct vdagent_virtio_port *port,
 }
 
 int virtio_port_read_complete(
-        struct vdagent_virtio_port *port,
+        struct vdagent_virtio_port *vport,
         VDIChunkHeader *chunk_header,
         VDAgentMessage *message_header,
         uint8_t *data)
@@ -229,13 +229,13 @@ int virtio_port_read_complete(
     case VD_AGENT_MONITORS_CONFIG:
         if (message_header->size < sizeof(VDAgentMonitorsConfig))
             goto size_error;
-        do_client_monitors(port, chunk_header->port, message_header,
+        do_client_monitors(vport, chunk_header->port, message_header,
                     (VDAgentMonitorsConfig *)data);
         break;
     case VD_AGENT_ANNOUNCE_CAPABILITIES:
         if (message_header->size < sizeof(VDAgentAnnounceCapabilities))
             goto size_error;
-        do_client_capabilities(port, message_header,
+        do_client_capabilities(vport, message_header,
                         (VDAgentAnnounceCapabilities *)data);
         break;
     case VD_AGENT_CLIPBOARD_GRAB:
@@ -252,7 +252,7 @@ int virtio_port_read_complete(
         }
         if (message_header->size < min_size)
             goto size_error;
-        do_client_clipboard(port, message_header, data);
+        do_client_clipboard(vport, message_header, data);
         break;
     default:
         if (debug)
-- 
1.7.3.2



More information about the Spice-devel mailing list