python: Add binding for non-blocking xs_check_watch()

xs_check_watch() checks for watch notifications without blocking.
Together with the binding for xs_fileno(), this makes it possible
to write event-driven clients in Python.

Signed-off-by: Euan Harris <euan.harris@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
This commit is contained in:
Euan Harris authored and Wei Liu committed 2017-09-25 14:36:00 +01:00
1 parent f6e1023412
commit 5fc07747d6
1 file changed
+28
+28
View File
@@ -474,6 +474,33 @@ static PyObject *xspy_fileno(XsHandle *self)
}
#define xspy_check_watch_doc "\n" \
"Check for watch notifications without blocking.\n" \
"\n" \
"Returns: [tuple] (path, token).\n" \
" None if no watches have fired.\n" \
"Raises xen.lowlevel.xs.Error on error.\n" \
"\n"
static PyObject *xspy_check_watch(XsHandle *self, PyObject *args)
{
struct xs_handle *xh = xshandle(self);
PyObject *val = NULL;
char **xsval;
if (!xh)
return NULL;
xsval = xs_check_watch(xh);
if (!xsval) {
return none(errno == EAGAIN);
}
val = match_watch_by_token(self, xsval);
free(xsval);
return val;
}
#define xspy_read_watch_doc "\n" \
"Read a watch notification.\n" \
"\n" \
@@ -911,6 +938,7 @@ static PyMethodDef xshandle_methods[] = {
XSPY_METH(set_permissions, METH_VARARGS),
XSPY_METH(watch, METH_VARARGS),
XSPY_METH(read_watch, METH_NOARGS),
XSPY_METH(check_watch, METH_NOARGS),
XSPY_METH(unwatch, METH_VARARGS),
XSPY_METH(transaction_start, METH_NOARGS),
XSPY_METH(transaction_end, METH_VARARGS | METH_KEYWORDS),
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.