Separate event loop and signal handling, reduces code duplication
Simplfy handling of the running flag in the event loop

Also set running to false in all cases in the Linux implementaion
and free the received events array.