File: libvirt-libvirt-stream.html

package info (click to toggle)
libvirt 3.0.0-4%2Bdeb9u4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 221,536 kB
  • sloc: ansic: 536,027; xml: 118,597; sh: 9,608; makefile: 5,399; perl: 3,888; python: 3,838; ml: 468; sed: 16
file content (151 lines) | stat: -rw-r--r-- 29,084 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!--
        This file is autogenerated from html/libvirt-libvirt-stream.html.in
        Do not edit this file. Changes will be lost.
      --><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><link rel="stylesheet" type="text/css" href="../main.css" /><link rel="SHORTCUT ICON" href="../32favicon.png" /><title>libvirt: Module libvirt-stream from libvirt</title><meta name="description" content="libvirt, virtualization, virtualization API" /></head><body><div id="body"><div id="content"><h1>Module libvirt-stream from libvirt</h1><p>Provides APIs for the management of streams</p><h2>Table of Contents</h2><h3><a href="#types">Types</a></h3><pre class="api"><span class="keyword">typedef</span> <span class="keyword">enum</span> <a href="#virStreamEventType">virStreamEventType</a>
<span class="keyword">typedef</span> <span class="keyword">enum</span> <a href="#virStreamFlags">virStreamFlags</a>
</pre><h3><a href="#functions">Functions</a></h3><pre class="api"><span class="type">int</span>	<a href="#virStreamAbort">virStreamAbort</a>			(<span class="type"><a href="libvirt-libvirt-host.html#virStreamPtr">virStreamPtr</a></span> stream)
<span class="type">int</span>	<a href="#virStreamEventAddCallback">virStreamEventAddCallback</a>	(<span class="type"><a href="libvirt-libvirt-host.html#virStreamPtr">virStreamPtr</a></span> stream, <br />					 <span class="type">int</span> events, <br />					 <span class="type"><a href="libvirt-libvirt-stream.html#virStreamEventCallback">virStreamEventCallback</a></span> cb, <br />					 <span class="type">void *</span> opaque, <br />					 <span class="type"><a href="libvirt-libvirt-common.html#virFreeCallback">virFreeCallback</a></span> ff)
<span class="keyword">typedef</span> <a href="#virStreamEventCallback">virStreamEventCallback</a>
<span class="type">void</span>	<a href="#virStreamEventCallback">virStreamEventCallback</a>		(<span class="type"><a href="libvirt-libvirt-host.html#virStreamPtr">virStreamPtr</a></span> stream, <br />					 <span class="type">int</span> events, <br />					 <span class="type">void *</span> opaque)

<span class="type">int</span>	<a href="#virStreamEventRemoveCallback">virStreamEventRemoveCallback</a>	(<span class="type"><a href="libvirt-libvirt-host.html#virStreamPtr">virStreamPtr</a></span> stream)
<span class="type">int</span>	<a href="#virStreamEventUpdateCallback">virStreamEventUpdateCallback</a>	(<span class="type"><a href="libvirt-libvirt-host.html#virStreamPtr">virStreamPtr</a></span> stream, <br />					 <span class="type">int</span> events)
<span class="type">int</span>	<a href="#virStreamFinish">virStreamFinish</a>			(<span class="type"><a href="libvirt-libvirt-host.html#virStreamPtr">virStreamPtr</a></span> stream)
<span class="type">int</span>	<a href="#virStreamFree">virStreamFree</a>			(<span class="type"><a href="libvirt-libvirt-host.html#virStreamPtr">virStreamPtr</a></span> stream)
<span class="type"><a href="libvirt-libvirt-host.html#virStreamPtr">virStreamPtr</a></span>	<a href="#virStreamNew">virStreamNew</a>		(<span class="type"><a href="libvirt-libvirt-host.html#virConnectPtr">virConnectPtr</a></span> conn, <br />					 <span class="type">unsigned int</span> flags)
<span class="type">int</span>	<a href="#virStreamRecv">virStreamRecv</a>			(<span class="type"><a href="libvirt-libvirt-host.html#virStreamPtr">virStreamPtr</a></span> stream, <br />					 <span class="type">char *</span> data, <br />					 <span class="type">size_t</span> nbytes)
<span class="type">int</span>	<a href="#virStreamRecvAll">virStreamRecvAll</a>		(<span class="type"><a href="libvirt-libvirt-host.html#virStreamPtr">virStreamPtr</a></span> stream, <br />					 <span class="type"><a href="libvirt-libvirt-stream.html#virStreamSinkFunc">virStreamSinkFunc</a></span> handler, <br />					 <span class="type">void *</span> opaque)
<span class="type">int</span>	<a href="#virStreamRef">virStreamRef</a>			(<span class="type"><a href="libvirt-libvirt-host.html#virStreamPtr">virStreamPtr</a></span> stream)
<span class="type">int</span>	<a href="#virStreamSend">virStreamSend</a>			(<span class="type"><a href="libvirt-libvirt-host.html#virStreamPtr">virStreamPtr</a></span> stream, <br />					 <span class="type">const char *</span> data, <br />					 <span class="type">size_t</span> nbytes)
<span class="type">int</span>	<a href="#virStreamSendAll">virStreamSendAll</a>		(<span class="type"><a href="libvirt-libvirt-host.html#virStreamPtr">virStreamPtr</a></span> stream, <br />					 <span class="type"><a href="libvirt-libvirt-stream.html#virStreamSourceFunc">virStreamSourceFunc</a></span> handler, <br />					 <span class="type">void *</span> opaque)
<span class="keyword">typedef</span> <a href="#virStreamSinkFunc">virStreamSinkFunc</a>
<span class="type">int</span>	<a href="#virStreamSinkFunc">virStreamSinkFunc</a>		(<span class="type"><a href="libvirt-libvirt-host.html#virStreamPtr">virStreamPtr</a></span> st, <br />					 <span class="type">const char *</span> data, <br />					 <span class="type">size_t</span> nbytes, <br />					 <span class="type">void *</span> opaque)

<span class="keyword">typedef</span> <a href="#virStreamSourceFunc">virStreamSourceFunc</a>
<span class="type">int</span>	<a href="#virStreamSourceFunc">virStreamSourceFunc</a>		(<span class="type"><a href="libvirt-libvirt-host.html#virStreamPtr">virStreamPtr</a></span> st, <br />					 <span class="type">char *</span> data, <br />					 <span class="type">size_t</span> nbytes, <br />					 <span class="type">void *</span> opaque)

</pre><h2>Description</h2><h3><a name="types" id="types">Types</a><a class="headerlink" href="#types" title="Permalink to this headline">¶</a></h3><h3><a name="virStreamEventType" id="virStreamEventType"><code>virStreamEventType</code></a><a class="headerlink" href="#virStreamEventType" title="Permalink to this headline">¶</a></h3><div class="api"><pre><span class="keyword">enum</span> virStreamEventType {
</pre><table><tr><td><a name="VIR_STREAM_EVENT_READABLE" id="VIR_STREAM_EVENT_READABLE">VIR_STREAM_EVENT_READABLE</a></td><td> = </td><td>1</td></tr><tr><td><a name="VIR_STREAM_EVENT_WRITABLE" id="VIR_STREAM_EVENT_WRITABLE">VIR_STREAM_EVENT_WRITABLE</a></td><td> = </td><td>2</td></tr><tr><td><a name="VIR_STREAM_EVENT_ERROR" id="VIR_STREAM_EVENT_ERROR">VIR_STREAM_EVENT_ERROR</a></td><td> = </td><td>4</td></tr><tr><td><a name="VIR_STREAM_EVENT_HANGUP" id="VIR_STREAM_EVENT_HANGUP">VIR_STREAM_EVENT_HANGUP</a></td><td> = </td><td>8</td></tr></table><pre>}
</pre></div><h3><a name="virStreamFlags" id="virStreamFlags"><code>virStreamFlags</code></a><a class="headerlink" href="#virStreamFlags" title="Permalink to this headline">¶</a></h3><div class="api"><pre><span class="keyword">enum</span> virStreamFlags {
</pre><table><tr><td><a name="VIR_STREAM_NONBLOCK" id="VIR_STREAM_NONBLOCK">VIR_STREAM_NONBLOCK</a></td><td> = </td><td>1</td></tr></table><pre>}
</pre></div><h3><a name="functions" id="functions">Functions</a><a class="headerlink" href="#functions" title="Permalink to this headline">¶</a></h3><h3><a name="virStreamAbort" id="virStreamAbort"><code>virStreamAbort</code></a><a class="headerlink" href="#virStreamAbort" title="Permalink to this headline">¶</a></h3><pre class="api"><span class="type">int</span>	virStreamAbort			(<span class="type"><a href="libvirt-libvirt-host.html#virStreamPtr">virStreamPtr</a></span> stream)</pre><div class="description"><p>Request that the in progress data transfer be cancelled abnormally before the end of the stream has been reached. For output streams this can be used to inform the driver that the stream is being terminated early. For input streams this can be used to inform the driver that it should stop sending data.</p></div><dl class="variablelist"><dt>stream</dt><dd>pointer to the stream object</dd><dt>Returns</dt><dd>0 on success, -1 upon error</dd></dl><div class="acl"></div><h3><a name="virStreamEventAddCallback" id="virStreamEventAddCallback"><code>virStreamEventAddCallback</code></a><a class="headerlink" href="#virStreamEventAddCallback" title="Permalink to this headline">¶</a></h3><pre class="api"><span class="type">int</span>	virStreamEventAddCallback	(<span class="type"><a href="libvirt-libvirt-host.html#virStreamPtr">virStreamPtr</a></span> stream,
					 <span class="type">int</span> events,
					 <span class="type"><a href="libvirt-libvirt-stream.html#virStreamEventCallback">virStreamEventCallback</a></span> cb,
					 <span class="type">void *</span> opaque,
					 <span class="type"><a href="libvirt-libvirt-common.html#virFreeCallback">virFreeCallback</a></span> ff)</pre><div class="description"><p>Register a callback to be notified when a stream becomes writable, or readable. This is most commonly used in conjunction with non-blocking data streams to integrate into an event loop</p></div><dl class="variablelist"><dt>stream</dt><dd>pointer to the stream object</dd><dt>events</dt><dd>set of events to monitor</dd><dt>cb</dt><dd>callback to invoke when an event occurs</dd><dt>opaque</dt><dd>application defined data</dd><dt>ff</dt><dd>callback to free @opaque data</dd><dt>Returns</dt><dd>0 on success, -1 upon error</dd></dl><div class="acl"></div><h3><a name="virStreamEventCallback" id="virStreamEventCallback"><code>virStreamEventCallback</code></a><a class="headerlink" href="#virStreamEventCallback" title="Permalink to this headline">¶</a></h3><pre class="api"><span class="keyword">typedef</span> <span class="type">void</span>	(*virStreamEventCallback	)	(<span class="type"><a href="libvirt-libvirt-host.html#virStreamPtr">virStreamPtr</a></span> stream,
					 <span class="type">int</span> events,
					 <span class="type">void *</span> opaque)
</pre><div class="description"><p>Callback for receiving stream events. The callback will be invoked once for each event which is pending.</p></div><dl class="variablelist"><dt>stream</dt><dd>stream on which the event occurred</dd><dt>events</dt><dd>bitset of events from <a href="libvirt-libvirt-event.html#virEventHandleType">virEventHandleType</a> constants</dd><dt>opaque</dt><dd>user data registered with handle</dd></dl><br /><h3><a name="virStreamEventRemoveCallback" id="virStreamEventRemoveCallback"><code>virStreamEventRemoveCallback</code></a><a class="headerlink" href="#virStreamEventRemoveCallback" title="Permalink to this headline">¶</a></h3><pre class="api"><span class="type">int</span>	virStreamEventRemoveCallback	(<span class="type"><a href="libvirt-libvirt-host.html#virStreamPtr">virStreamPtr</a></span> stream)</pre><div class="description"><p>Remove an event callback from the stream</p></div><dl class="variablelist"><dt>stream</dt><dd>pointer to the stream object</dd><dt>Returns</dt><dd>0 on success, -1 on error</dd></dl><div class="acl"></div><h3><a name="virStreamEventUpdateCallback" id="virStreamEventUpdateCallback"><code>virStreamEventUpdateCallback</code></a><a class="headerlink" href="#virStreamEventUpdateCallback" title="Permalink to this headline">¶</a></h3><pre class="api"><span class="type">int</span>	virStreamEventUpdateCallback	(<span class="type"><a href="libvirt-libvirt-host.html#virStreamPtr">virStreamPtr</a></span> stream,
					 <span class="type">int</span> events)</pre><div class="description"><p>Changes the set of events to monitor for a stream. This allows for event notification to be changed without having to unregister &amp; register the callback completely. This method is guaranteed to succeed if a callback is already registered</p></div><dl class="variablelist"><dt>stream</dt><dd>pointer to the stream object</dd><dt>events</dt><dd>set of events to monitor</dd><dt>Returns</dt><dd>0 on success, -1 if no callback is registered</dd></dl><div class="acl"></div><h3><a name="virStreamFinish" id="virStreamFinish"><code>virStreamFinish</code></a><a class="headerlink" href="#virStreamFinish" title="Permalink to this headline">¶</a></h3><pre class="api"><span class="type">int</span>	virStreamFinish			(<span class="type"><a href="libvirt-libvirt-host.html#virStreamPtr">virStreamPtr</a></span> stream)</pre><div class="description"><p>Indicate that there is no further data to be transmitted on the stream. For output streams this should be called once all data has been written. For input streams this should be called once <a href="libvirt-libvirt-stream.html#virStreamRecv">virStreamRecv</a> returns end-of-file.</p><p>This method is a synchronization point for all asynchronous errors, so if this returns a success code the application can be sure that all data has been successfully processed.</p></div><dl class="variablelist"><dt>stream</dt><dd>pointer to the stream object</dd><dt>Returns</dt><dd>0 on success, -1 upon error</dd></dl><div class="acl"></div><h3><a name="virStreamFree" id="virStreamFree"><code>virStreamFree</code></a><a class="headerlink" href="#virStreamFree" title="Permalink to this headline">¶</a></h3><pre class="api"><span class="type">int</span>	virStreamFree			(<span class="type"><a href="libvirt-libvirt-host.html#virStreamPtr">virStreamPtr</a></span> stream)</pre><div class="description"><p>Decrement the reference count on a stream, releasing the stream object if the reference count has hit zero.</p><p>There must not be an active data transfer in progress when releasing the stream. If a stream needs to be disposed of prior to end of stream being reached, then the <a href="libvirt-libvirt-stream.html#virStreamAbort">virStreamAbort</a> function should be called first.</p></div><dl class="variablelist"><dt>stream</dt><dd>pointer to the stream object</dd><dt>Returns</dt><dd>0 upon success, or -1 on error</dd></dl><div class="acl"></div><h3><a name="virStreamNew" id="virStreamNew"><code>virStreamNew</code></a><a class="headerlink" href="#virStreamNew" title="Permalink to this headline">¶</a></h3><pre class="api"><span class="type"><a href="libvirt-libvirt-host.html#virStreamPtr">virStreamPtr</a></span>	virStreamNew		(<span class="type"><a href="libvirt-libvirt-host.html#virConnectPtr">virConnectPtr</a></span> conn,
					 <span class="type">unsigned int</span> flags)</pre><div class="description"><p>Creates a new stream object which can be used to perform streamed I/O with other public API function.</p><p>When no longer needed, a stream object must be released with <a href="libvirt-libvirt-stream.html#virStreamFree">virStreamFree</a>. If a data stream has been used, then the application must call <a href="libvirt-libvirt-stream.html#virStreamFinish">virStreamFinish</a> or <a href="libvirt-libvirt-stream.html#virStreamAbort">virStreamAbort</a> before free'ing to, in order to notify the driver of termination.</p><p>If a non-blocking data stream is required passed <a href="libvirt-libvirt-stream.html#VIR_STREAM_NONBLOCK">VIR_STREAM_NONBLOCK</a> for flags, otherwise pass 0.</p></div><dl class="variablelist"><dt>conn</dt><dd>pointer to the connection</dd><dt>flags</dt><dd>bitwise-OR of <a href="libvirt-libvirt-stream.html#virStreamFlags">virStreamFlags</a></dd><dt>Returns</dt><dd>the new stream, or NULL upon error</dd></dl><div class="acl"></div><h3><a name="virStreamRecv" id="virStreamRecv"><code>virStreamRecv</code></a><a class="headerlink" href="#virStreamRecv" title="Permalink to this headline">¶</a></h3><pre class="api"><span class="type">int</span>	virStreamRecv			(<span class="type"><a href="libvirt-libvirt-host.html#virStreamPtr">virStreamPtr</a></span> stream,
					 <span class="type">char *</span> data,
					 <span class="type">size_t</span> nbytes)</pre><div class="description"><p>Reads a series of bytes from the stream. This method may block the calling application for an arbitrary amount of time.</p><p>Errors are not guaranteed to be reported synchronously with the call, but may instead be delayed until a subsequent call.</p><p>An example using this with a hypothetical file download API looks like</p><pre class="code">  virStreamPtr st = virStreamNew(conn, 0);
  int fd = open("demo.iso", O_WRONLY, 0600);

  virConnectDownloadFile(conn, "demo.iso", st);

  while (1) {
      char buf[1024];
      int got = virStreamRecv(st, buf, 1024);
      if (got &lt; 0)
         break;
      if (got == 0) {
         virStreamFinish(st);
         break;
      }
      int offset = 0;
      while (offset &lt; got) {
         int sent = write(fd, buf + offset, got - offset);
         if (sent &lt; 0) {
            virStreamAbort(st);
            goto done;
         }
         offset += sent;
      }
  }
  if (virStreamFinish(st) &lt; 0)
     ... report an error ....
done:
  virStreamFree(st);
  close(fd);</pre></div><dl class="variablelist"><dt>stream</dt><dd>pointer to the stream object</dd><dt>data</dt><dd>buffer to read into from stream</dd><dt>nbytes</dt><dd>size of @data buffer</dd><dt>Returns</dt><dd>the number of bytes read, which may be less than requested. Returns 0 when the end of the stream is reached, at which time the caller should invoke <a href="libvirt-libvirt-stream.html#virStreamFinish">virStreamFinish</a>() to get confirmation of stream completion. Returns -1 upon error, at which time the stream will be marked as aborted, and the caller should now release the stream with <a href="libvirt-libvirt-stream.html#virStreamFree">virStreamFree</a>. Returns -2 if there is no data pending to be read &amp; the stream is marked as non-blocking.</dd></dl><div class="acl"></div><h3><a name="virStreamRecvAll" id="virStreamRecvAll"><code>virStreamRecvAll</code></a><a class="headerlink" href="#virStreamRecvAll" title="Permalink to this headline">¶</a></h3><pre class="api"><span class="type">int</span>	virStreamRecvAll		(<span class="type"><a href="libvirt-libvirt-host.html#virStreamPtr">virStreamPtr</a></span> stream,
					 <span class="type"><a href="libvirt-libvirt-stream.html#virStreamSinkFunc">virStreamSinkFunc</a></span> handler,
					 <span class="type">void *</span> opaque)</pre><div class="description"><p>Receive the entire data stream, sending the data to the requested data sink. This is simply a convenient alternative to <a href="libvirt-libvirt-stream.html#virStreamRecv">virStreamRecv</a>, for apps that do blocking-I/O.</p><p>An example using this with a hypothetical file download API looks like</p><pre class="code">int mysink(virStreamPtr st, const char *buf, int nbytes, void *opaque) {
    int *fd = opaque;

    return write(*fd, buf, nbytes);
}

virStreamPtr st = virStreamNew(conn, 0);
int fd = open("demo.iso", O_WRONLY);

virConnectUploadFile(conn, st);
if (virStreamRecvAll(st, mysink, &amp;fd) &lt; 0) {
   ...report an error ...
   goto done;
}
if (virStreamFinish(st) &lt; 0)
   ...report an error...
virStreamFree(st);
close(fd);</pre></div><dl class="variablelist"><dt>stream</dt><dd>pointer to the stream object</dd><dt>handler</dt><dd>sink callback for writing data to application</dd><dt>opaque</dt><dd>application defined data</dd><dt>Returns</dt><dd>0 if all the data was successfully received. The caller should invoke virStreamFinish(st) to flush the stream upon success and then <a href="libvirt-libvirt-stream.html#virStreamFree">virStreamFree</a> Returns -1 upon any error, with <a href="libvirt-libvirt-stream.html#virStreamAbort">virStreamAbort</a>() already having been called, so the caller need only call <a href="libvirt-libvirt-stream.html#virStreamFree">virStreamFree</a>()</dd></dl><div class="acl"></div><h3><a name="virStreamRef" id="virStreamRef"><code>virStreamRef</code></a><a class="headerlink" href="#virStreamRef" title="Permalink to this headline">¶</a></h3><pre class="api"><span class="type">int</span>	virStreamRef			(<span class="type"><a href="libvirt-libvirt-host.html#virStreamPtr">virStreamPtr</a></span> stream)</pre><div class="description"><p>Increment the reference count on the stream. For each additional call to this method, there shall be a corresponding call to <a href="libvirt-libvirt-stream.html#virStreamFree">virStreamFree</a> to release the reference count, once the caller no longer needs the reference to this object.</p></div><dl class="variablelist"><dt>stream</dt><dd>pointer to the stream</dd><dt>Returns</dt><dd>0 in case of success, -1 in case of failure</dd></dl><div class="acl"></div><h3><a name="virStreamSend" id="virStreamSend"><code>virStreamSend</code></a><a class="headerlink" href="#virStreamSend" title="Permalink to this headline">¶</a></h3><pre class="api"><span class="type">int</span>	virStreamSend			(<span class="type"><a href="libvirt-libvirt-host.html#virStreamPtr">virStreamPtr</a></span> stream,
					 <span class="type">const char *</span> data,
					 <span class="type">size_t</span> nbytes)</pre><div class="description"><p>Write a series of bytes to the stream. This method may block the calling application for an arbitrary amount of time. Once an application has finished sending data it should call <a href="libvirt-libvirt-stream.html#virStreamFinish">virStreamFinish</a> to wait for successful confirmation from the driver, or detect any error.</p><p>This method may not be used if a stream source has been registered.</p><p>Errors are not guaranteed to be reported synchronously with the call, but may instead be delayed until a subsequent call.</p><p>An example using this with a hypothetical file upload API looks like</p><pre class="code">  virStreamPtr st = virStreamNew(conn, 0);
  int fd = open("demo.iso", O_RDONLY);

  virConnectUploadFile(conn, "demo.iso", st);

  while (1) {
       char buf[1024];
       int got = read(fd, buf, 1024);
       if (got &lt; 0) {
          virStreamAbort(st);
          break;
       }
       if (got == 0) {
          virStreamFinish(st);
          break;
       }
       int offset = 0;
       while (offset &lt; got) {
          int sent = virStreamSend(st, buf+offset, got-offset);
          if (sent &lt; 0) {
             virStreamAbort(st);
             goto done;
          }
          offset += sent;
       }
   }
   if (virStreamFinish(st) &lt; 0)
      ... report an error ....
 done:
   virStreamFree(st);
   close(fd);</pre></div><dl class="variablelist"><dt>stream</dt><dd>pointer to the stream object</dd><dt>data</dt><dd>buffer to write to stream</dd><dt>nbytes</dt><dd>size of @data buffer</dd><dt>Returns</dt><dd>the number of bytes written, which may be less than requested. Returns -1 upon error, at which time the stream will be marked as aborted, and the caller should now release the stream with <a href="libvirt-libvirt-stream.html#virStreamFree">virStreamFree</a>. Returns -2 if the outgoing transmit buffers are full &amp; the stream is marked as non-blocking.</dd></dl><div class="acl"></div><h3><a name="virStreamSendAll" id="virStreamSendAll"><code>virStreamSendAll</code></a><a class="headerlink" href="#virStreamSendAll" title="Permalink to this headline">¶</a></h3><pre class="api"><span class="type">int</span>	virStreamSendAll		(<span class="type"><a href="libvirt-libvirt-host.html#virStreamPtr">virStreamPtr</a></span> stream,
					 <span class="type"><a href="libvirt-libvirt-stream.html#virStreamSourceFunc">virStreamSourceFunc</a></span> handler,
					 <span class="type">void *</span> opaque)</pre><div class="description"><p>Send the entire data stream, reading the data from the requested data source. This is simply a convenient alternative to <a href="libvirt-libvirt-stream.html#virStreamSend">virStreamSend</a>, for apps that do blocking-I/O.</p><p>An example using this with a hypothetical file upload API looks like</p><pre class="code">int mysource(virStreamPtr st, char *buf, int nbytes, void *opaque) {
    int *fd = opaque;

    return read(*fd, buf, nbytes);
}

virStreamPtr st = virStreamNew(conn, 0);
int fd = open("demo.iso", O_RDONLY);

virConnectUploadFile(conn, st);
if (virStreamSendAll(st, mysource, &amp;fd) &lt; 0) {
   ...report an error ...
   goto done;
}
if (virStreamFinish(st) &lt; 0)
   ...report an error...
virStreamFree(st);
close(fd);</pre></div><dl class="variablelist"><dt>stream</dt><dd>pointer to the stream object</dd><dt>handler</dt><dd>source callback for reading data from application</dd><dt>opaque</dt><dd>application defined data</dd><dt>Returns</dt><dd>0 if all the data was successfully sent. The caller should invoke virStreamFinish(st) to flush the stream upon success and then <a href="libvirt-libvirt-stream.html#virStreamFree">virStreamFree</a> Returns -1 upon any error, with <a href="libvirt-libvirt-stream.html#virStreamAbort">virStreamAbort</a>() already having been called, so the caller need only call <a href="libvirt-libvirt-stream.html#virStreamFree">virStreamFree</a>()</dd></dl><div class="acl"></div><h3><a name="virStreamSinkFunc" id="virStreamSinkFunc"><code>virStreamSinkFunc</code></a><a class="headerlink" href="#virStreamSinkFunc" title="Permalink to this headline">¶</a></h3><pre class="api"><span class="keyword">typedef</span> <span class="type">int</span>	(*virStreamSinkFunc	)	(<span class="type"><a href="libvirt-libvirt-host.html#virStreamPtr">virStreamPtr</a></span> st,
					 <span class="type">const char *</span> data,
					 <span class="type">size_t</span> nbytes,
					 <span class="type">void *</span> opaque)
</pre><div class="description"><p>The <a href="libvirt-libvirt-stream.html#virStreamSinkFunc">virStreamSinkFunc</a> callback is used together with the <a href="libvirt-libvirt-stream.html#virStreamRecvAll">virStreamRecvAll</a> function for libvirt to provide the data that has been received.</p><p>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</p></div><dl class="variablelist"><dt>st</dt><dd>the stream object</dd><dt>data</dt><dd>preallocated array to be filled with data</dd><dt>nbytes</dt><dd>size of the data array</dd><dt>opaque</dt><dd>optional application provided data</dd><dt>Returns</dt><dd>the number of bytes consumed or -1 upon error</dd></dl><br /><h3><a name="virStreamSourceFunc" id="virStreamSourceFunc"><code>virStreamSourceFunc</code></a><a class="headerlink" href="#virStreamSourceFunc" title="Permalink to this headline">¶</a></h3><pre class="api"><span class="keyword">typedef</span> <span class="type">int</span>	(*virStreamSourceFunc	)	(<span class="type"><a href="libvirt-libvirt-host.html#virStreamPtr">virStreamPtr</a></span> st,
					 <span class="type">char *</span> data,
					 <span class="type">size_t</span> nbytes,
					 <span class="type">void *</span> opaque)
</pre><div class="description"><p>The <a href="libvirt-libvirt-stream.html#virStreamSourceFunc">virStreamSourceFunc</a> callback is used together with the <a href="libvirt-libvirt-stream.html#virStreamSendAll">virStreamSendAll</a> function for libvirt to obtain the data that is to be sent.</p><p>The callback will be invoked multiple times, fetching data in small chunks. The application should fill the 'data' array with up to 'nbytes' of data and then return the number actual number of bytes. The callback will continue to be invoked until it indicates the end of the source has been reached by returning 0. A return value of -1 at any time will abort the send operation</p></div><dl class="variablelist"><dt>st</dt><dd>the stream object</dd><dt>data</dt><dd>preallocated array to be filled with data</dd><dt>nbytes</dt><dd>size of the data array</dd><dt>opaque</dt><dd>optional application provided data</dd><dt>Returns</dt><dd>the number of bytes filled, 0 upon end of file, or -1 upon error</dd></dl><br /></div></div><div id="nav"><div id="home"><a href="../index.html">Home</a></div><div id="jumplinks"><ul><li><a href="../downloads.html">Download</a></li><li><a href="../contribute.html">Contribute</a></li><li><a href="../docs.html">Learn</a></li></ul></div><div id="search"><form action="../search.php" enctype="application/x-www-form-urlencoded" method="get"><div><input name="query" type="text" size="12" value="" /><input name="submit" type="submit" value="Go" /></div></form></div></div><div id="footer"><div id="contact"><h3>Contact</h3><ul><li><a href="../contact.html#email">email</a></li><li><a href="../contact.html#irc">irc</a></li></ul></div><div id="community"><h3>Community</h3><ul><li><a href="https://twitter.com/hashtag/libvirt">twitter</a></li><li><a href="https://plus.google.com/communities/109522598353007505282">google+</a></li><li><a href="http://stackoverflow.com/questions/tagged/libvirt">stackoverflow</a></li><li><a href="http://serverfault.com/questions/tagged/libvirt">serverfault</a></li></ul></div><div id="conduct">
            Participants in the libvirt project agree to abide by <a href="../governance.html#codeofconduct">the project code of conduct</a></div><br class="clear" /></div></body></html>