expose c.disconnect() and c.fd to Python.

This commit is contained in:
Joris Vink 2017-03-13 12:22:50 +01:00
parent af899f15e0
commit 0b84a9c1d4
2 changed files with 25 additions and 0 deletions

View File

@ -51,11 +51,17 @@ struct pyconnection {
struct connection *c;
};
static PyObject *pyconnection_disconnect(struct pyconnection *, PyObject *);
static PyMethodDef pyconnection_methods[] = {
METHOD("disconnect", pyconnection_disconnect, METH_NOARGS),
METHOD(NULL, NULL, -1),
};
static PyObject *pyconnection_get_fd(struct pyconnection *, void *);
static PyGetSetDef pyconnection_getset[] = {
GETTER("fd", pyconnection_get_fd),
GETTER(NULL, NULL),
};

View File

@ -667,6 +667,25 @@ pyconnection_alloc(struct connection *c)
return ((PyObject *)pyc);
}
static PyObject *
pyconnection_disconnect(struct pyconnection *pyc, PyObject *args)
{
kore_connection_disconnect(pyc->c);
Py_RETURN_TRUE;
}
static PyObject *
pyconnection_get_fd(struct pyconnection *pyc, void *closure)
{
PyObject *fd;
if ((fd = PyLong_FromLong(pyc->c->fd)) == NULL)
return (PyErr_NoMemory());
return (fd);
}
static PyObject *
pyhttp_request_alloc(struct http_request *req)
{