fix race condition. let write die if we get EPIPE more than one time in

the loop
This commit is contained in:
Benoit Chesneau 2010-01-19 20:08:01 +01:00
parent 73431574a5
commit c613b826c8
4 changed files with 9 additions and 11 deletions

View File

@ -17,16 +17,14 @@ class HttpParser(object):
self._chunk_eof = False
def headers(self, headers, buf):
""" take a string buff. It return
new position or -1 if parsing isn't done.
headers dict is updated.
""" take a string as buffer and an header dict
(empty or not). It return new position or -1
if parsing isn't done. headers dict is updated
with new headers.
"""
if self._headers:
return self._headers
# wee could be smarter here
# by just reading the array, but converting
# is enough for now
ld = len("\r\n\r\n")
i = buf.find("\r\n\r\n")
if i != -1:

View File

@ -81,7 +81,6 @@ class HTTPRequest(object):
buf = buf[i:]
self.log.info("Got headers:\n%s" % headers)
if headers.get('Except', '').lower() == "100-continue":

View File

@ -37,8 +37,6 @@ class HTTPResponse(object):
write(self.sock, "%s\r\n" % "".join(resp_head))
for chunk in list(self.data):
write(self.sock, chunk)

View File

@ -49,6 +49,7 @@ def read_partial(sock, length):
def write(sock, data):
buf = ""
buf += data
i = 0
while buf:
try:
bytes = sock.send(buf)
@ -60,9 +61,11 @@ def write(sock, data):
if e[0] in (errno.EWOULDBLOCK, errno.EAGAIN):
break
elif e[0] in (errno.EPIPE,):
continue
if i == 0:
continue
raise
i += 1
def write_nonblock(sock, data):
while True:
try: