How to kill a Thread into GServer "def server(io)" method?

Hi, I’m using GServer and in “serve” method I read a string from a TCP
socket:

line = io.gets("\n")

but it can occur that the TCP connection is closed so “gets” return NIL.
In this case I just one to terminate this thread, no more.

The only way I get it working is doing:

line = io.gets("\n")
Thread.current.terminate if !line # terminate = kill = exit

Is it the appropiate way? I read the method doc but don’t understand
what exactly it does:

thr.terminate
Terminates thr and schedules another thread to be run,
returning the terminated Thread. If
this is the main thread, or the last thread, exits the process.

Thanks for any explanation.

On Thu, Mar 27, 2008 at 11:31 AM, Iñaki Baz C. [email protected]
wrote:

The only way I get it working is doing:

line = io.gets(“\n”)
Thread.current.terminate if !line # terminate = kill = exit

Looking at the code in:

http://ruby-doc.org/stdlib/libdoc/gserver/rdoc/classes/GServer.html#M000757

I think you can just return from the method and be happy. You can
also raise an exception which will be caught and logged as an error if
you set the debug attribute to a true value.

Marcelo

El Jueves, 27 de Marzo de 2008, Marcelo escribió:

I think you can just return from the method and be happy.
Yes, that’s true. A simple return works well :slight_smile:

Thanks.