From: Francis Cianfrocca Date: 2006-05-14T21:59:49+09:00 Subject: Nonblocking socket-connect ------=_Part_53665_23432963.1147611587006 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline All, I needed a nonblocking socket connect for my asynchronous-event framework, and I notice that ruby_connect blocks the calling thread with wait_connectable. I solved my problem with this (eliding some error-checkin= g and platform-specific branches): static VALUE sock_connect_nonblocking (self, addr) VALUE self, addr; { struct sockaddr_in *pin; int sd, val, outcome; pin =3D (struct sockaddr_in*)StringValuePtr (addr); sd =3D FIX2INT (rb_funcall (self, rb_intern ("fileno"), 0)); val =3D fcntl (sd, F_GETFL, 0); fcntl (sd, F_SETFL, val | O_NONBLOCK); outcome =3D connect (sd, (struct sockaddr*)pin, sizeof (*pin)); if (outcome < 0) rb_sys_fail ("connect_nonblocking"); return INT2FIX (outcome); } With this code, the caller rescues Errno::EINPROGRESS (or the platform equivalent) and waits for the socket to select writable. Did I miss something in socket.c? Are there any good reasons not to do this? ------=_Part_53665_23432963.1147611587006--