These are chat archives for IndySockets/Indy

3rd
Feb 2018
mercedwang
@mercedwang
Feb 03 2018 10:10
@rlebeau I follow ur suggests and implement my own ReadBytes procedure. Now it works very well.
procedure ReadBytes(IOHandler: TIdIOHandler; var VBuffer: TIdBytes; AByteCount: Integer; AAppend: Boolean = True);
const
CheckInterval = 5000;
var
InitialTimeout, Timeout: Integer;
NewDataAvail: Boolean;
begin
Assert(Assigned(IOHandler.InputBuffer));
InitialTimeout := IfThen(IOHandler.ReadTimeout >= 0, IOHandler.ReadTimeout, MaxInt);
while IOHandler.InputBuffer.Size < AByteCount do begin
Timeout := InitialTimeout;
repeat
if Timeout <= 0 then raise EIdReadTimeout.Create(RSReadTimeout);
NewDataAvail := IOHandler.CheckForDataOnSource(Min(CheckInterval, Timeout));
IOHandler.CheckForDisconnect(True, True);
Dec(Timeout, CheckInterval);
until NewDataAvail;
end;
IOHandler.InputBuffer.ExtractToBytes(VBuffer, AByteCount, AAppend);
end;
Kudzu
@czhower
Feb 03 2018 17:32
I did some digging, and it looks like there is a bug affecting you. *nix does conform and closing a socket from one thread will err out recv/send calls in other threads.
Some users have reported that some linux builds are not doing this, but its incorrect behaviour and can break lots of apps.
It seems to be a recurring problem on Linux from what I can see.