Skip to content

Commit

Permalink
update uvloop to 0.9.0+
Browse files Browse the repository at this point in the history
  • Loading branch information
ifplusor committed Sep 10, 2018
1 parent 479ca61 commit 847b628
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 47 deletions.
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
keywords=['web', 'asyncio'],
platforms='x86_64 Linux and MacOS X',
install_requires=[
'uvloop<0.9.0',
'uvloop>=0.9.0',
],
entry_points="""
[console_scripts]
Expand All @@ -49,6 +49,7 @@
'Programming Language :: C',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: Implementation :: CPython',
'Topic :: Internet :: WWW/HTTP'
],
Expand Down
46 changes: 0 additions & 46 deletions src/japronto/protocol/cprotocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ static PyObject* Parser;
static PyObject* PyRequest;
static PyObject* RouteNotFoundException;

static PyObject* socket_str;

static Request_CAPI* request_capi;
static Matcher_CAPI* matcher_capi;
static Response_CAPI* response_capi;
Expand Down Expand Up @@ -165,19 +163,6 @@ Protocol_init(Protocol* self, PyObject *args, PyObject *kw)
}


// copied from Modules/socketmodule.h
// FIXME on Windows SOCKET_T is a different type
typedef int SOCKET_T;
typedef struct {
PyObject_HEAD
SOCKET_T sock_fd;
// more things here that we dont need
} PySocketSockObject;


#include <netinet/in.h>
#include <netinet/tcp.h>

static PyObject*
Protocol_connection_made(Protocol* self, PyObject* transport)
{
Expand All @@ -189,35 +174,10 @@ Protocol_connection_made(Protocol* self, PyObject* transport)
self->false_cnt = Py_REFCNT(Py_False);
#endif

PyObject* get_extra_info = 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;

// 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;

// 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")))
goto error;

Expand Down Expand Up @@ -245,8 +205,6 @@ Protocol_connection_made(Protocol* self, PyObject* transport)

finally:
Py_XDECREF(connections);
Py_XDECREF(socket);
Py_XDECREF(get_extra_info);
Py_RETURN_NONE;
}

Expand Down Expand Up @@ -924,7 +882,6 @@ PyInit_cprotocol(void)
PyObject* api_capsule = NULL;
PyObject* crequest = NULL;
PyObject* route = NULL;
socket_str = NULL;

if (PyType_Ready(&ProtocolType) < 0)
goto error;
Expand Down Expand Up @@ -979,9 +936,6 @@ PyInit_cprotocol(void)
if(!response_capi)
goto error;

if(!(socket_str = PyUnicode_FromString("socket")))
goto error;

Py_INCREF(&ProtocolType);
PyModule_AddObject(m, "Protocol", (PyObject*)&ProtocolType);

Expand Down

0 comments on commit 847b628

Please sign in to comment.