Angus Robertson - Magenta Systems Ltd wrote:
>>> I'm writing simple console downloader and decided to use sync
>>> operations in order to simplify structure. But I've found that
>>> sync requests (HttpCli) do not use any timeout, so they may last
>>> forever in case of error.
>>
>> That's IMHO a bug.
>
> Indeed, poor implementation in THttpCli with no timeout.
>
> But most components do have a timeout for sync methods, for instance
> TSyncSmtpCli and TFtpClient.
Yes they have, but do they work properly when a send or receive lasts
longer then the timeout value?
Please guys, take a look at this fix for V7 and test it, anything wrong
with it?
{code}
procedure THttpCli.DoRequestSync(Rq : THttpRequest);
var
DummyHandle : {$IFDEF CLR}Borland.Vcl.Windows.THandle;
{$ELSE} THandle;{$ENDIF}
TimeOutMsec : UINT;
begin
DoRequestAsync(Rq);
if not Assigned(FCtrlSocket.Counter) then
FCtrlSocket.CreateCounter;
FCtrlSocket.Counter.SetConnected; // Reset counter
DummyHandle := INVALID_HANDLE_VALUE;
TimeOutMsec := 5000;//FTimeOut * 1000; // hardcoded 5 sec for testing only
while FState <> httpReady do
begin
if MsgWaitForMultipleObjects(0, DummyHandle, FALSE, 1000,
QS_ALLINPUT) = WAIT_OBJECT_0 then
FCtrlSocket.MessagePump;
if (FState <> httpReady) and (
{$IFNDEF NOFORMS} Application.Terminated or {$ENDIF} FTerminated or
(IcsCalcTickDiff(FCtrlSocket.Counter.LastAliveTick,
GetTickCount) >= TimeOutMsec)) then
begin
Abort;
break;
end;
end;
{* Jul 12, 2004
WARNING: The component now doesn't consider 401 status
as a fatal error (no exception is triggered). This required a
change in the application code if it was using the exception that
is no more triggered for status 401 and 407.
*}
{* if FStatusCode > 401 then Dec 14, 2004 *}
if (FStatusCode >= 400) and (FStatusCode <> 401) and (FStatusCode <> 407)
then
raise EHttpException.Create(FReasonPhrase, FStatusCode);
end;
{code}
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be