<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2014-04-25 11:11 GMT-03:00 Michael Van Canneyt <span dir="ltr"><<a href="mailto:michael@freepascal.org" target="_blank">michael@freepascal.org</a>></span>:<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class=""><div class="h5">
On Fri, 25 Apr 2014, silvioprog wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
2014-04-25 10:24 GMT-03:00 Michael Van Canneyt <<a href="mailto:michael@freepascal.org" target="_blank">michael@freepascal.org</a>>:<br>
On Fri, 25 Apr 2014, silvioprog wrote:<br>
2014-04-25 3:39 GMT-03:00 Michael Van Canneyt <<a href="mailto:michael@freepascal.org" target="_blank">michael@freepascal.org</a>>:<br>
[...] <br>
Damn windows returning 0 on read... Can you please test with the following change:<br>
<br>
Procedure FillBuffer;<br>
<br>
Var<br>
R : Integer;<br>
<br>
begin<br>
SetLength(FBuffer,ReadBufLen);<br>
Repeat<br>
r:=FSocket.Read(FBuffer[1],<u></u>ReadBufLen);<br>
If r<0 then<br>
Raise EHTTPServer.Create(<u></u>SErrReadingSocket);<br>
if R=0 then<br>
Sleep(10);<br>
Until (R<>0);<br>
if (R<ReadBuflen) then<br>
SetLength(FBuffer,r);<br>
end;<br>
<br>
<br>
After apply this change, now when read returns 0, it freezes the app., because the "sleep(10)" command is infinitely called. :/<br>
<br>
<br>
OK, what we can do is add a timeout:<br>
<br>
Procedure FillBuffer;<br>
<br>
Const<br>
MaxReadRetries = 150;<br>
<br>
Var<br>
R,C : Integer;<br>
<br>
begin<br>
C:=0;<br>
SetLength(FBuffer,ReadBufLen);<br>
Repeat<br>
r:=FSocket.Read(FBuffer[1],<u></u>ReadBufLen);<br>
If r<0 then<br>
Raise EHTTPServer.Create(<u></u>SErrReadingSocket);<br>
if R=0 then<br>
begin<br>
Sleep(10);<br>
Inc(C);<br>
end;<br>
Until (R<>0) or (C>MaxReadRetries);<br>
if (R<ReadBuflen) then<br>
SetLength(FBuffer,r);<br>
end;<br>
<br>
It will then try 150 times, and then error out.<br>
<br>
BUT, reading this:<br>
<br>
<a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms740121%28v=vs.85%29.aspx" target="_blank">http://msdn.microsoft.com/en-<u></u>us/library/windows/desktop/<u></u>ms740121%28v=vs.85%29.aspx</a><br>
<br>
"If the connection has been gracefully closed, the return value is zero."<br>
<br>
So, this means then thay the original implementation is correct. You just need to catch the error using the OnRequestError handler...<br><br>
Sorry for my ignorance, but, would not it be better to read the HTTP data only if the client is still connected or if read bytes > 0?<br>
</blockquote>
<br></div></div>
Yes and no. Yes in the sense that you have a more 'clean' experience.<br>
No, because it IS an error condition (client went away unexpectedly) and you should be aware of it.<br>
<br>
I will make it a property that is settable: 'IgnoreLostConnections' or so.</blockquote></div><div><br></div><div>The 'IgnoreLostConnections' is a nice solution! :)</div><div><br></div>-- <br>Silvio Clécio<br>
My public projects - <a href="http://github.com/silvioprog" target="_blank">github.com/silvioprog</a>
</div></div>