summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--examples/Reactor/Misc/pingpong.cpp31
2 files changed, 25 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index e23ae46e5fa..ff06a013e0c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Sat Apr 30 15:24:13 2005 Douglas C. Schmidt <schmidt@cs.wustl.edu>
+
+ * examples/Reactor/Misc/pingpong.cpp (run_svc): Allocate the
+ Ping_Pong callback dynamically to avoid crashses when things
+ close down. Thanks to Johnny Willemsen for narrowing down the
+ problem and to Alex Ott <ott@jet.msk.su> for reporting it.
+
Fri Apr 29 23:45:59 2005 Ossama Othman <ossama@dre.vanderbilt.edu>
* examples/Bounded_Packet_Relay/BPR_Drivers.cpp:
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)
{