Forum: Ruby The ruby way of interrupting a Kernel::select?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
E4d8c6e0e9e5ca6ab51b4b1937586e6f?d=identicon&s=25 Christoffer Lernö (Guest)
on 2006-02-11 23:37
(Received via mailing list)
Hello everyone,

As a newbie with too much java-experience, I found it strange that I
couldn't interrupt the Kernel::select.

Basically what I wanted to do would be to interrupt the select as
soon as a socket decided it wanted to write something, and then add
that channel to the write-interest array.

I found no obvious way of doing that, so I made a hack around it: I
registered a pipe with the read-interest and every time I wanted to
write something then I would send a single byte on the pipe, which
would interrupt the select and allow me to register the socket with
the array.

I.e. something like this:


	@notifier, @requester = IO.pipe # this is my hack
		puts "Server started on port #{port} with handler #{@delegate}."
		while (true)
			@read = [@server, @notifier]
			@write =
			@error = [@server]
			@connections.each do |connection|
				@read << if
				@write << if connection.write
				@error << if
			read, write, error = Kernel::select(@read, @write, @error)
			@connections.each do |connection|
				connection.handle_read if read.include?
				connection.handle_write if write.include?
				connection.handle_error if error.include?
			@notifier.getc if read.include? @notifier
			handle_connect if read.include? @server


	def poke
		#this is a hack to interrupt Kernel::select
		puts "Poking!"
		@requester.putc "!"

Please tell me there's a better way! :)

This topic is locked and can not be replied to.