This now utilizes Snooze in order to have the server wake up to process RCON commands ondemand, similar to how the CommandReader thread operates. This is better for performance and response times.
This also makes a few other changes:
- RCON thread will now waste less CPU since it uses a blocking select() with timeout to read
- Following from that, IPC sockets are used to allow interrupting select() from the RCON thread.
- Multiple threads for RCON has been removed (this is entirely unnecessary, reading data from sockets is not CPU-intensive, and a single thread is easier to work with)
in some cases the main thread was trying to signal the server killer to stop before it was even started due to limited resources available for scheduling.
ArrayOutOfBoundsException is not thrown by SPL anymore since the exception handler throwing it was removed by @shoghicp. Regardless, it seems cleaner to to check it properly.
This allows other threads to notify the main thread to wake it up while it's sleeping between ticks, allowing reduction of processing latency.
Currently only RakLib and the CommandReader threads utilize this, but it's planned to extend it to more things in the near future.
CommandReader is now event-driven instead of poll-based - the server will not poll the CommandReader thread for messages each tick anymore.
RakLib utilizes this mechanism to get packets processed without delays to lower latency.
This now adds an extra dependency - `pocketmine/snooze` library contains the meat of the code used for this. See the Snooze repository for details.
pthreads doesn't play well with resources, and this code upsets it. Also, this code is utterly pointless.
The whole of RCON needs burning to the ground...
It is somewhat reasonable to have a function in an event handler which accepts an Event parameter, but is not a handler. For example, multiple event handlers can redirect to the same function to process an event, but this function may not want to receive called events.
There are other ways to get around this, such as making the event handler protected/private, or adding a dummy parameter, but this way is cleaner and more explicit.
Relevant old-repo PR: PocketMine/PocketMine-MP#2143