2005/10/11, snacktime <snacktime / gmail.com>:
> >
> >
> >
> > You architecture is not fully clear to me, but given the small about of
> > sources and sinks I'd use a thread per source and either do the processing
> > directly in that thread or push tasks down a queue. IMHO this is far
> > easier in this case than writing a select loop that does the multiplexing.
> > Does that sound reasonable to you?
>
>
>
> It was late and my brain was tired.. My question really involved around the
> best way to constantly read from a socket in ruby and at the same time be
> able to detect when a client connects with data that needs to be written to
> the socket.

Here's a typical example which uses a reader thread per client

.require 'socket'
.port = (ARGV[0] || 80).to_i
.server = TCPServer.new('localhost', port)
.while (session = server.accept)
.  Thread.new(session) do |sess|
.    puts "Request: #{sess.gets}"
.    sess.print "HTTP/1.1 200/OK\r\nContent-type: text/html\r\n\r\n"
.    sess.print "<html><body><h1>#{Time.now}</h1></body></html>\r\n"
.    # other stuff
.    sess.close
.  end
.end

Derived from
http://www.ruby-doc.org/docs/ProgrammingRuby/html/lib_network.html

> After looking around some more it looks like in the thread that holds the
> connection to asterisk a simple loop combined with io/wait would work. Any
> reason to use io/wait over select in a case like this?

As I said, IMHO it's simpler and cleaner.  Otherwise you'll be
implementing the multiplexing loop with select in Ruby which is
implemented in the interpreter in C anyway.  Using select seems only
appropriate to me if the number of descriptors becomes very large.

Kind regards

robert