[ace-users] reactor handle events and event handlers

[ace-users] reactor handle events and event handlers

Post by David Gibb » Thu, 26 Apr 2007 01:53:51


i, I'm looking for some advice on event handling, Please see below.

ACE VERSION: 5.5

HOST MACHINE and OPERATING SYSTEM:
Intel P IV 2.8 Ghz, Win XP Prod v 2002, sp2, VC8

TARGET MACHINE and OPERATING SYSTEM, if different from HOST:
Same

THE $ACE_ROOT/ace/config.h FILE [if you use a link to a platform-
specific file, simply state which one]:

"#include "ace/config-win32.h"
"#define ACE_HAS_STANDARD_CPP_LIBRARY 1"

THE $ACE_ROOT/include/makeinclude/platform_macros.GNU FILE [if you
use a link to a platform-specific file, simply state which one
(unless this isn't used in this case, e.g., with Microsoft Visual
C++)]:

CONTENTS OF $ACE_ROOT/bin/MakeProjectCreator/config/default.features
(used by MPC when you generate your own makefiles):
n/a

AREA/CLASS/EXAMPLE AFFECTED:
[What example failed? What module failed to compile?]

Reactor/Event Handlers.

DOES THE PROBLEM AFFECT:
COMPILATION?
No
LINKING?
No
EXECUTION?
Yes
OTHER (please specify)?
N/A
[Please indicate whether ACE, your application, or both are
affected.]
My application only.

SYNOPSIS:
Question about reactor event handlers.

DESCRIPTION:
Are registered event handlers still registered after
handle_events (ACE_Time_Value &max_wait_time) or run_reactor_event_loop
returns ?

I've written some code that works if run_reactor_event_loop is
used (running on a background thread) but if I try using handle_events
(with a timeout) or timing out run_reactor_event_loop; events don't seem
to be handled thereafter if the event loop is restarted or handle_events
is called again.

I even tried re-registering the event handler.

Presumably I'm not following the paradigm nicely. I need to use
a select/poll style mechanism to handle a few serial consecutive events
(connecting and logging on to a service using a third party library)
before I can leave the reactor event loop to its own devices.
The event handler in fact calls a dispatch method back on the third
party library.
This third party code is not re-entrant so I thought handle_events would
be a convenient way to handle an event at a time before eventually
calling run_reactor_event_loop.

REPEAT BY:

class AnEventHandler : public ACE_Event_Handler {
public:
AnEventHandler (ACE_HANDLE queue) : queue(queue) {
DEBUG("AnEventHandler created");
}

/*
Initialises the event handler
*/
virtual void init() {
this->reactor()->register_handler(this,

ACE_Event_Handler::READ_MASK|ACE_Event_Handler::EXCEPT_MASK);
}

virtual ~AnEventHandler () {
DEBUG("AnEventHandler destroyed");
}

/*
Returns the handle for which this handler awaits events
*/
virtual void set_handle(ACE_HANDLE fd) {
DEBUG("AnEventHandler set_handle called, fd : " << fd);
queue = fd;
}


/*
Returns the handle for which this handler awaits events
*/
virtual ACE_HANDLE get_handle(void) const {
IG_DEBUG("AnEventHandler get_handle called " <<
this->queue);
return this->queue;
}

/*
Called when there is output to handle
*/
virtual int handle_output(ACE_HANDLE fd = ACE_INVALID_HANDLE) {
IG_DEBUG("AnEventHandler handle_output called");
return 0;
}
 
 
 

[ace-users] reactor handle events and event handlers

Post by Douglas C. » Thu, 26 Apr 2007 02:32:19

Hi David,

Thanks for the PRF.


Yes, indeed - they get removed only when you explicitly remove them or
when the Reactor's destructor is called.


Did you try calling

ACE_Reactor::instance ()->reset_reactor_event_loop ();

so that the event loop can be restarted?

Thanks,

Doug



 
 
 

[ace-users] reactor handle events and event handlers

Post by David Gibb » Thu, 26 Apr 2007 03:09:17

hanks Doug,
I tried that but it did not resolve the problem, which I think means
that I'm not using the correct approach as I expect reset would succeed
:-). The "connect events" are processed on the second call to
handle_events, after the first call to handle_events returns.
I've tried the reactor->notify(,,,) approach as well but it did not work
straight off so I will do some more testing of that just to prove to
myself that I understand how it is intended to work.
I think the right approach for this problem is to use a condition
variable on which the main thread will wait until it can do the next
step.
Dave

-----Original Message-----
From: XXXX@XXXXX.COM [mailto: XXXX@XXXXX.COM ]
Sent: 24 April 2007 18:32
To: David Gibbs
Cc: XXXX@XXXXX.COM
Subject: Re: [ace-users] reactor handle events and event handlers


Hi David,

Thanks for the PRF.

$ACE_ROOT/bin/MakeProjectCreator/config/default.features

Yes, indeed - they get removed only when you explicitly remove them or
when the Reactor's destructor is called.




Did you try calling

ACE_Reactor::instance ()->reset_reactor_event_loop ();

so that the event loop can be restarted?

Thanks,

Doug

const
ucontext_t *
should
notification
The information contained in this email is strictly confidential and for the use of the addressee only, unless otherwise indicated. If you are not the intended recipient, please do not read, copy, use or disclose to others this message or any attachment. Please also notify the sender by replying to this email or by telephone +44 (0)20 7896 0011 and then delete the email and any copies of it. Opinions, conclusions (etc.) that do not relate to the official business of this company shall be understood as neither given nor endorsed by it. IG Markets Limited and IG Index Plc are authorised and regulated by the Financial Services Authority and, in Australia, by the Australian Securities and Investments Commission.