comp.lang.ada
 help / color / mirror / Atom feed
* Aborting a call to Accept_Socket
@ 2009-04-21 15:40 Tony
  2009-04-21 16:21 ` Dmitry A. Kazakov
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Tony @ 2009-04-21 15:40 UTC (permalink / raw)


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?
Thanks.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Aborting a call to Accept_Socket
  2009-04-21 15:40 Aborting a call to Accept_Socket Tony
@ 2009-04-21 16:21 ` Dmitry A. Kazakov
  2009-04-21 16:32   ` Tony
  2009-04-21 17:34   ` Adam Beneschan
  2009-04-21 21:03 ` Maciej Sobczak
  2009-04-21 23:24 ` anon
  2 siblings, 2 replies; 7+ messages in thread
From: Dmitry A. Kazakov @ 2009-04-21 16:21 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Aborting a call to Accept_Socket
  2009-04-21 16:21 ` Dmitry A. Kazakov
@ 2009-04-21 16:32   ` Tony
  2009-04-21 17:34   ` Adam Beneschan
  1 sibling, 0 replies; 7+ messages in thread
From: Tony @ 2009-04-21 16:32 UTC (permalink / raw)


On 21 avr, 18:21, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> 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. Kazakovhttp://www.dmitry-kazakov.de

That's what I suspected, thanks a lot for your confirmation.
Regards.
Tony.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Aborting a call to Accept_Socket
  2009-04-21 16:21 ` Dmitry A. Kazakov
  2009-04-21 16:32   ` Tony
@ 2009-04-21 17:34   ` Adam Beneschan
  2009-04-21 19:02     ` sjw
  1 sibling, 1 reply; 7+ messages in thread
From: Adam Beneschan @ 2009-04-21 17:34 UTC (permalink / raw)


On Apr 21, 9:21 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> 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.

I think you also have to think about what happens to the client when
an incoming connection request comes after 19.999999 seconds...  It
may be too remote a problem to worry about, but in some circumstances
it could be important.

                             -- Adam





^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Aborting a call to Accept_Socket
  2009-04-21 17:34   ` Adam Beneschan
@ 2009-04-21 19:02     ` sjw
  0 siblings, 0 replies; 7+ messages in thread
From: sjw @ 2009-04-21 19:02 UTC (permalink / raw)


On Apr 21, 6:34 pm, Adam Beneschan <a...@irvine.com> wrote:

> I think you also have to think about what happens to the client when
> an incoming connection request comes after 19.999999 seconds...  It
> may be too remote a problem to worry about, but in some circumstances
> it could be important.

Dealing with errant networked peers leads to a maze of twisty race
conditions ... and they _will_ bite you!



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Aborting a call to Accept_Socket
  2009-04-21 15:40 Aborting a call to Accept_Socket Tony
  2009-04-21 16:21 ` Dmitry A. Kazakov
@ 2009-04-21 21:03 ` Maciej Sobczak
  2009-04-21 23:24 ` anon
  2 siblings, 0 replies; 7+ messages in thread
From: Maciej Sobczak @ 2009-04-21 21:03 UTC (permalink / raw)


On 21 Kwi, 17:40, Tony <truand.t...@gmail.com> wrote:
> I would like to abort a call to Accept_Socket() if no connection
> request arrives within a specified time (20 seconds).

Then you want to use the selector with timeout.
In order to wait for the listening socket put it in the "reading"
selector set.
If the Check_Selector finishes with the Status equal to Completed, it
means that you can call Accept_Socket without blocking, because there
is an incoming connection pending. Otherwise the timeout has expired,
which means that there was no incoming connection during the given
time.

> For me, a quite
> simple solution (perhaps not safe) is to use an asynchronous transfer
> of control

Unfortunately there is no integration of ATC and I/O.
Expecially when it comes to non-standard I/O.

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

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



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Aborting a call to Accept_Socket
  2009-04-21 15:40 Aborting a call to Accept_Socket Tony
  2009-04-21 16:21 ` Dmitry A. Kazakov
  2009-04-21 21:03 ` Maciej Sobczak
@ 2009-04-21 23:24 ` anon
  2 siblings, 0 replies; 7+ messages in thread
From: anon @ 2009-04-21 23:24 UTC (permalink / raw)


You must use the Selectors routines in the Socket package.

Then set the Timout parameter to 20 second in procedure Check_Selector.  
This routine will wait until an event has occured.  Once returned then you 
can check the return value for the parameter Status to determine which one 
of the following three events has occured: Completed, Expired, or Aborted.

   --  Complete: one of the expected events occurred
   --  Expired:  no event occurred before the expiration of the timeout
   --  Aborted:  an external action cancelled the wait operation before
   --            any event occurred.



In <44d6b044-3cb8-402c-9b1f-afe39f6a47ce@r33g2000yqn.googlegroups.com>, Tony <truand.tony@gmail.com> writes:
>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?
>Thanks.




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2009-04-21 23:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-21 15:40 Aborting a call to Accept_Socket Tony
2009-04-21 16:21 ` Dmitry A. Kazakov
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

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