kopia lustrzana https://github.com/cirospaciari/socketify.py
less pressure on WSGI try_end
rodzic
27cfb3482b
commit
18892b729d
|
@ -31,6 +31,6 @@ def app_hello(environ, start_response):
|
|||
|
||||
if __name__ == "__main__":
|
||||
from socketify import WSGI
|
||||
WSGI(app).listen(8000, lambda config: print(f"Listening on port http://localhost:{config.port} now\n")).run(4)
|
||||
WSGI(app_chunked).listen(8000, lambda config: print(f"Listening on port http://localhost:{config.port} now\n")).run(8)
|
||||
# import fastwsgi
|
||||
# fastwsgi.run(wsgi_app=app_hello, host='127.0.0.1', port=8000)
|
||||
|
|
|
@ -40,58 +40,47 @@ def wsgi_on_writable_handler(res, offset, user_data):
|
|||
return False
|
||||
|
||||
chunks = data_retry.chunks
|
||||
while len(chunks) > 0:
|
||||
last_sended_offset = data_retry.last_offset
|
||||
ssl = data_retry.app.server.SSL
|
||||
content_length = data_retry.content_length
|
||||
|
||||
data = chunks[0]
|
||||
last_sended_offset = data_retry.last_offset
|
||||
ssl = data_retry.app.server.SSL
|
||||
content_length = data_retry.content_length
|
||||
|
||||
data = chunks[0]
|
||||
data_size = len(data)
|
||||
last_offset = int(lib.uws_res_get_write_offset(ssl, res))
|
||||
if last_sended_offset != last_offset:
|
||||
offset = last_offset - last_sended_offset
|
||||
data = data[offset:data_size]
|
||||
data_size = len(data)
|
||||
last_offset = int(lib.uws_res_get_write_offset(ssl, res))
|
||||
if last_sended_offset != last_offset:
|
||||
offset = last_offset - last_sended_offset
|
||||
data = data[offset:data_size]
|
||||
data_size = len(data)
|
||||
if data_size == 0:
|
||||
chunks.pop(0)
|
||||
|
||||
if len(chunks) == 0:
|
||||
logging.error(AssertionError("Content-Length do not match sended content"))
|
||||
lib.uws_res_close(
|
||||
ssl,
|
||||
res
|
||||
)
|
||||
if data_retry.id is not None:
|
||||
data_retry.app._data_refs.pop(data_retry.id, None)
|
||||
|
||||
return False
|
||||
data = chunks[0]
|
||||
|
||||
result = lib.uws_res_try_end(
|
||||
ssl,
|
||||
res,
|
||||
data,
|
||||
data_size,
|
||||
content_length,
|
||||
0,
|
||||
)
|
||||
has_responded = bool(result.has_responded)
|
||||
data_retry.last_offset = int(lib.uws_res_get_write_offset(ssl, res))
|
||||
|
||||
if bool(result.ok):
|
||||
if data_size == 0:
|
||||
chunks.pop(0)
|
||||
if not has_responded and len(chunks) == 0:
|
||||
logging.error(AssertionError("Content-Length do not match sended content"))
|
||||
lib.uws_res_close(
|
||||
ssl,
|
||||
res
|
||||
)
|
||||
if data_retry.id is not None:
|
||||
data_retry.app._data_refs.pop(data_retry.id, None)
|
||||
elif has_responded and data_retry.id is not None:
|
||||
|
||||
if len(chunks) == 0:
|
||||
logging.error(AssertionError("Content-Length do not match sended content"))
|
||||
lib.uws_res_close(
|
||||
ssl,
|
||||
res
|
||||
)
|
||||
if data_retry.id is not None:
|
||||
data_retry.app._data_refs.pop(data_retry.id, None)
|
||||
break
|
||||
elif not has_responded and len(chunks) == 0:
|
||||
|
||||
return True
|
||||
data = chunks[0]
|
||||
|
||||
result = lib.uws_res_try_end(
|
||||
ssl,
|
||||
res,
|
||||
data,
|
||||
data_size,
|
||||
content_length,
|
||||
0,
|
||||
)
|
||||
has_responded = bool(result.has_responded)
|
||||
ok = bool(result.ok)
|
||||
data_retry.last_offset = int(lib.uws_res_get_write_offset(ssl, res))
|
||||
|
||||
if ok:
|
||||
chunks.pop(0)
|
||||
if not has_responded and len(chunks) == 0:
|
||||
logging.error(AssertionError("Content-Length do not match sended content"))
|
||||
lib.uws_res_close(
|
||||
ssl,
|
||||
|
@ -101,10 +90,19 @@ def wsgi_on_writable_handler(res, offset, user_data):
|
|||
data_retry.app._data_refs.pop(data_retry.id, None)
|
||||
elif has_responded and data_retry.id is not None:
|
||||
data_retry.app._data_refs.pop(data_retry.id, None)
|
||||
break
|
||||
|
||||
elif not has_responded and len(chunks) == 0:
|
||||
logging.error(AssertionError("Content-Length do not match sended content"))
|
||||
lib.uws_res_close(
|
||||
ssl,
|
||||
res
|
||||
)
|
||||
if data_retry.id is not None:
|
||||
data_retry.app._data_refs.pop(data_retry.id, None)
|
||||
elif has_responded and data_retry.id is not None:
|
||||
data_retry.app._data_refs.pop(data_retry.id, None)
|
||||
|
||||
|
||||
return False
|
||||
return ok
|
||||
|
||||
|
||||
class WSGIBody:
|
||||
|
|
Ładowanie…
Reference in New Issue