improve read_partial

This commit is contained in:
benoitc 2010-03-04 18:07:45 +01:00
parent 176ad162b1
commit a0d8a16b86

View File

@ -3,7 +3,6 @@
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
import array
import ctypes
import fcntl
import os
@ -91,7 +90,13 @@ def close(sock):
pass
def read_partial(sock, length, buf=None):
tmp_buf = array.array("c", '\0' * length)
if buf is not None:
if len(buf) >= length:
return buf
else:
length = length - len(buf)
tmp_buf = ctypes.create_string_buffer(length)
l = sock.recv_into(tmp_buf, length)
if not buf: