Hi Danijel
Thanks for the reply.
I've been playing and I think I've got most things sorted, but I wondered how the below scenario would work.
All my classes (that access HTTP data) run in their own threads and I will dedicate one TRtcHTTPClient to each thread (from a pool). The TRtcHTTPClient will not be accessed by any other thread. I've set Multithreaded = true and AutoConnect = true.
Each thread will also have a dedicated TRtcDataRequest, this will not be accessed by any other threads. I've set HyperThreading = false and AutoSyncEvents = false.
In my thread code, I call TRtcDataRequest.Post and then my thread waits on a TEvent to be signaled.
In the TRtcDataRequest.OnDataReceived event, I signal the TEvent when I get Response.Done. Because the data being downloaded may be large I call ReadEx in the TRtcDataRequest.OnDataReceived event and store it in my thread.
This seems to work great so I moved on to think about how to handle lost connections.
I have connected the TRtcDataRequest.OnConnectionLost event, in it I have:
FHasErrorCode := -1;
FErrorMessage := 'Connection lost';
Sender.Disconnect;
FWaitEvent.SetEvent;
My thread was waiting on the event so now continues, sees the FHasErrorCode then exits.
However, I think this will interfere with the TRtcDataRequest.AutoRepost setting.
I'd like TRtcDataRequest to try a seccond time if the connection fails, so should I, instead of signalling my TEvent in the OnConnectionLost event, do something like the following
Inc(FConnectionLostCount); //Keep track of how many tries we've done
FStream.Size := 0; //Delete any data already downloaded ready for a retry
if FConnectionLostCount = 2 then
begin
Sender.Disconnect;
FHasErrorCode := 1;
FWaitEvent.SetEvent;
end;
I hope the above makes sense?