Refactor different variants of waiting for the connection socket.

Reduce the 4 variants of waiting to only 2 which are used by both

This also fixes 'Bad file descriptor' respectively wrong behaviour
of #wait_for_notify() on Windows and fixes timeout handling of

Make use of rb_thread_fd_select() on Ruby 1.9, to avoid deprecation
warnings on rb_thread_select().
Free memory allocated per rb_fd_init().