Use a better variable name than 'tmp'
Remove excess indentation
send_event_sockets checks for a NULL msg
Remove unused code
Bail on the socket if things fail
Handle only a single reply at a time

Things are still gated by a cookie, but now there's not a buffer to fill
up over time with junk replies.
Kill an annoying warning
Add a timeout for replies

Avoid a deadlock due to a non-responsive event manager.
Remove nasty cookie hack

Since there's only one request out at a time, we don't have to worry
about duplicating cookies. For this, g_random_int should be good enough.