All pastes #1228030 Raw Edit

Untitled

public text v1 · immutable
#1228030 ·published 2008-10-15 17:57 UTC
rendered paste body
diff --git a/hw/hw.h b/hw/hw.h
index 8edd788..99d4b8d 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -34,7 +34,7 @@ QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer,
                          QEMUFileCloseFunc *close,
                          QEMUFileRateLimit *rate_limit);
 QEMUFile *qemu_fopen(const char *filename, const char *mode);
-QEMUFile *qemu_fopen_fd(int fd);
+QEMUFile *qemu_fopen_socket(int fd);
 void qemu_fflush(QEMUFile *f);
 int qemu_fclose(QEMUFile *f);
 void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size);
diff --git a/migration-tcp.c b/migration-tcp.c
index df8080f..1c1b248 100644
--- a/migration-tcp.c
+++ b/migration-tcp.c
@@ -84,11 +84,11 @@ static ssize_t fd_put_buffer(void *opaque, const void *data, size_t size)
     ssize_t ret;
 
     do {
-        ret = write(s->fd, data, size);
+        ret = send(s->fd, data, size, 0);
     } while (ret == -1 && errno == EINTR);
 
     if (ret == -1)
-        ret = -errno;
+        ret = -socket_error();
 
     if (ret == -EAGAIN)
         qemu_set_fd_handler2(s->fd, NULL, NULL, fd_put_notify, s);
@@ -262,7 +262,7 @@ MigrationState *tcp_start_outgoing_migration(const char *host_port,
 	return NULL;
     }
 
-    fcntl(s->fd, F_SETFL, O_NONBLOCK);
+    socket_set_nonblock(s->fd);
 
     if (s->detach == 1) {
         dprintf("detaching from monitor\n");
@@ -309,7 +309,7 @@ static void tcp_accept_incoming_migration(void *opaque)
         return;
     }
 
-    f = qemu_fopen_fd(c);
+    f = qemu_fopen_socket(c);
     if (f == NULL) {
         fprintf(stderr, "could not qemu_fopen socket\n");
         goto out;
diff --git a/vl.c b/vl.c
index c0e43ac..1fb4749 100644
--- a/vl.c
+++ b/vl.c
@@ -6224,9 +6224,8 @@ void qemu_announce_self(void)
         len = announce_self_create(buf, nd_table[i].macaddr);
         vlan = nd_table[i].vlan;
         for(vc = vlan->first_client; vc != NULL; vc = vc->next) {
-            if (vc->fd_read == tap_receive)  /* send only if tap */
-                for (j=0; j < SELF_ANNOUNCE_ROUNDS; j++)
-                    vc->fd_read(vc->opaque, buf, len);
+            for (j=0; j < SELF_ANNOUNCE_ROUNDS; j++)
+                vc->fd_read(vc->opaque, buf, len);
         }
     }
 }
@@ -6253,43 +6252,43 @@ struct QEMUFile {
     int has_error;
 };
 
-typedef struct QEMUFileFD
+typedef struct QEMUFileSocket
 {
     int fd;
     QEMUFile *file;
-} QEMUFileFD;
+} QEMUFileSocket;
 
-static int fd_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
+static int socket_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
 {
-    QEMUFileFD *s = opaque;
+    QEMUFileSocket *s = opaque;
     ssize_t len;
 
     do {
-        len = read(s->fd, buf, size);
-    } while (len == -1 && errno == EINTR);
+        len = recv(s->fd, buf, size, 0);
+    } while (len == -1 && socket_error() == EINTR);
 
     if (len == -1)
-        len = -errno;
+        len = -socket_error();
 
     return len;
 }
 
-static int fd_close(void *opaque)
+static int socket_close(void *opaque)
 {
-    QEMUFileFD *s = opaque;
+    QEMUFileSocket *s = opaque;
     qemu_free(s);
     return 0;
 }
 
-QEMUFile *qemu_fopen_fd(int fd)
+QEMUFile *qemu_fopen_socket(int fd)
 {
-    QEMUFileFD *s = qemu_mallocz(sizeof(QEMUFileFD));
+    QEMUFileSocket *s = qemu_mallocz(sizeof(QEMUFileSocket));
 
     if (s == NULL)
         return NULL;
 
     s->fd = fd;
-    s->file = qemu_fopen_ops(s, NULL, fd_get_buffer, fd_close, NULL);
+    s->file = qemu_fopen_ops(s, NULL, socket_get_buffer, socket_close, NULL);
     return s->file;
 }