From: Tanaka Akira Date: 2004-11-27T04:01:01+09:00 Subject: Re: [ANN] Multiplexer - linear non-blocking I/O In article <01ec01c4d3e3$68209820$6442a8c0@musicbox>, "Bill Kelly" writes: > Strange... I'm surprised there are too many differences between > your select multiplexer using continuations and a threads solution, > since: a) ruby uses select() to multiplex behind the scenes when > multiple threads are doing I/O; and b) ruby continuations are > implemented using threads. Because write(2) system call blocks until whole data is written unless nonblocking flag is set, even after select notify the fd is writable. The multiplexer works well because it sets nonblocking flag. The threaded server also works well if it sets nonblocking flag. Try: require 'socket' require 'fcntl' server = TCPServer.new 12345 t_a = Thread.start do a = server.accept a.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK) data = "foo" * 10000000 a << data a.close end b = server.accept b.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK) b << "b" b.close t_a.join However nonblocking flag with stdio buffering may cause data lost... -- Tanaka Akira