From: Henrik Warne Date: 2004-09-07T00:47:09+09:00 Subject: Can't get non-blocking TCP connect to work Hello, I am trying to do a non-blocking connect for a TCP connection, and I can't get it to work. I have googled a lot without finding a solution. I do the following in ruby: #!/usr/bin/env ruby require 'socket' require 'fcntl' client = Socket.new(Socket::PF_INET, Socket::SOCK_STREAM, 0) flags = client.fcntl(Fcntl::F_GETFL, 0) client.fcntl(Fcntl::F_SETFL, flags | Fcntl::O_NONBLOCK) flags = client.fcntl(Fcntl::F_GETFL, 0) sockaddr = [Socket::AF_INET, 80, 10, 2, 20, 250, ''].pack('snCCCCa8') client.connect(sockaddr) client.send("GET something HTTP/1.1\r\n\r\n", 0) $res = client.readlines client.close puts $res There is no contact with 10.2.20.250:80, and I want the connect call to return immediately with EINPROGRESS (or similar), so I can use select to decide how long to wait before giving up (I haven't added the code to do that since I can't get the connect to return immediately). As it is now, the connect call hangs for three and a half minutes before returning "Exception: Connection timed out - connect(2)" I can successfully do this in C++ on the same machine, so I know it can work. Am I missing something in the ruby code, or have I misunderstood something? I've tried this in ruby 1.6.8 (2002-12-24) [i386-linux] and ruby 1.8.1 (2003-12-25) [i686-linux], and I'm using Debian GNU/Linux 3.0. Thanks in advance. /Henrik Warne