From: "David S." Date: 2001-03-07T08:00:33+09:00 Subject: [ruby-talk:12190] Re: Nonblocking Read] On Wed, Mar 07, 2001 at 07:28:22AM +0900, Alex McHale wrote: > > The UNIX call for doing it would be something like > > > > fcntl(fd, F_SETFL, O_NONBLOCK) > > > > In Ruby you could do > > > > player.socket.fcntl(...) > > > > but I don't know if Ruby makes the constants 'F_SETFL' or 'O_NONBLOCK' > > available. You probably need to look the 'fcntl' man page on your > > system, and the 'fcntl.h' header file. > > Doing some examining of the Ruby source, and it appears that O_NONBLOCK is > imported as File::NONBLOCK, but I can't find any reference to a varient of > F_SETFL, nor any pointers on where I might find an equivalent / > possibilities for the Ruby fcntl cmds. > > With File::NONBLOCK being there, I have to assume there's a way to read > from a socket without blocking. The pickaxe book documents two paramaters for IO::fcntl ios.fcntl(anIntegerCmd, anArg) --> anInteger You've found File::NONBLOCK, presumably "anArg". On OpenBSD, FreeBSD, Linux, and Solaris '/usr/include/fcntl.h' defines 'F_SETFL' as 4, so I'd say 4 is a good bet for "anIntegerCmd". Now, in UNIX when you try to read from a non-blocking file stream with read(2) ('sysread' in Ruby) where there's no data present, or write to it with write(2) ('syswrite') when it's not ready, you get a return value of -1 and ERRNO set to EAGAIN or EWOULDBLOCK. In Ruby, I presume you'd get a 'SystemCallError' that you'll have to trap and check. Welcome to UNIX system programming. The standard reference is Stevens' 'Advanced Programming in the UNIX Environment'. David S. > > If anyone out there can help.. > > Alex McHale