Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

RE: [ace-users] timeout function?

2 views
Skip to first unread message

David Hawkins

unread,
May 5, 2005, 3:11:56 PM5/5/05
to

> Hello to all, I need your help on a simple problem
> I created a broadcast system so my client can find
> where all the servers are, which can be a variable
> number between 1 and unknown.
>
>
> Therefore I created and infinite loop where I wait
> for datagrams and then get their remote host name
> obviously this isn't good enough because I never get
> out of the loop, therefore I was thinking of inserting
> an ace timeout, but this doesn't work.

Its a bit difficult to determine what kind of timeout
you used - so we can tell you why it didn't work.
What ACE timeout parameter are you referring to?

> Also the only thing this time out must do is get me
> out of the loop and continue on with the instructions
> of the code right out of the while loop.
>
> I know it is simple, probably the answer is only a
> simple function, but I can't find it, and I really REALLY
> need it: can anyone help me?

There is always the use of threads ....

- create and start a server locate thread
- main thread drops into an ACE_OS::sleep()
- main thread wakes up and requests that the
server locate thread finish (it might have already)
- main thread joins with server locate thread.
- carry on.

Or use a Reactor model. The reactor could have a timer setup,
and whatever reactive handling is possible with your
server UDP packets (although I have not used UDP before,
so I can't comment on how it integrates with the Reactor
model).

Cheers
Dave Hawkins
Caltech.


DJ Stachniak

unread,
May 5, 2005, 3:12:05 PM5/5/05
to
Have you thought about using the reactor framework
here? Even for something as trivial as what you are
doing it seems ideal and IMO doesn't add that much
overhead considering what you get out of it. You
could even write a handle timeout in your event
handler to get the behavior it sounds like you're
looking for.

Check out the reactor chapters in C++NPv2 and APG for
more info. There's also a datagram reactor example
that ships with ACE.


--- Claudio <pas...@email.it> wrote:
> Hello to all, I need your help on a simple problem
> I created a broadcast system so my client can find
> where all the servers
> are, which can be a variable number between 1 and
> unknown.
>
>
> Therefore I created and infinite loop where I wait
> for datagrams and
> then get their remote host name
>

> Int main ()
> {
> while (true)
> {
> receive the datagram


> }
> }
>
> obviously this isn't good enough because I never get
> out of the loop,
> therefore I was thinking of inserting an ace
> timeout, but this doesn't
> work.

> Also the only thing this time out must do is get me
> out of the loop and
> continue on with the instructions of the code right
> out of the while
> loop.
>
>
> I know it is simple, probably the answer is only a
> simple function, but
> I can't find it, and I really REALLY need it: can
> anyone help me?
>
>

> Thanks to all
> Claudio Capuzzo
>
>
>
> --
> Email.it, the professional e-mail, gratis per te:
> http://www.email.it/f
>
> Sponsor:
> Hai 5 minuti per avvisare tutti i tuoi colleghi che
> la riunione h stata spostata...che fai?
> * Semplice! Invii un SMS da Email.it al gruppo
> "colleghi"!!
> Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=3389&d=5-5

D.J. Stachniak
djsta...@yahoo.com


David Hawkins

unread,
May 5, 2005, 4:09:06 PM5/5/05
to

> ACE_Time_Value timeout (2,0)

This is just a time VALUE, i.e., a data type representing time.
The first parameter is in seconds, the second in microseconds
(timeval format).

If you want to sleep for 2 seconds, then:

ACE_Time_Value sleeptime(2,0);
ACE_OS::sleep(sleeptime);

if you want to pass a pointer to a timeout then

ACE_Time_Value timeout(2,0);
someclass.send(<data>, &timeout);

where timeouts to functions are often pointers so that 0
means to block indefinitely.

Dave


Douglas C. Schmidt

unread,
May 5, 2005, 5:45:06 PM5/5/05
to
Hi Folks,

>> Check out the reactor chapters in C++NPv2 and APG for
>> more info. There's also a datagram reactor example
>> that ships with ACE.

Yes, indeed! Check out

ACE_ROOT/examples/Reactor/Dgram/

Thanks,

Doug
--
Dr. Douglas C. Schmidt Professor and Associate Chair
Electrical Engineering and Computer Science TEL: (615) 343-8197
Institute for Software Integrated Systems WEB: www.dre.vanderbilt.edu/~schmidt
Vanderbilt University, Nashville TN, 37203 NET: d.sc...@vanderbilt.edu

0 new messages