See

staticVALUEsock_connect_nonblock(VALUEsock,VALUEaddr){rb_io_t*fptr;intn;SockAddrStringValue(addr);addr=rb_str_new4(addr);GetOpenFile(sock,fptr);rb_io_set_nonblock(fptr);n=connect(fptr->fd,(structsockaddr*)RSTRING_PTR(addr),RSTRING_LENINT(addr));if(n<0){if(errno==EINPROGRESS)rb_mod_sys_fail(rb_mWaitWritable,"connect(2) would block");rb_sys_fail("connect(2)");}returnINT2FIX(n);}