Arno
I use multiple threads to read the data from sockets, I actually have a
thread pool that process data.
This is my current code for OnDataAvailable from sockets:
procedure TTCPSocketThread.HandleOnSocketDataAvailable(Sender: TObject;
ErrCode: Word);
begin
// We can´t proceed on errors
if ErrCode <> 0 then
Exit;
// Start the work
ScheduleAction(saReceiveData, 0);
end;
So, basically, it does not read the socket, but it schedules an action that
will be processed by my thread pool system, a thread will get the scheduled
action and will effectivelly read the socket.
The problem is that Do_FD_CLOSE will call my HandleOnSocketDataAvailable
routine, and since that does not read the data from socket, the library will
enter in an infinite loop, locking up my whole system
This is my worker thread execution routine (This routine is called by a
thread from the pool), I just left the relevant parts of the code here:
procedure TTCPSocketThread.Work;
var
Action: TSocketActionRecord;
begin
// Get the action to execute
Action := GetScheduledAction;
// Get a scheduled action and process it
case Action.Action of
..
..
// Action to receive data
saReceiveData: TriggerOnSocketDataAvailable(0);
end;
end;
My class TTCPSocketThread is basically an encapsulation of your socket, but
then OnSocketDataAvailable is triggered it will be triggered by a thread
from thread pool, this is required for my application since all the
processing done outside the class on the handler of the data should be
processed on threading and I found this was the best way to avoid many
buffering techniques
Hope you understand the problem I´m facing.
To temporarily fix the issue I changed my ICS code to:
if (FState <> wsConnecting) and (FHSocket <> INVALID_SOCKET) then begin
{ Check if we have something arrived, if yes, process it }
{ DLR, since we are closing MAKE SURE WE LOOP in the receive }
{ function to get ALL remaining data }
ASyncReceive(0, FComponentOptions);
That will call ASyncReceive with flag wsoNoReceiveLoop, allowing me not to
process the data, because if it is closing the socket I can lose the
remaining data anyway, this is video data
Do you use multiple threads or just one? If the latter you could simply
create and destroy the ICS object in TThread's Execute method.
If the first, receive in OnDataAvailable if wsoNoReceiveLoop is not set,
that cannot be much data after Do_FD_CLOSE has been called.
--
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