Éric Fleming Bonilha wrote: > Arno > > I use multiple threads to read the data from sockets, I actually have > a thread pool that process data.
Never done somthing like that, I guess you have to ensure that data is processed in the right order with such a design, as with Windows IOCP sockets as well. > > 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 [..] > Hope you understand the problem I´m facing. Yes, I understand, but there's a reason for doing this since it ensures that OnSessionClosed does not fire until winsock buffer is empty. > > 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 That may be a workaround in your special case if it doesn't matter to lose same packets, however that isn't a general solution. We have the same problem with SSL, where received encrypted data has to be decrypted first before SessionClosed may be triggered, the workaround is a derived component that overides Do_FD_Close. -- Arno Garrels -- 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