kopia lustrzana https://github.com/cirospaciari/socketify.py
fixed cork in CPython + PyPy
rodzic
1e16de77f2
commit
b825d81fbf
|
@ -87,8 +87,8 @@ class Loop:
|
||||||
#force asyncio run once to enable req in async functions before first await
|
#force asyncio run once to enable req in async functions before first await
|
||||||
self.run_once_asyncio()
|
self.run_once_asyncio()
|
||||||
|
|
||||||
# if response != None: #set auto cork
|
#if response != None: #set auto cork
|
||||||
# response.needs_cork = True
|
# response.needs_cork = True
|
||||||
return future
|
return future
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,9 @@ from datetime import datetime
|
||||||
from urllib.parse import parse_qs, quote_plus, unquote_plus
|
from urllib.parse import parse_qs, quote_plus, unquote_plus
|
||||||
from threading import Thread, local, Lock
|
from threading import Thread, local, Lock
|
||||||
|
|
||||||
|
import platform
|
||||||
|
is_python = platform.python_implementation() == 'CPython'
|
||||||
|
|
||||||
ffi = cffi.FFI()
|
ffi = cffi.FFI()
|
||||||
ffi.cdef("""
|
ffi.cdef("""
|
||||||
|
|
||||||
|
@ -266,9 +269,11 @@ def uws_generic_listen_handler(listen_socket, config, user_data):
|
||||||
@ffi.callback("void(uws_res_t *, void*)")
|
@ffi.callback("void(uws_res_t *, void*)")
|
||||||
def uws_generic_aborted_handler(response, user_data):
|
def uws_generic_aborted_handler(response, user_data):
|
||||||
if not user_data == ffi.NULL:
|
if not user_data == ffi.NULL:
|
||||||
res = ffi.from_handle(user_data)
|
try:
|
||||||
res.trigger_aborted()
|
res = ffi.from_handle(user_data)
|
||||||
|
res.trigger_aborted()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
@ffi.callback("void(uws_res_t *, const char *, size_t, bool, void*)")
|
@ffi.callback("void(uws_res_t *, const char *, size_t, bool, void*)")
|
||||||
def uws_generic_on_data_handler(res, chunk, chunk_length, is_end, user_data):
|
def uws_generic_on_data_handler(res, chunk, chunk_length, is_end, user_data):
|
||||||
if not user_data == ffi.NULL:
|
if not user_data == ffi.NULL:
|
||||||
|
@ -408,14 +413,15 @@ class AppResponse:
|
||||||
self._ptr = ffi.new_handle(self)
|
self._ptr = ffi.new_handle(self)
|
||||||
self._grabed_abort_handler_once = False
|
self._grabed_abort_handler_once = False
|
||||||
self._write_jar = None
|
self._write_jar = None
|
||||||
# self.needs_cork = False
|
|
||||||
self._cork_handler = None
|
self._cork_handler = None
|
||||||
|
|
||||||
def cork(self, callback):
|
def cork(self, callback):
|
||||||
if not self.aborted:
|
if not self.aborted:
|
||||||
self._cork_handler = callback
|
self._cork_handler = callback
|
||||||
#just add to uv loop in next tick to garantee corking works properly
|
if is_python:
|
||||||
self.loop.set_timeout(0, lambda instance: lib.uws_res_cork(instance.SSL, instance.res, uws_generic_cork_handler, instance._ptr), self)
|
lib.uws_res_cork(self.SSL, self.res, uws_generic_cork_handler, self._ptr)
|
||||||
|
else: #just add to uv loop in next tick to garantee corking works properly in pypy3
|
||||||
|
self.loop.set_timeout(0, lambda instance: lib.uws_res_cork(instance.SSL, instance.res, uws_generic_cork_handler, instance._ptr), self)
|
||||||
|
|
||||||
def set_cookie(self, name, value, options={}):
|
def set_cookie(self, name, value, options={}):
|
||||||
if self._write_jar == None:
|
if self._write_jar == None:
|
||||||
|
|
|
@ -28,7 +28,7 @@ import asyncio
|
||||||
|
|
||||||
async def home(res, req):
|
async def home(res, req):
|
||||||
# res.write_header("Content-Type", "plain/text")
|
# res.write_header("Content-Type", "plain/text")
|
||||||
await asyncio.sleep(0)
|
# await asyncio.sleep(0)
|
||||||
|
|
||||||
def corked(res):
|
def corked(res):
|
||||||
res.write("Test ")
|
res.write("Test ")
|
||||||
|
@ -51,7 +51,7 @@ def create_fork():
|
||||||
if not n > 0:
|
if not n > 0:
|
||||||
run_app()
|
run_app()
|
||||||
|
|
||||||
# fork limiting the cpu count - 1
|
# # fork limiting the cpu count - 1
|
||||||
# for i in range(1, multiprocessing.cpu_count()):
|
# for i in range(1, multiprocessing.cpu_count()):
|
||||||
# create_fork()
|
# create_fork()
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue