Klaus Demo bjoern / e426b99
Make it possible to pass file descriptors 'bjoern.server_run' may now be used with an integer, not only with real socket objects, as first argument (actually, you can pass in anything that works with the 'PyObject_AsFileDescriptor()' C function). Jonas Haag 6 years ago
2 changed file(s) with 12 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
7575 for initializing and cleaning up the socket in that case. ::
7676
7777 bjoern.server_run(socket_object, wsgi_application)
78 bjoern.server_run(filedescriptor_as_integer, wsgi_application)
7879
7980 .. _WSGI: http://www.python.org/dev/peps/pep-0333/
8081 .. _libev: http://software.schmorp.de/pkg/libev.html
2020 return NULL;
2121 }
2222
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;
23 info.host = NULL;
24 if (PyObject_HasAttrString(socket, "getsockname")) {
25 PyObject* sockname = PyObject_CallMethod(socket, "getsockname", NULL);
26 if (sockname == NULL) {
27 return NULL;
28 }
29 if (PyTuple_CheckExact(sockname) && PyTuple_GET_SIZE(sockname) == 2) {
30 /* Standard (ipaddress, port) case */
31 info.host = PyTuple_GET_ITEM(sockname, 0);
32 info.port = PyTuple_GET_ITEM(sockname, 1);
33 }
3334 }
3435
3536 _initialize_request_module();