[PATCH]: Add another portion virStream bindings (C# bindings, libvirt-csharp.git)

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

 



From 13d3e161d94c02bd9b5803f23399c8dc90dac3b1 Mon Sep 17 00:00:00 2001
From: Anton Podavalov <a.podavalov@xxxxxxxxx>
Date: Thu, 14 Jul 2011 18:08:44 +0400
Subject: [PATCH] Add another portion of virStream bindings
 Recv, RecvAll, Ref.

---
 Stream.cs |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------
 Types.cs  |   15 +++++++++++++++
 2 files changed, 69 insertions(+), 6 deletions(-)

diff --git a/Stream.cs b/Stream.cs
index 428df90..b349605 100644
--- a/Stream.cs
+++ b/Stream.cs
@@ -94,12 +94,60 @@ namespace Libvirt
 		/// <returns>the new stream, or NULL upon error</returns>
 		[DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virStreamNew")]
 		public static extern int New(IntPtr conn, uint flags);
-
-        // TODO virStreamRecv
-
-        // TODO virStreamRecvAll
-
-        // TODO virStreamRef
+		/// <summary>
+		/// Reads a series of bytes from the stream. This method may block the calling application
+		/// for an arbitrary amount of time. Errors are not guaranteed to be reported synchronously
+		/// with the call, but may instead be delayed until a subsequent call.
+		/// </summary>
+		/// <param name="stream">
+		/// pointer to the stream object
+		/// </param>
+		/// <param name="data">
+		/// buffer to read into from stream
+		/// </param>
+		/// <param name="size">
+		/// size of @data buffer
+		/// </param>
+		/// <returns>
+		/// completion. Returns -1 upon error, at which time the stream will be marked as aborted,
+		/// and the caller should now release the stream with virStreamFree. Returns -2 if there is no
+		/// data pending to be read & the stream is marked as non-blocking.
+		/// </returns>
+		[DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virStreamRecv")]
+		public static extern int Recv(IntPtr stream, IntPtr data, int size);
+		/// <summary>
+		/// Receive the entire data stream, sending the data to the requested data sink. This is simply a
+		/// convenient alternative to virStreamRecv, for apps that do blocking-I/O.
+		/// </summary>
+		/// <param name="stream">
+		/// pointer to the stream object
+		/// </param>
+		/// <param name="handler">
+		/// sink callback for writing data to application
+		/// </param>
+		/// <param name="opaque">
+		/// application defined data
+		/// </param>
+		/// <returns>
+		/// 0 if all the data was successfully received. The caller should invoke virStreamFinish(st) to flush
+		/// the stream upon success and then virStreamFree Returns -1 upon any error, with virStreamAbort()
+		/// already having been called, so the caller need only call virStreamFree()
+		/// </returns>
+		[DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virStreamRecvAll")]
+		public static extern int RecvAll(IntPtr stream, [MarshalAs(UnmanagedType.FunctionPtr)] StreamSinkFunc handler, IntPtr opaque);
+		/// <summary>
+		/// Increment the reference count on the stream. For each additional call to this method, there shall be a
+		/// corresponding call to virStreamFree to release the reference count, once the caller no longer needs
+		/// the reference to this object.
+		/// </summary>
+		/// <param name="stream">
+		/// pointer to the stream
+		/// </param>
+		/// <returns>
+		/// 0 in case of success, -1 in case of failure
+		/// </returns>
+		[DllImport("libvirt-0.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "virStreamRef")]
+		public static extern int Ref(IntPtr stream);
 
         // TODO virStreamSend
 
diff --git a/Types.cs b/Types.cs
index 67ea002..46c1d7e 100644
--- a/Types.cs
+++ b/Types.cs
@@ -126,6 +126,21 @@ namespace Libvirt
 	/// <param name="opaque">user data registered with handle</param>
 	[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
 	public delegate void StreamEventCallback(IntPtr stream, int events, IntPtr opaque);
+	/// <summary>
+	/// The virStreamSinkFunc callback is used together with the virStreamRecvAll function for libvirt
+	/// to provide the data that has been received. The callback will be invoked multiple times, providing
+	/// data in small chunks. The application should consume up 'nbytes' from the 'data' array of data and
+	/// then return the number actual number of bytes consumed. The callback will continue to be invoked until
+	/// it indicates the end of the stream has been reached. A return value of -1 at any time will abort the
+	/// receive operation
+	/// </summary>
+	/// <param name="st">the stream object</param>
+	/// <param name="data">preallocated array to be filled with data</param>
+	/// <param name="nbytes">size of the data array</param>
+	/// <param name="opaque">optional application provided data</param>
+	/// <returns>the number of bytes filled, 0 upon end of file, or -1 upon error</returns>
+	[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+	public delegate int StreamSinkFunc(IntPtr st, IntPtr data, int nbytes, IntPtr opaque);
     #endregion
 
     #region structs
-- 
1.7.4.1

--
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]