expose kore_websocket_send() to python.

This commit is contained in:
Joris Vink 2017-01-30 22:00:03 +01:00
parent e4d87b72a0
commit 30666618f8
2 changed files with 22 additions and 0 deletions

View File

@ -15,6 +15,7 @@
*/
static PyObject *python_exported_log(PyObject *, PyObject *);
static PyObject *python_websocket_send(PyObject *, PyObject *);
static PyObject *python_websocket_broadcast(PyObject *, PyObject *);
#define METHOD(n, c, a) { n, (PyCFunction)c, a, NULL }
@ -24,6 +25,7 @@ static PyObject *python_websocket_broadcast(PyObject *, PyObject *);
static struct PyMethodDef pykore_methods[] = {
METHOD("log", python_exported_log, METH_VARARGS),
METHOD("websocket_send", python_websocket_send, METH_VARARGS),
METHOD("websocket_broadcast", python_websocket_broadcast, METH_VARARGS),
{ NULL, NULL, 0, NULL }
};

View File

@ -773,6 +773,26 @@ python_websocket_broadcast(PyObject *self, PyObject *args)
Py_RETURN_TRUE;
}
static PyObject *
python_websocket_send(PyObject *self, PyObject *args)
{
int op;
struct pyconnection *pyc;
Py_buffer data;
if (!PyArg_ParseTuple(args, "O!iy*",
&pyconnection_type, &pyc, &op, &data)) {
PyErr_SetString(PyExc_TypeError, "invalid parameters");
return (NULL);
}
kore_websocket_send(pyc->c, op, data.buf, data.len);
PyBuffer_Release(&data);
Py_RETURN_TRUE;
}
static PyObject *
pyhttp_get_host(struct pyhttp_request *pyreq, void *closure)
{