kore

An easy to use, scalable and secure web application framework for writing web APIs in C.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 0b84a9c1d4c76ecc1619bbcf8949c10bf501bebd
parent af899f15e0dbdbf05b32a7fdee68af765bd664be
Author: Joris Vink <joris@coders.se>
Date:   Mon, 13 Mar 2017 12:22:50 +0100

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

Diffstat:
includes/python_methods.h | 6++++++
src/python.c | 19+++++++++++++++++++
2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/includes/python_methods.h b/includes/python_methods.h @@ -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), }; diff --git a/src/python.c b/src/python.c @@ -668,6 +668,25 @@ pyconnection_alloc(struct connection *c) } 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) { struct pyhttp_request *pyreq;