Hi
I am messing around with the Indy 10 supplied with Delphi 2009 and am having trouble with getting all the data from the IOHandler when OnExecute fires...
procedure TFormMain.IdTCPServerExecute(AContext: TIdContext);
var
RxBufStr: UTF8String;
RxBufSize: Integer;
begin
if AContext.Connection.IOHandler.Readable then
begin
RxBufSize := AContext.Connection.IOHandler.InputBuffer.Size;
if RxBufSize > 0 then
begin
SetLength(RxBufStr, RxBufSize);
AContext.Connection.IOHandler.ReadBytes(TBytes(RxBufStr), RxBufSize, False);
end;
end;
end;
AContext.Connection.IOHandler.InputBuffer.Size doesn't seem reliable and often returns 0, but on the next run throug the OnExecute it'll pick up the right number of bytes, but that is too late.
Essentially I want to be able to just grab all the data, stuff it into a UTF8String (not a Unicode string) and then parse for a special marker. So I have no headers and messages are variable length. It seems the Indy 10 IOHandlers are not setup for this or I am just using it wrong.
It would be nice to do something like pass a buffer of a certain size, fill it as much as possible and return the number of bytes actually filled and then keep going if there are more.
As an aside what's the status of TIdSchedulerOfFiber, this looks very interesting, does it work? Is anyone using it? I notice that it isn't in the standard install of Delphi 2009 though.
Update: I found Msg := AContext.Connection.IOHandler.ReadLn(#0, enUTF8); which works but I still would like to know the answer to the above question, is it because it is based on blocking IO? Which makes even more keen on this TIdSchedulerOfFiber.