Anton Sviridov wrote:

> Arno Garrels wrote
>> Please guys, take a look at this fix for V7 and test it, anything
>> wrong with it?
> It works, but I think Abort isn'tt a very good way to tell that there
> was timeout... 

Abort on timeout is commonly used in ICS.    

> and 404 even stranger. 404 means that file not exist
> (constant error), 

Any alternates (http://en.wikipedia.org/wiki/List_of_HTTP_status_codes)? 

It's not a constant error AFAIK. IMO 408 was more confusing. 
404 Not Found
The requested resource could not be found but may be available again
in the future. Subsequent requests by the client are permissible.

408 Request Timeout
The server timed out waiting for the request.

"Connection aborted on request" means that user or
> control proc decided to break the waiting, and timeout means that
> there's no answer from server and we should wait and retry later.

OK, what about this one?

{code}
procedure THttpCli.DoRequestSync(Rq : THttpRequest);
var
    DummyHandle     : {$IFDEF CLR}Borland.Vcl.Windows.THandle;
                      {$ELSE} THandle;{$ENDIF}
    TimeOutMsec     : UINT;
    bFlag           : Boolean;
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
            bFlag := (FState = httpDnsLookup);
            StateChange(httpAborting);

            if bFlag then
            try
                FCtrlSocket.CancelDnsLookup;
            except
                { Ignore any exception }
            end;
            FStatusCode := 404;
            if {$IFNDEF NOFORMS} Application.Terminated or {$ENDIF} FTerminated 
then
            begin
                FReasonPhrase     := 'Request aborted';
                FRequestDoneError := httperrAborted;
            end
            else begin
                FReasonPhrase     := 'Request aborted on timeout';
                FRequestDoneError := 8; //new const will be added 
httperrCustomTimeOut = 8
            end;
            if bFlag then
                SocketSessionClosed(Self, 0)
            else
                FCtrlSocket.Close;
            StateChange(httpReady);
            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}
    
--
Arno Garrels

--
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

Reply via email to