[libvirt-perl][PATCH 2/7] Introduce flags to Stream::recv()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At the same time register RECV_STOP_AT_HOLE constant.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 Changes                |  2 ++
 Virt.xs                | 13 ++++++++++---
 lib/Sys/Virt/Stream.pm | 20 ++++++++++++++++----
 3 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/Changes b/Changes
index 2e4a99e..b4a493c 100644
--- a/Changes
+++ b/Changes
@@ -4,6 +4,8 @@ Revision history for perl module Sys::Virt
 
  - Add LIST_CAP_MDEV & LIST_CAP_MDEV_TYPES constants
  - Fix send_all() callback helper
+ - Introduce flags to Stream::recv() and
+   register RECV_STOP_AT_HOLE constant
 
 3.3.0 2017-05-08
 
diff --git a/Virt.xs b/Virt.xs
index a041c95..498e711 100644
--- a/Virt.xs
+++ b/Virt.xs
@@ -7874,16 +7874,21 @@ send(st, data, nbytes)
 
 
 int
-recv(st, data, nbytes)
+recv(st, data, nbytes, flags=0)
       virStreamPtr st;
       SV *data;
       size_t nbytes;
+      unsigned int flags;
  PREINIT:
       char *rawdata;
     CODE:
       Newx(rawdata, nbytes, char);
-      if ((RETVAL = virStreamRecv(st, rawdata, nbytes)) < 0 &&
-          RETVAL != -2) {
+      if (flags)
+          RETVAL = virStreamRecvFlags(st, rawdata, nbytes, flags);
+      else
+          RETVAL = virStreamRecv(st, rawdata, nbytes);
+
+      if (RETVAL != -2 && RETVAL != -3) {
           Safefree(rawdata);
           _croak_error();
       }
@@ -9010,6 +9015,8 @@ BOOT:
       REGISTER_CONSTANT(VIR_STREAM_EVENT_ERROR, EVENT_ERROR);
       REGISTER_CONSTANT(VIR_STREAM_EVENT_HANGUP, EVENT_HANGUP);
 
+      REGISTER_CONSTANT(VIR_STREAM_RECV_STOP_AT_HOLE, RECV_STOP_AT_HOLE);
+
 
 
       stash = gv_stashpv( "Sys::Virt::Error", TRUE );
diff --git a/lib/Sys/Virt/Stream.pm b/lib/Sys/Virt/Stream.pm
index 4022c84..069895e 100644
--- a/lib/Sys/Virt/Stream.pm
+++ b/lib/Sys/Virt/Stream.pm
@@ -69,11 +69,23 @@ be called on any stream which has been activated
 Complete I/O on the stream. Either this function or C<abort> must
 be called on any stream which has been activated
 
-=item $rv = $st->recv($data, $nbytes)
+=item $rv = $st->recv($data, $nbytes, $flags=0)
 
-Receive upto C<$nbytes> worth of data, copying into C<$data>.
-Returns the number of bytes read, or -2 if I/O would block,
-or -1 on error.
+Receive up to C<$nbytes> worth of data, copying into C<$data>.
+Returns the number of bytes read, or -3 if hole is reached and
+C<$flags> contains RECV_STOP_AT_HOLE, or -2 if I/O would block,
+or -1 on error. The C<$flags> parameter accepts the following
+flags:
+
+=over 4
+
+=item Sys::Virt::Stream::RECV_STOP_AT_HOLE
+
+If this flag is set, the C<recv> function will stop reading from
+stream if it has reached a hole. In that case, -3 is returned and
+C<recvHole> should be called to get the hole size.
+
+=back
 
 =item $rv = $st->send($data, $nbytes)
 
-- 
2.13.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux