Zvone wrote:
> 
>> something, worth to be tested anyway:
>> [...]
> 
> I'll take a look and test this code soon enough. Thanks.

Try the change below instead, otherwise you might get Integer 
overflow exceptions.
It happens that even though the socket is paused the component
receives data after it got a close notify message. When we Pause
the socket there may still be notify messages from Winsock
in the message queue, so be prepared that the throttle and timeout
might not work reliable always. 

{code}

function TCustomThrottledWSocket.RealSend(var Data: TWSocketData;
  Len: Integer): Integer;
begin
    if FBandwidthEnabled and (Len > 0) and
       (FBandwidthCount < FBandwidthMaxCount) and
       (FBandwidthCount + LongWord(Len) > FBandwidthMaxCount) then
        Len := (FBandwidthMaxCount - FBandwidthCount) + 1;

    Result := inherited RealSend(Data, Len);

    if FBandwidthEnabled and (Result > 0) then begin
        Inc(FBandwidthCount, Result);
        if (FBandwidthCount > FBandwidthMaxCount) and
           (not FBandwidthPaused) then begin
            FBandwidthPaused := TRUE;
            Pause;
        end;
    end;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function TCustomThrottledWSocket.Receive(Buffer: TWSocketData;
  BufferSize: Integer): Integer;
begin
    if FBandwidthEnabled and (BufferSize > 0) and
       (FBandwidthCount < FBandwidthMaxCount) and
       (FBandwidthCount + LongWord(BufferSize) > FBandwidthMaxCount) then
        BufferSize := (FBandwidthMaxCount - FBandwidthCount) + 1;

    Result := inherited Receive(Buffer, BufferSize);

    if FBandwidthEnabled and (Result > 0) then begin
        Inc(FBandwidthCount, Result);
        if (FBandwidthCount > FBandwidthMaxCount) and
            (not FBandwidthPaused) then begin
            FBandwidthPaused := TRUE;
            Pause;
        end;    
    end;
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

Reply via email to