Skip to content

Commit

Permalink
supported new uvloop(>=0.9.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
ifplusor committed Sep 7, 2018
1 parent 0650081 commit 479ca61
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/japronto/protocol/cprotocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,21 +190,32 @@ Protocol_connection_made(Protocol* self, PyObject* transport)
#endif

PyObject* get_extra_info = NULL;
PySocketSockObject* socket = NULL;
PyObject* socket = NULL;
PyObject* socket_fileno = NULL;
PyObject* fileno = NULL;
PyObject* connections = NULL;
self->transport = transport;
Py_INCREF(self->transport);

if(!(get_extra_info = PyObject_GetAttrString(transport, "get_extra_info")))
goto error;

if(!(socket = (PySocketSockObject*)PyObject_CallFunctionObjArgs(
// NOTE: this will return a PseudoSocket object(uvloop>=0.9.0), not PySocketSockObject(socket_socket in uvloop<0.9.0)
if(!(socket = PyObject_CallFunctionObjArgs(
get_extra_info, socket_str, NULL)))
goto error;

if(!(socket_fileno = PyObject_GetAttrString(socket, "fileno")))
goto error;

if(!(fileno = PyObject_CallFunctionObjArgs(socket_fileno, NULL)))
goto error;

int sock_fd = (int)PyLong_AsLong(fileno);
const int on = 1;

if(setsockopt(socket->sock_fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)) != 0)
// in uvloop(>=0.9.0) TCPTransport.new, the socket have set nodelay now.
if(setsockopt(sock_fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)) != 0)
goto error;

if(!(self->write = PyObject_GetAttrString(transport, "write")))
Expand Down

0 comments on commit 479ca61

Please sign in to comment.