[Libguestfs] [PATCH libnbd discussion only 3/5] lib: Pass handle to socket recv and send calls.

Richard W.M. Jones rjones at redhat.com
Mon Jun 3 15:29:46 UTC 2019


Just a simple refactoring in preparation for forthcoming work.
---
 generator/states-reply.c | 2 +-
 generator/states.c       | 4 ++--
 lib/crypto.c             | 5 +++--
 lib/internal.h           | 6 ++++--
 lib/socket.c             | 5 +++--
 5 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/generator/states-reply.c b/generator/states-reply.c
index 5be3431..f0ef47c 100644
--- a/generator/states-reply.c
+++ b/generator/states-reply.c
@@ -36,7 +36,7 @@
   h->rbuf = &h->sbuf;
   h->rlen = sizeof h->sbuf.simple_reply;
 
-  r = h->sock->ops->recv (h->sock, h->rbuf, h->rlen);
+  r = h->sock->ops->recv (h, h->sock, h->rbuf, h->rlen);
   if (r == -1) {
     /* This should never happen because when we enter this state we
      * should have notification that the socket is ready to read.
diff --git a/generator/states.c b/generator/states.c
index 834fa44..bce4f85 100644
--- a/generator/states.c
+++ b/generator/states.c
@@ -61,7 +61,7 @@ recv_into_rbuf (struct nbd_handle *h)
     rlen = h->rlen > sizeof buf ? sizeof buf : h->rlen;
   }
 
-  r = h->sock->ops->recv (h->sock, rbuf, rlen);
+  r = h->sock->ops->recv (h, h->sock, rbuf, rlen);
   if (r == -1) {
     if (errno == EAGAIN || errno == EWOULDBLOCK)
       return 1;                 /* more data */
@@ -92,7 +92,7 @@ send_from_wbuf (struct nbd_handle *h)
 
   if (h->wlen == 0)
     return 0;                   /* move to next state */
-  r = h->sock->ops->send (h->sock, h->wbuf, h->wlen);
+  r = h->sock->ops->send (h, h->sock, h->wbuf, h->wlen);
   if (r == -1) {
     if (errno == EAGAIN || errno == EWOULDBLOCK)
       return 1;                 /* more data */
diff --git a/lib/crypto.c b/lib/crypto.c
index c437788..aba2e27 100644
--- a/lib/crypto.c
+++ b/lib/crypto.c
@@ -145,7 +145,7 @@ nbd_unlocked_set_tls_psk_file (struct nbd_handle *h, const char *filename)
 #ifdef HAVE_GNUTLS
 
 static ssize_t
-tls_recv (struct socket *sock, void *buf, size_t len)
+tls_recv (struct nbd_handle *h, struct socket *sock, void *buf, size_t len)
 {
   ssize_t r;
 
@@ -163,7 +163,8 @@ tls_recv (struct socket *sock, void *buf, size_t len)
 }
 
 static ssize_t
-tls_send (struct socket *sock, const void *buf, size_t len)
+tls_send (struct nbd_handle *h,
+          struct socket *sock, const void *buf, size_t len)
 {
   ssize_t r;
 
diff --git a/lib/internal.h b/lib/internal.h
index 73cb3f9..c8e5094 100644
--- a/lib/internal.h
+++ b/lib/internal.h
@@ -188,8 +188,10 @@ struct close_callback {
 };
 
 struct socket_ops {
-  ssize_t (*recv) (struct socket *sock, void *buf, size_t len);
-  ssize_t (*send) (struct socket *sock, const void *buf, size_t len);
+  ssize_t (*recv) (struct nbd_handle *h,
+                   struct socket *sock, void *buf, size_t len);
+  ssize_t (*send) (struct nbd_handle *h,
+                   struct socket *sock, const void *buf, size_t len);
   int (*get_fd) (struct socket *sock);
   int (*close) (struct socket *sock);
 };
diff --git a/lib/socket.c b/lib/socket.c
index df933be..f48e455 100644
--- a/lib/socket.c
+++ b/lib/socket.c
@@ -30,7 +30,7 @@
 #include "internal.h"
 
 static ssize_t
-socket_recv (struct socket *sock, void *buf, size_t len)
+socket_recv (struct nbd_handle *h, struct socket *sock, void *buf, size_t len)
 {
   ssize_t r;
 
@@ -41,7 +41,8 @@ socket_recv (struct socket *sock, void *buf, size_t len)
 }
 
 static ssize_t
-socket_send (struct socket *sock, const void *buf, size_t len)
+socket_send (struct nbd_handle *h,
+             struct socket *sock, const void *buf, size_t len)
 {
   ssize_t r;
 
-- 
2.21.0




More information about the Libguestfs mailing list