Can I use Exit after adding a Queue command in the TIdTCPServer.OnExecute event?
if condition then
begin
MyNotify := TMyNotify.Create;
MyNotify.FMyData := Format('%s > %d > %s, [TimeToStr(Now), AContext.Connection.Socket.Binding.Handle, AContext.Binding.PeerIP]);
MyNotify.Notify;
Con.Queue.Add('DCCUSTOMER');
exit;
end;
Or will it cause deadlocks, or other problems?
Exit
in the TIdTCPServer.OnExecute
event handler. The OnExecute
event is fired in a continuous loop for the lifetime of the TCP connection. Exiting from the OnExecute
handler is perfectly normal, the event will simply be fired again. This allows you to write simpler handler code, as you only have to write code for one iteration at a time. The most common use-case is to read and process one command and then exit (implicitly or explicitly, it doesn't matter), repeating for the next command when the event is fired again.
Closing the socket, or raising an uncaught exception, will terminate the loop.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.