[Patch] Rewritten SimpleIPC implementation for Windows
Original Reporter info from Mantis: dezlov
-
Reporter name: Denis Kozlov
Original Reporter info from Mantis: dezlov
- Reporter name: Denis Kozlov
Description:
Patches here fix several issues with SimpleIPC on Windows.
Summary of changes:
- Using SetTimer + GetMessage method for handling PeekMessage.
- Store all received incoming messages in a message queue (per IPC server instance).
- Implemented message queue (PeekMessage receives messages, ReadMessage picks from the queue)
- Implemented optional message queue limit and overflow handling (more on that below).
- Timeout<-1 is forced to -1; Documented meaning of various Timeout values in comments.
- Minor refactoring and code formatting changes.
All these changes currently affect only the Windows implementation. The main IPC interface has not changed. This allows to fix all major issues on Windows and test the new concept of buffering/queueing IPC messages.
A new global type was introduced:
TIPCMessageOverflowAction = (ipcmoaNone, ipcmoaDiscardOld, ipcmoaDiscardNew, ipcmoaError);
Added two global variables which configure message queue limit and overflow handling (affect newly created IPC servers):
DefaultIPCMessageOverflowAction: TIPCMessageOverflowAction = ipcmoaNone;
DefaultIPCMessageQueueLimit: Integer = 0;
Currently these are used only in Windows implementation, but they need to be in the interface section to allow unit testing and perhaps later reuse on other platforms.
The second part is a comprehensive test suite for Windows implementation of SimpleIPC. Tests spawn client mode instances as needed for proper testing of IPC. Tests check handling of messages, processing delays, synchronicity and message queue overflow actions. Read comments for each test routine for additional information. All timing based checks are very relaxed and can be controlled by IPC_BASETIME constant (a base line time per message in milliseconds), which can be increased for really-really slow machines. Simply compile and run. Exception is raised if any errors occur.
Other platforms will fail most tests due to not implemented featured, such as message queue and overflow handling. Perhaps it could be added to FPC test suite for Windows platform only, but I'm not sure how suitable it is due to complexity of multiple processes and timing checks.
I also tested separately for compatibility with Lazarus message loop by using PeekMessage(0, True) in Application.OnIdle, it works perfectly.
Attached files (full copies included for convenience; patches against FPC trunk revision 32628 from 10 Dec 2015):
- testipc.pas/testipc.out.txt - tests for SimpleIPC and example output.
- simpleipc.pp/simpleipc.pp.patch - patch and a full copy of main SimpleIPC unit.
- simpleipc.inc/simpleipc.inc.patch - patch and a full copy of Windows include file (not Windows CE).
Additional information:
As per discussion in the mailing list:
http://lists.freepascal.org/pipermail/fpc-devel/2015-December/036437.html
Mantis conversion info:
- Mantis ID: 29346
- Platform: Windows
- Fixed in version: 3.1.1
- Fixed in revision: 32859 (#072b473f)
- Monitored by: » dezlov (Denis Kozlov)
- Target version: 3.0.2