I used TIdBytes in the thread because this is purportedly better than string.
The old code expects a stream of events each supplying a string type chunk.
The processing part of the event handler adds the new chunk to a client side string buffer and then checks if the ETX has arrived. So there is a packeting mechanism there.
If it has it also signals that there is a message to read for the main code.
If I instead make the read thread wait for a complete message ending with ETX, before firing off the event, then I guess all of the data (potentially rather big) will be supplied in one call. And the ETX will not be part of it, right?
So I could add ETX to the end so that the existing code will get it like before.
Question:
If I do a read with delimiting char in the thread (ReadLn), then I suspect that if the transfer takes some time the timeout will fire in the thread. How can it know that this happened and not send off the data but instead do another read call?
I cannot find a version of Read that uses a terminator and TIdBytes as an expanding buffer...
Or does ReadLn(ETX) not return any data if the terminator has not been seen?
Will this work (with FRxData being a string instead of TIdBytes):
EDIT:
Well, it turns out that using the ETX in socket readln makes the system throw up an exception from within Indy10 with this message:
It happens when a logfile was transfered.
It is pretty big (currently 7.6 Mbytes) and was the reason I asked about the maximum size of transfers before...
What is the maximum line length for Indy10?
EDIT2:
Turns out that in Core/IdIOHandler.pas this is specified:
Which means that the tx and rx buffers are each 32K and the max line length for ReadLn is 16K.
How can one then transfer data that is megabytes in size using an STX/ETX protocol?
The old code expects a stream of events each supplying a string type chunk.
The processing part of the event handler adds the new chunk to a client side string buffer and then checks if the ETX has arrived. So there is a packeting mechanism there.
If it has it also signals that there is a message to read for the main code.
If I instead make the read thread wait for a complete message ending with ETX, before firing off the event, then I guess all of the data (potentially rather big) will be supplied in one call. And the ETX will not be part of it, right?
So I could add ETX to the end so that the existing code will get it like before.
Question:
If I do a read with delimiting char in the thread (ReadLn), then I suspect that if the transfer takes some time the timeout will fire in the thread. How can it know that this happened and not send off the data but instead do another read call?
I cannot find a version of Read that uses a terminator and TIdBytes as an expanding buffer...
Or does ReadLn(ETX) not return any data if the terminator has not been seen?
Will this work (with FRxData being a string instead of TIdBytes):
Code:
procedure TReadingThread.Execute;
begin
while not Terminated do
begin
if FOwner.Connected then //Do not use FConn.Connected here
begin
FRxData := FOwner.FConn.IOHandler.ReadLn(ETX); //was ReadBytes(FRxData, -1, False); //Get all available data
if Assigned(FOwner.FOnRxData) and (Length(FRxData) > 0) then
Synchronize(DoOnRxData);
end;
end;
end;
procedure TReadingThread.DoOnRxData;
begin
if Assigned(FOwner.FOnRxData) then
FOwner.FOnRxData(Self, FRxData + ETX);
end;
EDIT:
Well, it turns out that using the ETX in socket readln makes the system throw up an exception from within Indy10 with this message:
Quote:Debugger exception notification
Project <name> raised exception class 'EIdReadLnMaxLineLengthExceeded' with message
Max line length exceeded.
in file '.\Core\IdIOHandler.pas' at line 1524
It happens when a logfile was transfered.
It is pretty big (currently 7.6 Mbytes) and was the reason I asked about the maximum size of transfers before...
What is the maximum line length for Indy10?
EDIT2:
Turns out that in Core/IdIOHandler.pas this is specified:
Code:
const
GRecvBufferSizeDefault = 32 * 1024;
GSendBufferSizeDefault = 32 * 1024;
IdMaxLineLengthDefault = 16 * 1024;
// S.G. 6/4/2004: Maximum number of lines captured
// S.G. 6/4/2004: Default to "unlimited"
Id_IOHandler_MaxCapturedLines = -1;
How can one then transfer data that is megabytes in size using an STX/ETX protocol?