comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Aborting a call to Accept_Socket
Date: Tue, 21 Apr 2009 18:21:57 +0200
Date: 2009-04-21T18:21:59+02:00	[thread overview]
Message-ID: <5v74txgo3q9d$.cj2k983k72sh$.dlg@40tude.net> (raw)
In-Reply-To: 44d6b044-3cb8-402c-9b1f-afe39f6a47ce@r33g2000yqn.googlegroups.com

On Tue, 21 Apr 2009 08:40:13 -0700 (PDT), Tony wrote:

> I would like to abort a call to Accept_Socket() if no connection
> request arrives within a specified time (20 seconds).  For me, a quite
> simple solution (perhaps not safe) is to use an asynchronous transfer
> of control like this:
> --****************************************************
>    procedure Server is
>        ...
>    begin
>        GNAT.Sockets.Initialize;
>        ...
>        loop
>            ...
>            select
>                delay 20.0;
>                exit;
>            then abort
>                GNAT.Sockets.Accept_Socket (...);
>            end select;
>            ...
>        end loop ;
>    end Server;
> --****************************************************
> The expecting behaviour was the end of the program after 20 seconds
> (if no connection request arrives). I observe : after 20 seconds the
> program will terminate only if  a connection request arrives.
> Is this behaviour correct?

Yes, it is. Asynchronous transfer of control is not guaranteed to work with
an outstanding calls. Most likely it does not work as in this case. The
behavior is correct because Ada does not know how to abort a socket
operation in order to implement this statement. Ada RM contains a list of
abort deferred things, which includes potentially any call to any external
operation. Specifically for sockets there is a solution: you close the
socket from another task. That will kill accept with an error code.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2009-04-21 16:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-21 15:40 Aborting a call to Accept_Socket Tony
2009-04-21 16:21 ` Dmitry A. Kazakov [this message]
2009-04-21 16:32   ` Tony
2009-04-21 17:34   ` Adam Beneschan
2009-04-21 19:02     ` sjw
2009-04-21 21:03 ` Maciej Sobczak
2009-04-21 23:24 ` anon
replies disabled

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