summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorschmidt <douglascraigschmidt@users.noreply.github.com>2005-04-30 22:15:05 +0000
committerschmidt <douglascraigschmidt@users.noreply.github.com>2005-04-30 22:15:05 +0000
commit7412e4d6683fd930ddd69fef56e774d2050fe2e4 (patch)
tree529c6ccdb40509affa07a2dd362e92d1f94b22e2 /examples
parent44df52d3020ea2c029fd18a0054b033596d133ba (diff)
downloadATCD-7412e4d6683fd930ddd69fef56e774d2050fe2e4.tar.gz
ChangeLogTag:Sat Apr 30 15:24:13 2005 Douglas C. Schmidt <schmidt@cs.wustl.edu>
Diffstat (limited to 'examples')
-rw-r--r--examples/Reactor/Misc/pingpong.cpp31
1 files changed, 18 insertions, 13 deletions
diff --git a/examples/Reactor/Misc/pingpong.cpp b/examples/Reactor/Misc/pingpong.cpp
index 337aa4c063f..032495b00ed 100644
--- a/examples/Reactor/Misc/pingpong.cpp
+++ b/examples/Reactor/Misc/pingpong.cpp
@@ -65,7 +65,8 @@ public:
virtual int handle_output (ACE_HANDLE);
virtual int handle_timeout (const ACE_Time_Value &,
const void *);
-
+ virtual int handle_close (ACE_HANDLE handle,
+ ACE_Reactor_Mask close_mask);
private:
char buf_[BUFSIZ];
// Buffer to send.
@@ -98,6 +99,14 @@ Ping_Pong::get_handle (void) const
return this->handle_;
}
+int
+Ping_Pong::handle_close (ACE_HANDLE,
+ ACE_Reactor_Mask)
+{
+ delete this; // Cleanup when we're removed from the reactor.
+ return 0;
+}
+
int
Ping_Pong::handle_input (ACE_HANDLE)
{
@@ -193,28 +202,24 @@ static const int SHUTDOWN_TIME = 10;
static void
run_svc (ACE_HANDLE handle)
{
- // The <callback> object is an <ACE_Event_Handler> created on the
- // stack. This is normally not a good idea, but in this case it
- // works because the ACE_Reactor is destroyed before leaving this
- // scope as well, so it'll remove the <callback> object from its
- // internal tables BEFORE it is destroyed.
- Ping_Pong callback (ACE_TEXT_ALWAYS_CHAR (string_name), handle);
-
- // Note that we put the <reactor> AFTER the <callback> so that the
- // <reactor> will get shutdown first.
+ Ping_Pong *callback = 0;
+ ACE_NEW (callback,
+ Ping_Pong (ACE_TEXT_ALWAYS_CHAR (string_name),
+ handle));
+
ACE_Reactor reactor;
// Register the callback object for the various I/O, signal, and
// timer-based events.
- if (reactor.register_handler (&callback,
+ if (reactor.register_handler (callback,
ACE_Event_Handler::READ_MASK
| ACE_Event_Handler::WRITE_MASK) == -1
#if !defined (CHORUS)
|| reactor.register_handler (SIGINT,
- &callback) == -1
+ callback) == -1
#endif /* CHORUS */
- || reactor.schedule_timer (&callback,
+ || reactor.schedule_timer (callback,
0,
SHUTDOWN_TIME) == -1)
{