Forum: Ruby Block reading from socket and STDIN

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3a831be2a4aa6d4fa02d5184b5757a82?d=identicon&s=25 Giuseppe Parlavecchio (massimiliano)
on 2009-02-26 10:33
Hi I am pretty new in ruby, may be this topic has already been discussed
here. But I start running out of resources.
I am on a Windows XP PC and I am using ruby186-26.

I am writing a client/Multiplexing Server socket application,
(I took most of the code from the manual).

The server application, beside to listening on the socket via the
select(...), must listening at the standard input. This is because a
user has to give input to the server while he is handling the socket
connection to clients.

The problem I found is that the select(...) and the STDIN.gets methos
are both blocking also if I run it on two different threads.

Many thanks
Fa2521c6539342333de9f42502657e5a?d=identicon&s=25 Eleanor McHugh (Guest)
on 2009-02-26 11:02
(Received via mailing list)
On 26 Feb 2009, at 09:32, Giuseppe Parlavecchio wrote:
> user has to give input to the server while he is handling the socket
> connection to clients.
>
> The problem I found is that the select(...) and the STDIN.gets methos
> are both blocking also if I run it on two different threads.


This is off the top of my head, so apologies if it's wrong, but as
STDIN is a regular IO object you _should_ be able to handle its input
from the same select(...) call as the server socket.

Ellie

Eleanor McHugh
Games With Brains
http://slides.games-with-brains.net
----
raise ArgumentError unless @reality.responds_to? :reason
42773b24e0c3fb506a8a875c058a9dd7?d=identicon&s=25 Dylan Evans (Guest)
on 2009-02-26 12:41
(Received via mailing list)
Pretty sure gets doesn't actually block. I believe it is implemented
with a
select internally.

Try this as a test
Thread.new {
  loop {
    puts "loop "
  }
}
STDIN.gets

If it stops then gets is blocking



On Thu, Feb 26, 2009 at 8:01 PM, Eleanor McHugh <
47b1910084592eb77a032bc7d8d1a84e?d=identicon&s=25 Joel VanderWerf (Guest)
on 2009-02-28 21:42
(Received via mailing list)
Giuseppe Parlavecchio wrote:
> connection to clients.
>
> The problem I found is that the select(...) and the STDIN.gets methos
> are both blocking also if I run it on two different threads.
>
> Many thanks

Windows + STDIN.gets == ruby blocks other threads, sorry to say.

At least, that's my experience in ruby186. Maybe this has changed more
recently?
This topic is locked and can not be replied to.