4 libvirtmod
.virStreamEventRemoveCallback(self
._o
)
9 libvirtmod
.virStreamFree(self
._o
)
12 def _dispatchStreamEventCallback(self
, events
, cbData
):
14 Dispatches events to python user's stream event callbacks
17 opaque
= cbData
["opaque"]
19 cb(self
, events
, opaque
)
22 def eventAddCallback(self
, events
, cb
, opaque
):
24 cbData
= {"stream": self
, "cb" : cb
, "opaque" : opaque
}
25 ret
= libvirtmod
.virStreamEventAddCallback(self
._o
, events
, cbData
)
26 if ret
== -1: raise libvirtError ('virStreamEventAddCallback() failed')
28 def recvAll(self
, handler
, opaque
):
29 """Receive the entire data stream, sending the data to the
30 requested data sink. This is simply a convenient alternative
31 to virStreamRecv, for apps that do blocking-I/o.
33 A hypothetical handler function looks like:
35 def handler(stream, # virStream instance
36 buf, # string containing received data
37 opaque): # extra data passed to recvAll as opaque
39 return os.write(fd, buf)
42 got
= self
.recv(1024*64)
44 raise libvirtError("cannot use recvAll with "
50 ret
= handler(self
, got
, opaque
)
51 if type(ret
) is int and ret
< 0:
52 raise RuntimeError("recvAll handler returned %d" % ret
)
60 def sendAll(self
, handler
, opaque
):
62 Send the entire data stream, reading the data from the
63 requested data source. This is simply a convenient alternative
64 to virStreamSend, for apps that do blocking-I/o.
66 A hypothetical handler function looks like:
68 def handler(stream, # virStream instance
69 nbytes, # int amt of data to read
70 opaque): # extra data passed to recvAll as opaque
72 return os.read(fd, nbytes)
76 got
= handler(self
, 1024*64, opaque
)
89 raise libvirtError("cannot use recvAll with "
92 def recv(self
, nbytes
):
93 """Write a series of bytes to the stream. This method may
94 block the calling application for an arbitrary amount
97 Errors are not guaranteed to be reported synchronously
98 with the call, but may instead be delayed until a
101 On success, the received data is returned. On failure, an
102 exception is raised. If the stream is a NONBLOCK stream and
103 the request would block, integer -2 is returned.
105 ret
= libvirtmod
.virStreamRecv(self
._o
, nbytes
)
106 if ret
== None: raise libvirtError ('virStreamRecv() failed')
109 def send(self
, data
):
110 """Write a series of bytes to the stream. This method may
111 block the calling application for an arbitrary amount
112 of time. Once an application has finished sending data
113 it should call virStreamFinish to wait for successful
114 confirmation from the driver, or detect any error
116 This method may not be used if a stream source has been
119 Errors are not guaranteed to be reported synchronously
120 with the call, but may instead be delayed until a
123 ret
= libvirtmod
.virStreamSend(self
._o
, data
, len(data
))
124 if ret
== -1: raise libvirtError ('virStreamSend() failed')