summaryrefslogtreecommitdiffstats
path: root/libvirt-override.c
diff options
context:
space:
mode:
authorCole Robinson <crobinso@redhat.com>2011-06-14 16:07:43 -0400
committerCole Robinson <crobinso@redhat.com>2011-06-21 10:08:47 -0400
commitfa47dad041bf9878702724dba9d0ca4152fab928 (patch)
tree13b08cdead9ee6312e7116d0ea1f3f5f578aee97 /libvirt-override.c
parent8f2990bffe64b6d9392abd60a2bdc6da3a9aeafd (diff)
downloadlibvirt-python-v6-fa47dad041bf9878702724dba9d0ca4152fab928.tar.gz
libvirt-python-v6-fa47dad041bf9878702724dba9d0ca4152fab928.tar.xz
libvirt-python-v6-fa47dad041bf9878702724dba9d0ca4152fab928.zip
python: Implement virStreamSend/Recv
The return values for the python version are different that the C version of virStreamSend: on success we return a string, an error raises an exception, and if the stream would block we return int(-2). We need to do this since strings aren't passed by reference in python.
Diffstat (limited to 'libvirt-override.c')
-rw-r--r--libvirt-override.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/libvirt-override.c b/libvirt-override.c
index 55cb61c..63157b4 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -3697,6 +3697,66 @@ libvirt_virStreamEventAddCallback(PyObject *self ATTRIBUTE_UNUSED,
return py_retval;
}
+static PyObject *
+libvirt_virStreamRecv(PyObject *self ATTRIBUTE_UNUSED,
+ PyObject *args)
+{
+ PyObject *pyobj_stream;
+ virStreamPtr stream;
+ char *buf = NULL;
+ int ret;
+ int nbytes;
+
+ if (!PyArg_ParseTuple(args, (char *) "Oi:virStreamRecv",
+ &pyobj_stream, &nbytes)) {
+ DEBUG("%s failed to parse tuple\n", __FUNCTION__);
+ return VIR_PY_NONE;
+ }
+ stream = PyvirStream_Get(pyobj_stream);
+
+ if ((buf = malloc(nbytes+1 > 0 ? nbytes+1 : 1)) == NULL)
+ return VIR_PY_NONE;
+
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ ret = virStreamRecv(stream, buf, nbytes);
+ LIBVIRT_END_ALLOW_THREADS;
+
+ buf[ret > -1 ? ret : 0] = '\0';
+ DEBUG("StreamRecv ret=%d strlen=%d\n", ret, (int) strlen(buf));
+
+ if (ret < 0)
+ return libvirt_intWrap(ret);
+ return libvirt_charPtrSizeWrap((char *) buf, (Py_ssize_t) ret);
+}
+
+static PyObject *
+libvirt_virStreamSend(PyObject *self ATTRIBUTE_UNUSED,
+ PyObject *args)
+{
+ PyObject *py_retval;
+ PyObject *pyobj_stream;
+ virStreamPtr stream;
+ char *data;
+ int ret;
+ int nbytes;
+
+ if (!PyArg_ParseTuple(args, (char *) "Ozi:virStreamRecv",
+ &pyobj_stream, &data, &nbytes)) {
+ DEBUG("%s failed to parse tuple\n", __FUNCTION__);
+ return VIR_PY_INT_FAIL;
+ }
+ stream = PyvirStream_Get(pyobj_stream);
+
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ ret = virStreamSend(stream, data, nbytes);
+ LIBVIRT_END_ALLOW_THREADS;
+
+ DEBUG("StreamSend ret=%d\n", ret);
+
+ py_retval = libvirt_intWrap(ret);
+ return py_retval;
+}
+
/************************************************************************
* *
* The registration stuff *
@@ -3715,6 +3775,8 @@ static PyMethodDef libvirtMethods[] = {
{(char *) "virConnectDomainEventRegisterAny", libvirt_virConnectDomainEventRegisterAny, METH_VARARGS, NULL},
{(char *) "virConnectDomainEventDeregisterAny", libvirt_virConnectDomainEventDeregisterAny, METH_VARARGS, NULL},
{(char *) "virStreamEventAddCallback", libvirt_virStreamEventAddCallback, METH_VARARGS, NULL},
+ {(char *) "virStreamRecv", libvirt_virStreamRecv, METH_VARARGS, NULL},
+ {(char *) "virStreamSend", libvirt_virStreamSend, METH_VARARGS, NULL},
{(char *) "virDomainGetInfo", libvirt_virDomainGetInfo, METH_VARARGS, NULL},
{(char *) "virDomainGetState", libvirt_virDomainGetState, METH_VARARGS, NULL},
{(char *) "virDomainGetControlInfo", libvirt_virDomainGetControlInfo, METH_VARARGS, NULL},