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

[libvirt] [PATCH v2 04/32] Introduce virStreamHoleSize



This function is basically a counterpart for virStreamSkip. If
one side of a stream called virStreamSkip() the other should call
virStreamHoleSize() to get the size of the hole.

Signed-off-by: Michal Privoznik <mprivozn redhat com>
---
 include/libvirt/libvirt-stream.h |  3 +++
 src/driver-stream.h              |  5 +++++
 src/libvirt-stream.c             | 42 ++++++++++++++++++++++++++++++++++++++++
 src/libvirt_public.syms          |  1 +
 4 files changed, 51 insertions(+)

diff --git a/include/libvirt/libvirt-stream.h b/include/libvirt/libvirt-stream.h
index 4e0a599..2ebda74 100644
--- a/include/libvirt/libvirt-stream.h
+++ b/include/libvirt/libvirt-stream.h
@@ -53,6 +53,9 @@ int virStreamRecvFlags(virStreamPtr st,
 int virStreamSkip(virStreamPtr st,
                   unsigned long long length);
 
+int virStreamHoleSize(virStreamPtr,
+                      unsigned long long *length);
+
 
 /**
  * virStreamSourceFunc:
diff --git a/src/driver-stream.h b/src/driver-stream.h
index 20ea13f..e196b6d 100644
--- a/src/driver-stream.h
+++ b/src/driver-stream.h
@@ -46,6 +46,10 @@ typedef int
                     unsigned long long length);
 
 typedef int
+(*virDrvStreamHoleSize)(virStreamPtr st,
+                        unsigned long long *length);
+
+typedef int
 (*virDrvStreamEventAddCallback)(virStreamPtr stream,
                                 int events,
                                 virStreamEventCallback cb,
@@ -73,6 +77,7 @@ struct _virStreamDriver {
     virDrvStreamRecv streamRecv;
     virDrvStreamRecvFlags streamRecvFlags;
     virDrvStreamSkip streamSkip;
+    virDrvStreamHoleSize streamHoleSize;
     virDrvStreamEventAddCallback streamEventAddCallback;
     virDrvStreamEventUpdateCallback streamEventUpdateCallback;
     virDrvStreamEventRemoveCallback streamEventRemoveCallback;
diff --git a/src/libvirt-stream.c b/src/libvirt-stream.c
index 55f3ef5..3ac9e0d 100644
--- a/src/libvirt-stream.c
+++ b/src/libvirt-stream.c
@@ -403,6 +403,48 @@ virStreamSkip(virStreamPtr stream,
 
 
 /**
+ * virStreamHoleSize:
+ * @stream: pointer to the stream object
+ * @length: number of bytes to skip
+ *
+ * This function is a counterpart to virStreamSkip(). That is, if
+ * one side of a stream has called virStreamSkip() the other side
+ * of the stream should call virStreamHoleSize() to retrieve the
+ * size of hole. If there's currently no hole in the stream, -1
+ * is returned.
+ *
+ * Returns 0 on success,
+ *        -1 on error
+ */
+int
+virStreamHoleSize(virStreamPtr stream,
+                  unsigned long long *length)
+{
+    VIR_DEBUG("stream=%p, length=%p", stream, length);
+
+    virResetLastError();
+
+    virCheckStreamReturn(stream, -1);
+    virCheckNonNullArgReturn(length, -1);
+
+    if (stream->driver &&
+        stream->driver->streamHoleSize) {
+        int ret;
+        ret = (stream->driver->streamHoleSize)(stream, length);
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virReportUnsupportedError();
+
+ error:
+    virDispatchError(stream->conn);
+    return -1;
+}
+
+
+/**
  * virStreamSendAll:
  * @stream: pointer to the stream object
  * @handler: source callback for reading data from application
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index d781a5b..6d37ddb 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -734,6 +734,7 @@ LIBVIRT_1.3.3 {
 
 LIBVIRT_1.3.5 {
     global:
+        virStreamHoleSize;
         virStreamRecvFlags;
         virStreamSkip;
 } LIBVIRT_1.3.3;
-- 
2.8.3


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