How about this? My @who data structure is shared with a mutex between the
threads. It keeps a list of the thread id with each person’s username and
whatever who is logged on. When someone hangs up, Ruby just kills the
thread (I verified this with an experiment last night…)
I write a thread that wakes up every so often and checks Thread.current, and
compares that list with the list in @who, and if someone is missing from
Thread.current, zaps them from the list.
Is this a reasonable idea?
From: Jonathan Gillette [SMTP:firstname.lastname@example.org]
Sent: 21 June 2002 21:56
Subject: Re: detecting a socket dropping in multi-threaded app
Yeah, I forgot your client would be a simple telnet session. In the same
vein as a ping, you could have a thread watching for inactive threads and
shutting them down. So you could keep a timestamp on the last time a
thread read a byte and shutdown the thread if too much time elapsed. In
my Ruby socket servers, I tend to stay away from trying to catch all the
possible exceptions and just keep a single thread that monitors the
others. It’s just less of a headache. I guess I hate having to worry
about missing an exception.
NOTICE: This e-mail and any attachment(s) may contain confidential and
proprietary information of Goss International Corporation and/or its
subsidiaries and may be legally privileged. This e-mail is intended solely
for the addressee. If you are not the addressee, dissemination, copying or
other use of this e-mail or any of its content is strictly prohibited and
may be unlawful. If you are not the intended recipient please inform the
sender immediately and destroy the e-mail and any copies. All liability for
viruses is excluded to the fullest extent permitted by law. Any views
expressed in this message are those of the individual sender. No contract
may be construed by this e-mail.