comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <see.my.homepage@gmail.com>
Subject: Re: Ada and (SIGTERM?)
Date: Sat, 8 Aug 2009 08:06:23 -0700 (PDT)
Date: 2009-08-08T08:06:23-07:00	[thread overview]
Message-ID: <52dab4e5-9ee0-4e01-9072-32a95caadb84@j19g2000vbp.googlegroups.com> (raw)
In-Reply-To: 103641e8-0738-4b10-b2c6-cbfb53b50d98@d34g2000vbm.googlegroups.com

On 8 Sie, 15:11, Tomek Wałkuski <tomek.walku...@gmail.com> wrote:

> I cannot stop task if Do_Something is Accept_Socket from GNAT.Sockets.
>
> There is a listener which waits for client connections and then
> delegates jobs to the worker tasks. I want to stop all tasks and
> finalize all objects when SIGTERM is fired.

Use non-blocking I/O and a selector to wait for the sockets to become
ready.
You might need to set up a separate pair of sockets (one for writing
and one for reading - a socket-based implementation of a simple pipe)
which you can use to break out of the selector. This solution is very
scalable and can handle any number of listeners and regular sockets in
a single construct.

If you want to preserve the blocking I/O scheme in your program, you
can break out of Accept_Socket by establishing an artificial
connection to the listening socket. Just pretend to be your own client
and knock to your own door. :-)
When the Accept_Socket returns, check the "quit" flag to decide what
to do next. This flag should be set before establishing this
artificial connection to yourself, so that it is already set up when
Accept_Socket returns.

--
Maciej Sobczak * www.msobczak.com * www.inspirel.com

Database Access Library for Ada: www.inspirel.com/soci-ada



  reply	other threads:[~2009-08-08 15:06 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-05 19:58 Ada and (SIGTERM?) Tomek Walkuski
2009-08-06  1:06 ` Adam Beneschan
2009-08-06 18:13   ` sjw
2009-08-06 18:48     ` Adam Beneschan
2009-08-06 19:30   ` Tomek Wałkuski
2009-08-06 19:57     ` Jeffrey R. Carter
2009-08-06 20:02       ` Tomek Wałkuski
2009-08-06 20:00     ` okellogg
2009-08-08 13:11     ` Tomek Wałkuski
2009-08-08 15:06       ` Maciej Sobczak [this message]
2009-08-08 17:53         ` Tomek Wałkuski
2009-08-16 13:11           ` Tomek Wałkuski
2009-08-16 15:47             ` Maciej Sobczak
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox