From a0d8a16b86c62072bd5c1514a70a94369c2e7279 Mon Sep 17 00:00:00 2001 From: benoitc Date: Thu, 4 Mar 2010 18:07:45 +0100 Subject: [PATCH] improve read_partial --- gunicorn/util.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gunicorn/util.py b/gunicorn/util.py index 7d8593bb..352679b5 100644 --- a/gunicorn/util.py +++ b/gunicorn/util.py @@ -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: