summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschmidt <douglascraigschmidt@users.noreply.github.com>1997-03-22 21:03:22 +0000
committerschmidt <douglascraigschmidt@users.noreply.github.com>1997-03-22 21:03:22 +0000
commitcf65201234014d5509a3b635e6be5924909a5e07 (patch)
treef4b9df9dbe9edda1ce7d4cb05afd67b4bcd2d05b
parentd726503942f934532a5a91077303150dae1d638c (diff)
downloadATCD-cf65201234014d5509a3b635e6be5924909a5e07.tar.gz
*** empty log message ***
-rw-r--r--ChangeLog-97a18
-rw-r--r--ace/Connector.cpp11
-rw-r--r--ace/Connector.h4
-rw-r--r--ace/Svc_Handler.cpp27
-rw-r--r--ace/config-hpux-10.x-g++.h1
-rw-r--r--examples/Logger/simple-server/Logging_Handler.cpp1
-rw-r--r--examples/Reactor/Multicast/client.cpp75
-rw-r--r--examples/Reactor/Multicast/server.cpp95
-rw-r--r--netsvcs/lib/TS_Clerk_Handler.cpp6
-rw-r--r--netsvcs/lib/Token_Handler.cpp3
10 files changed, 152 insertions, 89 deletions
diff --git a/ChangeLog-97a b/ChangeLog-97a
index 16dbecafd6e..d7d2526b1c6 100644
--- a/ChangeLog-97a
+++ b/ChangeLog-97a
@@ -1,5 +1,23 @@
Sat Mar 22 12:06:22 1997 Douglas C. Schmidt <schmidt@flamenco.cs.wustl.edu>
+ * examples/Reactor/Multicast: Improved the multicast client and
+ server programs to work better.
+
+ * ace/Connector.cpp: Modified the ACE_Connector::handle_close()
+ method to prevent recursive calls to itself. Thanks to Paul Han
+ <phan@CCGATE.HAC.COM> for reporting this.
+
+ * ace/Svc_Handler.cpp: Put the check (closing_ == 0) in the
+ destructor as well as in the destroy() method. This prevents a
+ possible core dump when the timer exists. The instruction
+ reactor::remove_handler in the shutdown method currently will be
+ called twice when ACE_Svc_Handler object is being deleted. Core
+ dump occurs when it tries to execute ACE_Reactor::remove_handler
+ method the second time because the ACE_Svc_Handler object
+ pointer has already been deleted by the previous instruction
+ ACE_Reactor::cancel_timer. Thanks to Paul Han
+ <phan@CCGATE.HAC.COM> for reporting this.
+
* ace/OS.cpp: Added new thread-safe implementations of writev()
and readv() for platforms that lack these functions.
diff --git a/ace/Connector.cpp b/ace/Connector.cpp
index e0585dd1711..2339549c475 100644
--- a/ace/Connector.cpp
+++ b/ace/Connector.cpp
@@ -123,6 +123,7 @@ ACE_Connector<SH, PR_CO_2>::open (ACE_Reactor *reactor)
{
ACE_TRACE ("ACE_Connector<SH, PR_CO_2>::open");
this->reactor_ = reactor;
+ this->closing_ = 0;
return 0;
}
@@ -442,9 +443,15 @@ ACE_Connector<SH, PR_CO_2>::handle_close (ACE_HANDLE, ACE_Reactor_Mask mask)
{
ACE_TRACE ("ACE_Connector<SH, PR_CO_2>::handle_close");
- if (this->reactor_ != 0)
+ if (this->reactor_ != 0 && this->closing_ == 0)
{
- // Remove all timer objects from the Reactor's Timer_Queue.
+ // We're closing down now, so make sure not to call ourselves
+ // recursively via other calls to handle_close() (e.g., from the
+ // Timer_Queue).
+ this->closing_ = 1;
+
+ // Remove all timer objects associated with <this> object from
+ // the <Reactor>'s Timer_Queue.
this->reactor_->cancel_timer (this);
MAP_ITERATOR mi (this->handler_map_);
diff --git a/ace/Connector.h b/ace/Connector.h
index a20da7fcdf3..8f800e8cb54 100644
--- a/ace/Connector.h
+++ b/ace/Connector.h
@@ -253,6 +253,10 @@ private:
ACE_Reactor *reactor_;
// Event demultiplex associated with this object.
+
+ char closing_;
+ // Keeps track of whether we are in the process of closing (required
+ // to avoid circular calls to <handle_close>).
};
#include "ace/Connector.i"
diff --git a/ace/Svc_Handler.cpp b/ace/Svc_Handler.cpp
index aae1e74c044..9673ce5a068 100644
--- a/ace/Svc_Handler.cpp
+++ b/ace/Svc_Handler.cpp
@@ -66,17 +66,11 @@ ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_2>::destroy (void)
// Only delete ourselves if we've been allocated dynamically.
if (this->dynamic_ && this->closing_ == 0)
- {
- // We're closing down now, so make sure not to call ourselves
- // recursively...
- this->closing_ = 1;
-
- // Will call the destructor, which automatically calls <shutdown>.
- // Note that if we are *not* allocated dynamically then the
- // destructor will call <shutdown> automatically when it gets run
- // during cleanup.
- delete this;
- }
+ // Will call the destructor, which automatically calls <shutdown>.
+ // Note that if we are *not* allocated dynamically then the
+ // destructor will call <shutdown> automatically when it gets run
+ // during cleanup.
+ delete this;
}
template <PR_ST_1, ACE_SYNCH_1> void
@@ -197,7 +191,16 @@ template <PR_ST_1, ACE_SYNCH_1>
ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_2>::~ACE_Svc_Handler (void)
{
ACE_TRACE ("ACE_Svc_Handler<PR_ST_2, ACE_SYNCH_2>::~ACE_Svc_Handler");
- this->shutdown ();
+
+ if (this->closing_ == 0)
+ {
+ // We're closing down now, so make sure not to call ourselves
+ // recursively via other calls to handle_close() (e.g., from the
+ // Timer_Queue).
+ this->closing_ = 1;
+
+ this->shutdown ();
+ }
}
template <PR_ST_1, ACE_SYNCH_1> int
diff --git a/ace/config-hpux-10.x-g++.h b/ace/config-hpux-10.x-g++.h
index 5da70fc0bd3..a53956ce198 100644
--- a/ace/config-hpux-10.x-g++.h
+++ b/ace/config-hpux-10.x-g++.h
@@ -83,6 +83,7 @@
#define ACE_HAS_SIGINFO_T
#define ACE_LACKS_UCONTEXT_T
+#define ACE_LACKS_UCONTEXT_H
#define _CLOCKID_T
#define ACE_SELECT_USES_INT
#define ACE_LACKS_SI_ADDR
diff --git a/examples/Logger/simple-server/Logging_Handler.cpp b/examples/Logger/simple-server/Logging_Handler.cpp
index f6aec6db542..3a5381dea7a 100644
--- a/examples/Logger/simple-server/Logging_Handler.cpp
+++ b/examples/Logger/simple-server/Logging_Handler.cpp
@@ -1,4 +1,3 @@
-
// $Id$
#include "Logging_Handler.h"
diff --git a/examples/Reactor/Multicast/client.cpp b/examples/Reactor/Multicast/client.cpp
index 2147fd18d49..c9bce1b45a6 100644
--- a/examples/Reactor/Multicast/client.cpp
+++ b/examples/Reactor/Multicast/client.cpp
@@ -3,19 +3,19 @@
// This program reads in messages from stdin and sends them to a
// Log_Wrapper.
-
#include "ace/Get_Opt.h"
-
#include "Log_Wrapper.h"
-const char *MCAST_ADDR = ACE_DEFAULT_MULTICAST_ADDR;
+// Multi-cast address.
+static const char *MCAST_ADDR = ACE_DEFAULT_MULTICAST_ADDR;
-const int UDP_PORT = ACE_DEFAULT_MULTICAST_PORT;
+// UDP port.
+static const int UDP_PORT = ACE_DEFAULT_MULTICAST_PORT;
-// maximum message size
-static int max_message_size = BUFSIZ * 20;
+// Maximum message size.
+static int max_message_size = BUFSIZ;
-// number of times to send message of max_message_size
+// Number of times to send message of max_message_size.
static int iterations = 0;
static void
@@ -23,7 +23,8 @@ parse_args (int argc, char *argv[])
{
ACE_LOG_MSG->open (argv[0]);
- ACE_Get_Opt getopt (argc, argv, "m:ui:", 1); // Start at argv[1]
+ // Start at argv[1]
+ ACE_Get_Opt getopt (argc, argv, "m:ui:", 1);
for (int c; (c = getopt ()) != -1; )
switch (c)
@@ -37,7 +38,9 @@ parse_args (int argc, char *argv[])
case 'u':
// usage fallthrough
default:
- ACE_ERROR ((LM_ERROR, "%n: -m max_message_size (in k) -i iterations\n%a", 1));
+ ACE_ERROR ((LM_ERROR,
+ "%n: -m max_message_size (in k) -i iterations\n%a",
+ 1));
/* NOTREACHED */
}
}
@@ -49,57 +52,65 @@ main (int argc, char **argv)
parse_args (argc,argv);
- ACE_DEBUG ((LM_DEBUG, "Max Buffer size = %d\n", max_message_size));
+ ACE_DEBUG ((LM_DEBUG, "max buffer size = %d\n", max_message_size));
// Instantiate a log wrapper for logging
Log_Wrapper log;
- // make a connection to a logger via orbixd
+ // Make a connection to a logger.
if (log.open (UDP_PORT, MCAST_ADDR) == -1)
- ACE_OS::perror ("connect failed"), ACE_OS::exit (1);
+ ACE_ERROR_RETURN ((LM_ERROR, "%p\n" "open"), -1);
char *buf;
-
- ACE_NEW_RETURN (buf, char[::max_message_size], -1);
+ ACE_NEW_RETURN (buf, char[max_message_size], -1);
// If -i has been specified, send max_message_size messages
// iterations number of times.
if (iterations)
{
- ACE_OS::memset (buf,1,::max_message_size);
+ ACE_OS::memset (buf, 1, max_message_size);
+
while (iterations--)
if (log.log_message (Log_Wrapper::LM_DEBUG, buf) == -1)
- perror("log failed."), exit(1);
+ ACE_ERROR_RETURN ((LM_ERROR, "%p\n" "log"), -1);
}
// otherwise, a file has been redirected, or give prompts
else
{
- // If a file has been redirected, don't activate user prompts
+ // If a file has been redirected, don't activate user prompts.
if (ACE_OS::isatty (0))
user_prompt = 1;
else
user_prompt = 0;
- int nbytes;
- // continually read messages from stdin and log them.
- while (1)
+ // Continually read messages from stdin and log them.
+
+ for (int count = 1;;)
{
if (user_prompt)
ACE_DEBUG ((LM_DEBUG, "\nEnter message ('Q':quit):\n"));
+
+ ssize_t nbytes = ACE_OS::read (ACE_STDIN, buf, max_message_size);
+
+ if (nbytes <= 0)
+ break; // End of file or error.
+ buf[nbytes - 1] = '\0';
- if ((nbytes = read (0, buf, max_message_size)) == 0)
- break; // end of file
- buf[nbytes-1] = '\0';
-
- // quitting?
- if (buf[0] == 'Q')
- break;
-
- // send the message to the logger
- else if (log.log_message (Log_Wrapper::LM_DEBUG, buf) == -1)
- perror("log failed."), exit(1);
- } // while(1)
+ // Quitting?
+ if (user_prompt)
+ {
+ if (buf[0] == 'Q' || buf[0] == 'q')
+ break;
+ }
+ else // Keep from overrunning the receiver.
+ ACE_OS::sleep (1);
+
+ // Send the message to the logger.
+ if (log.log_message (Log_Wrapper::LM_DEBUG, buf) == -1)
+ ACE_ERROR_RETURN ((LM_ERROR, "%p\n" "log_message"), -1);
+ ACE_DEBUG ((LM_DEBUG, "finished sending message %d\n", count++));
+ }
}
ACE_DEBUG ((LM_DEBUG, "Client done.\n"));
diff --git a/examples/Reactor/Multicast/server.cpp b/examples/Reactor/Multicast/server.cpp
index d85b2109d02..b573e4bb1fb 100644
--- a/examples/Reactor/Multicast/server.cpp
+++ b/examples/Reactor/Multicast/server.cpp
@@ -1,8 +1,9 @@
// $Id$
// server.C (written by Tim Harrison)
-// listens to multicast address. after first message received, will
-// listen for 5 more seconds. prints Mbits/sec received from client.
+
+// Listens to multicast address for client log messages. Prints
+// Mbits/sec received from client.
#include "ace/SOCK_Dgram.h"
#include "ace/INET_Addr.h"
@@ -26,13 +27,14 @@ public:
virtual ACE_HANDLE get_handle (void) const;
ACE_Time_Value *wait_time (void);
-
+
private:
char *message_;
Log_Wrapper::ACE_Log_Record *log_record_;
char buf_[4 * BUFSIZ];
+ char hostname_[MAXHOSTNAMELEN];
- int initialize_;
+ int initialized_;
int count_;
int interval_;
// time interval to log messages
@@ -49,6 +51,10 @@ private:
int last_sequence_number_;
};
+static const char MCAST_ADDR[] = ACE_DEFAULT_MULTICAST_ADDR;
+static const int UDP_PORT = ACE_DEFAULT_MULTICAST_PORT;
+static const int DURATION = 5;
+
ACE_HANDLE
Server_Events::get_handle (void) const
{
@@ -65,21 +71,27 @@ Server_Events::Server_Events (u_short port,
const char *mcast_addr,
long time_interval)
: total_bytes_received_ (0),
- count_(-1),
- initialize_ (0),
+ count_ (1),
+ initialized_ (0),
interval_ (time_interval),
mcast_addr_ (port, mcast_addr)
{
// Use ACE_SOCK_Dgram_Mcast factory to subscribe to multicast group.
- if (this->mcast_dgram_.subscribe (this->mcast_addr_) == -1)
- perror("can't subscribe to multicast group"), exit(1);
-
- // Point to NULL so that we block in the beginning.
- this->how_long_ = 0;
+ if (ACE_OS::hostname (this->hostname_, MAXHOSTNAMELEN) == -1)
+ ACE_ERROR ((LM_ERROR, "%p\n", "hostname"));
+
+ else if (this->mcast_dgram_.subscribe (this->mcast_addr_) == -1)
+ ACE_ERROR ((LM_ERROR, "%p\n", "subscribe"));
+
+ else
+ {
+ // Point to NULL so that we block in the beginning.
+ this->how_long_ = 0;
- this->log_record_ = (Log_Wrapper::ACE_Log_Record *) &buf_;
- this->message_ = &buf_[sizeof (Log_Wrapper::ACE_Log_Record)];
+ this->log_record_ = (Log_Wrapper::ACE_Log_Record *) &buf_;
+ this->message_ = &buf_[sizeof (Log_Wrapper::ACE_Log_Record)];
+ }
}
// A destructor that emacs refuses to color blue ;-)
@@ -102,74 +114,77 @@ Server_Events::~Server_Events (void)
}
int
-Server_Events::handle_timeout (const ACE_Time_Value &tv,
+Server_Events::handle_timeout (const ACE_Time_Value &,
const void *arg)
{
- ACE_DEBUG ((LM_DEBUG, "\t%d timeout occurred for %s.\n",
- ++count_,
+ ACE_DEBUG ((LM_DEBUG, "\t%d timeout%s occurred for %s.\n",
+ this->count_,
+ this->count_ == 1 ? "" : "s",
(char *) arg));
+
+ // Don't let the timeouts continue if there's no activity since
+ // otherwise we use up a lot of CPU time unnecessarily.
if (this->count_ == 5)
{
- reactor()->cancel_timer (this);
- this->initialize_ = 0;
+ reactor ()->cancel_timer (this);
+ this->initialized_ = 0;
- ACE_DEBUG ((LM_DEBUG, "\t%d canceled timeout occurred for %s.\n",
- count_, (char *) arg));
+ ACE_DEBUG ((LM_DEBUG,
+ "\t%cancelled timeout for %s to avoid busy waiting.\n",
+ (char *) arg));
}
+ this->count_++;
return 0;
}
int
Server_Events::handle_input (ACE_HANDLE)
{
- // receive message from multicast group
+ // Receive message from multicast group.
iovec iovp[2];
iovp[0].iov_base = buf_;
iovp[0].iov_len = sizeof log_record_;
iovp[1].iov_base = &buf_[sizeof (log_record_)];
iovp[1].iov_len = 4 * BUFSIZ - sizeof log_record_;
- int retcode = this->mcast_dgram_.recv (iovp,
- 2,
- this->remote_addr_);
+ ssize_t retcode =
+ this->mcast_dgram_.recv (iovp, 2, this->remote_addr_);
+
if (retcode != -1)
{
total_messages_received_++;
total_bytes_received_ += retcode;
- last_sequence_number_ = ntohl(log_record_->sequence_number);
+ last_sequence_number_ = ntohl (log_record_->sequence_number);
+
ACE_DEBUG ((LM_DEBUG, "sequence number = %d\n",
last_sequence_number_));
ACE_DEBUG ((LM_DEBUG, "message = '%s'\n",
this->message_));
- if (!this->initialize_)
+ if (this->initialized_ == 0)
{
+ // Restart the timer since we've received events again.
reactor()->schedule_timer (this,
- (void *) "Foo",
+ (void *) this->hostname_,
ACE_Time_Value::zero,
- ACE_Time_Value(5));
- initialize_ = 1;
+ ACE_Time_Value (DURATION));
+ this->initialized_ = 1;
}
-
- count_ = -1;
+ this->count_ = 1;
return 0;
}
else
return -1;
}
-static const char MCAST_ADDR[] = ACE_DEFAULT_MULTICAST_ADDR;
-static const int UDP_PORT = ACE_DEFAULT_MULTICAST_PORT;
-
int
-main(int, char *[])
+main (int, char *[])
{
- int duration = 5;
-
- // Instantiate a server which will receive messages for 5 seconds.
- Server_Events server_events (UDP_PORT, MCAST_ADDR, duration);
+ // Instantiate a server which will receive messages for DURATION
+ // seconds.
+ Server_Events server_events (UDP_PORT, MCAST_ADDR, DURATION);
// Instance of the ACE_Reactor.
ACE_Reactor reactor;
@@ -178,6 +193,8 @@ main(int, char *[])
ACE_Event_Handler::READ_MASK) == -1)
ACE_ERROR ((LM_ERROR, "%p\n%a", "register_handler", 1));
+ ACE_DEBUG ((LM_DEBUG, "starting up server\n"));
+
for (;;)
reactor.handle_events (server_events.wait_time ());
diff --git a/netsvcs/lib/TS_Clerk_Handler.cpp b/netsvcs/lib/TS_Clerk_Handler.cpp
index 0469da18339..b327a5667b3 100644
--- a/netsvcs/lib/TS_Clerk_Handler.cpp
+++ b/netsvcs/lib/TS_Clerk_Handler.cpp
@@ -1,6 +1,7 @@
-// TS_Clerk_Handler.cpp
// $Id$
+// TS_Clerk_Handler.cpp
+
#define ACE_BUILD_SVC_DLL
#include "ace/Service_Config.h"
#include "ace/Connector.h"
@@ -342,10 +343,11 @@ ACE_TS_Clerk_Handler::get_handle (void) const
int
ACE_TS_Clerk_Handler::handle_close (ACE_HANDLE,
- ACE_Reactor_Mask)
+ ACE_Reactor_Mask mask)
{
ACE_TRACE ("ACE_TS_Clerk_Handler::handle_close");
ACE_DEBUG ((LM_DEBUG, "(%t) shutting down on handle %d\n", this->get_handle ()));
+
return this->reinitiate_connection ();
}
diff --git a/netsvcs/lib/Token_Handler.cpp b/netsvcs/lib/Token_Handler.cpp
index ae2e80666db..f993dbc8214 100644
--- a/netsvcs/lib/Token_Handler.cpp
+++ b/netsvcs/lib/Token_Handler.cpp
@@ -1,6 +1,7 @@
-// Token_Handler.cpp
// $Id$
+// Token_Handler.cpp
+
#define ACE_BUILD_SVC_DLL
#include "ace/Get_Opt.h"