comp.lang.ada
 help / color / mirror / Atom feed
From: "Thomas Løcke" <thomas@12boo.net>
Subject: Tasking and timing out
Date: Thu, 20 Sep 2012 10:17:22 +0200
Date: 2012-09-20T10:17:22+02:00	[thread overview]
Message-ID: <505ad112$0$295$14726298@news.sunsite.dk> (raw)

Hey all,

I need to be able to be abandon a socket connection in a task and let
the task complete if:

a. the socket connect takes too long to complete

or

b. the Start task entry isn't called within a set timeframe

My current solution appears to do the trick just fine, but I'm not sure
if it's a "good" solution, specifically the nested select block pains
me to no end - I can't explain why though.   :)

Here's what I've got:

https://gist.github.com/3754529

Or without the fancy syntax highlighting from GitHub:


task body AMI_Action
is
begin
    select
       accept Start do
          select
             delay 2.0;
             raise AMI_Action_Error with Connect_Timed_Out_Message;
          then abort
             AWS.Net.Std.Connect (Socket => Action_Socket,
                                  Host => Config.Get (PBX_Host),
                                  Port => Config.Get (PBX_Port));
          end select;
       end Start;
    or
       delay 3.0;
       raise AMI_Action_Error with No_Call_On_Start_Received;
    end select;

    loop
       -- Mad socket action!
    end loop;
exception
    --  Catch exceptions, log issue and complete.
end AMI_Action;


The general idea is that if the call to AWS.Net.Std.Connect takes more
than 2 seconds to complete, then I raise an exception or if the Start
entry isn't called before 3 seconds have passed, then I also raise an
exception. In both cases I just want the task to log the issue and
complete.

It works - at least I haven't been able to make it fail in my tests,
it's just that I'm not sure if this is the right way to live up to the
requirements - maybe there's a better way?

Advice and/or suggestions are more than welcome.

-- 
Thomas L�cke | thomas@12boo.net | http://12boo.net



             reply	other threads:[~2012-09-20  8:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-20  8:17 Thomas Løcke [this message]
2012-09-20  8:53 ` Tasking and timing out Dmitry A. Kazakov
2012-09-20  9:36   ` Thomas Løcke
2012-09-20 10:21     ` Dmitry A. Kazakov
2012-09-20 20:40       ` Thomas Løcke
2012-09-20 18:33     ` Adam Beneschan
2012-09-20 20:43       ` Thomas Løcke
2012-09-20 21:24       ` sbelmont700
replies disabled

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