Do not write to unconnected event pipe.

If a event pipe is not connected it is a bad idea to write something
there pretending it is connected. Hence, close and reset descriptor
to -1 in case of connection error.