From: nobu.nokada@... Date: 2003-03-19T07:51:57+09:00 Subject: Re: How to get the Windows handle for a socket Hi, At Wed, 19 Mar 2003 07:03:09 +0900, Tom Felker wrote: > On Windows, I do the following (trying to get a nonblocking socket): > > f=Win32API.new("ws2_32", "ioctlsocket", ["l", "l", "l"], 'i') > s=TCPServer.new(15000) > f.call(s.fileno, 2147772030, 1) #FIONBIO Currently ruby's on Windows (except for bccwin32 in 1.8) use Winsock, and I don't know whether Winsock and Winsock2 can work each together. > This returns 10038, "Not a socket," instead of 0, "Success." s.fileno > is 3. On Windows, sockets are simply handles, which don't need to be > low integers like 3, and usually aren't. > > What I need is to get the real handle to the socket. (Or any other way > to set a socket nonblocking in Windows.) This might work for mingw32 and mswin32. Win32API.new("msvcrt", "_get_osfhandle", "I", "I").call(s.fileno) > Also, a way to make TCPSocket.new not block would be nice. I'm trying > to make a chat program, and it needs to stay responsive, so it uses the > GUI toolkit's functions to register a callback when the socket is > selected for. Note that non-blocking IO doesn't work fine in 1.6, i.e., already recevied data will be lost at EAGAIN. This issue has been fixed in 1.8. -- Nobu Nakada