Klaus Demo bjoern / 4271e46
bjoernmodule.{c,h} -> _bjoernmodule.{c,h} Jonas Haag 6 years ago
6 changed file(s) with 61 addition(s) and 62 deletion(s). Raw diff Collapse all Expand all
2323 FEATURES += -D WANT_SIGINT_HANDLING
2424 endif
2525
26 all: prepare-build $(objects) bjoernmodule
26 all: prepare-build $(objects) _bjoernmodule
2727
2828 print-env:
2929 @echo CFLAGS=$(CFLAGS)
3737 small: clean
3838 CFLAGS='-Os' make
3939
40 bjoernmodule:
40 _bjoernmodule:
4141 @$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(objects) -o $(BUILD_DIR)/_bjoern.so
4242 @PYTHONPATH=$$PYTHONPATH:$(BUILD_DIR) python2 -c "import bjoern"
4343
0 #include <Python.h>
1 #include "server.h"
2 #include "wsgi.h"
3 #include "_bjoernmodule.h"
4 #include "filewrapper.h"
5
6
7 static PyObject*
8 run(PyObject* self, PyObject* args)
9 {
10 ServerInfo info;
11
12 PyObject* socket;
13
14 if(!PyArg_ParseTuple(args, "OO:server_run", &socket, &info.wsgi_app)) {
15 return NULL;
16 }
17
18 info.sockfd = PyObject_AsFileDescriptor(socket);
19 if (info.sockfd < 0) {
20 return NULL;
21 }
22
23 PyObject* sockname = PyObject_CallMethod(socket, "getsockname", NULL);
24 if (sockname == NULL) {
25 return NULL;
26 }
27 if (PyTuple_CheckExact(sockname) && PyTuple_GET_SIZE(sockname) == 2) {
28 /* Standard (ipaddress, port) case */
29 info.host = PyTuple_GET_ITEM(sockname, 0);
30 info.port = PyTuple_GET_ITEM(sockname, 1);
31 } else {
32 info.host = NULL;
33 }
34
35 _initialize_request_module();
36 server_run(&info);
37
38 Py_RETURN_NONE;
39 }
40
41 static PyMethodDef Bjoern_FunctionTable[] = {
42 {"server_run", (PyCFunction) run, METH_VARARGS, NULL},
43 {NULL, NULL, 0, NULL}
44 };
45
46 PyMODINIT_FUNC init_bjoern(void)
47 {
48 _init_common();
49 _init_filewrapper();
50
51 PyType_Ready(&FileWrapper_Type);
52 assert(FileWrapper_Type.tp_flags & Py_TPFLAGS_READY);
53 PyType_Ready(&StartResponse_Type);
54 assert(StartResponse_Type.tp_flags & Py_TPFLAGS_READY);
55
56 PyObject* bjoern_module = Py_InitModule("_bjoern", Bjoern_FunctionTable);
57 PyModule_AddObject(bjoern_module, "version", Py_BuildValue("(iii)", 1, 3, 3));
58 }
(New empty file)
+0
-59
bjoern/bjoernmodule.c less more
0 #include <Python.h>
1 #include "server.h"
2 #include "wsgi.h"
3 #include "bjoernmodule.h"
4 #include "filewrapper.h"
5
6
7 static PyObject*
8 run(PyObject* self, PyObject* args)
9 {
10 ServerInfo info;
11
12 PyObject* socket;
13
14 if(!PyArg_ParseTuple(args, "OO:server_run", &socket, &info.wsgi_app)) {
15 return NULL;
16 }
17
18 info.sockfd = PyObject_AsFileDescriptor(socket);
19 if (info.sockfd < 0) {
20 return NULL;
21 }
22
23 PyObject* sockname = PyObject_CallMethod(socket, "getsockname", NULL);
24 if (sockname == NULL) {
25 return NULL;
26 }
27 if (PyTuple_CheckExact(sockname) && PyTuple_GET_SIZE(sockname) == 2) {
28 /* Standard (ipaddress, port) case */
29 info.host = PyTuple_GET_ITEM(sockname, 0);
30 info.port = PyTuple_GET_ITEM(sockname, 1);
31 } else {
32 info.host = NULL;
33 }
34
35 _initialize_request_module();
36 server_run(&info);
37
38 Py_RETURN_NONE;
39 }
40
41 static PyMethodDef Bjoern_FunctionTable[] = {
42 {"server_run", (PyCFunction) run, METH_VARARGS, NULL},
43 {NULL, NULL, 0, NULL}
44 };
45
46 PyMODINIT_FUNC init_bjoern(void)
47 {
48 _init_common();
49 _init_filewrapper();
50
51 PyType_Ready(&FileWrapper_Type);
52 assert(FileWrapper_Type.tp_flags & Py_TPFLAGS_READY);
53 PyType_Ready(&StartResponse_Type);
54 assert(StartResponse_Type.tp_flags & Py_TPFLAGS_READY);
55
56 PyObject* bjoern_module = Py_InitModule("_bjoern", Bjoern_FunctionTable);
57 PyModule_AddObject(bjoern_module, "version", Py_BuildValue("(iii)", 1, 3, 3));
58 }
+0
-0
bjoern/bjoernmodule.h less more
(Empty file)
00 #include "common.h"
1 #include "bjoernmodule.h"
21 #include "filewrapper.h"
32 #include "wsgi.h"
43