summaryrefslogtreecommitdiff
path: root/apps/Gateway/Peer
diff options
context:
space:
mode:
authorschmidt <douglascraigschmidt@users.noreply.github.com>1998-01-01 00:53:34 +0000
committerschmidt <douglascraigschmidt@users.noreply.github.com>1998-01-01 00:53:34 +0000
commit7697ddf5a428a8d67965710beb5386f0cccebb24 (patch)
tree0655da898e3834dba21cd923222e085290c8e313 /apps/Gateway/Peer
parentf99533b87ca9647d575372b97d3a1b89d6e97b00 (diff)
downloadATCD-7697ddf5a428a8d67965710beb5386f0cccebb24.tar.gz
*** empty log message ***
Diffstat (limited to 'apps/Gateway/Peer')
-rw-r--r--apps/Gateway/Peer/Options.cpp53
-rw-r--r--apps/Gateway/Peer/Options.h65
-rw-r--r--apps/Gateway/Peer/Peer.cpp59
-rw-r--r--apps/Gateway/Peer/Peer.h3
4 files changed, 106 insertions, 74 deletions
diff --git a/apps/Gateway/Peer/Options.cpp b/apps/Gateway/Peer/Options.cpp
index 59a6acdbaa2..3e6953e6769 100644
--- a/apps/Gateway/Peer/Options.cpp
+++ b/apps/Gateway/Peer/Options.cpp
@@ -1,24 +1,65 @@
#include "ace/Get_Opt.h"
void
+Options::print_usage_and_die (void)
+{
+ ACE_DEBUG ((LM_DEBUG, "%n [-p port] [-t timeout] [-v]\n"));
+}
+
+long
+Options::timeout (void) const
+{
+ return this->timeout_;
+}
+
+u_short
+Options::port (void) const
+{
+ return this->port_;
+}
+
+u_short
+Options::verbose (void) const
+{
+ return this->verbose_;
+}
+
+void
Options::parse_args (int argc, char *argv[])
{
- ACE_Get_Opt get_opt (argc, argv, "dp:v", 0);
+ ACE_Get_Opt get_opt (argc, argv, "p:t:v", 0);
+
+ char *to = ACE_OS::getenv ("TIMEOUT");
+
+ if (to == 0)
+ this->timeout_ = Options::DEFAULT_TIMEOUT;
+ else
+ this->timeout_ = ACE_OS::atoi (to);
+
+ this->port_ = ACE_DEFAULT_PEER_SERVER_PORT;
+ this->verbose_ = 0;
for (int c; (c = get_opt ()) != -1; )
{
switch (c)
{
case 'p':
- this->addr_.set (ACE_OS::atoi (get_opt.optarg));
+ this->port_ = ACE_OS::atoi (get_opt.optarg);
break;
- case 'd':
+ /* NOTREACHED */
+ case 't':
+ // Timeout
+ this->timeout_ = ACE_OS::atoi (get_opt.optarg);
break;
- case 'v': // Verbose mode.
- verbose = 1;
+ /* NOTREACHED */
+ case 'v':
+ // Verbose mode.
+ this->verbose_ = 1;
break;
+ /* NOTREACHED */
default:
- break;
+ this->print_usage_and_die ();
+ /* NOTREACHED */
}
}
}
diff --git a/apps/Gateway/Peer/Options.h b/apps/Gateway/Peer/Options.h
index 5092861422d..4d2385707a3 100644
--- a/apps/Gateway/Peer/Options.h
+++ b/apps/Gateway/Peer/Options.h
@@ -18,20 +18,22 @@ public:
// Parse the arguments.
// = Accessor methods.
- char *program_name (void);
- const char *slave_name (void);
- int debug (void);
- int exec_slave (void);
- size_t iteration_count (void);
- int use_sbrk (void);
- int use_shmem (void);
- size_t max_msg_size (void);
- size_t spawn_count (void);
- int spawn_threads (void);
- int use_mmap (void);
- int child (void);
+ int verbose (void) const;
+ // Are we in verbose mode?
+
+ u_short port (void) const;
+ // What is our listening port number?
+
+ long timeout (void) const;
+ // What is our timeout?
private:
+ enum
+ {
+ DEFAULT_TIMEOUT = 60
+ // By default, disconnect the peer every minute.
+ }
+
Options (void);
// Ensure Singleton.
@@ -41,41 +43,14 @@ private:
void print_usage_and_die (void);
// Explain usage and exit.
- char *program_name_;
- // Name of the program.
-
- const char *slave_name_;
- // Name of slave process.
-
- int debug_;
- // Flag to indicate if we are debugging.
-
- int exec_slave_;
- // Flag to indicate if we should exec after forking.
-
- size_t iteration_count_;
- // Number of iterations to call malloc_recurse().
-
- int use_sbrk_;
- // Should we use sbrk(2)?
-
- int use_shmem_;
- // Should we use Shared Memory?
-
- size_t max_msg_size_;
- // Maximum number of bytes to malloc.
-
- size_t spawn_count_;
- // Number of threads.
-
- int spawn_threads_;
- // Spawn threads vs. processes.
+ int verbose_;
+ // Flag to indicate if we want verbose diagnostics.
- int use_mmap_;
- // Use mmap() as the backing store.
+ u_short port_;
+ // Our port number.
- int child_;
- // We're a child process.
+ long timeout_;
+ // The amount of time to wait before disconnecting from the Peerd.
};
#endif /* OPTIONS_H */
diff --git a/apps/Gateway/Peer/Peer.cpp b/apps/Gateway/Peer/Peer.cpp
index 12d50a6fc4c..b7068da74af 100644
--- a/apps/Gateway/Peer/Peer.cpp
+++ b/apps/Gateway/Peer/Peer.cpp
@@ -23,7 +23,8 @@ Peer_Handler::Peer_Handler (void)
int
Peer_Handler::open (void *a)
{
- ACE_DEBUG ((LM_DEBUG, "Gateway handler's handle = %d\n",
+ ACE_DEBUG ((LM_DEBUG,
+ "Gateway handler's handle = %d\n",
this->peer ().get_handle ()));
// Call down to the base class to activate and register this handler
@@ -34,21 +35,25 @@ Peer_Handler::open (void *a)
if (this->peer ().enable (ACE_NONBLOCK) == -1)
ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "enable"), -1);
- char *to = ACE_OS::getenv ("TIMEOUT");
- ACE_Time_Value timeout (to == 0 ? Peer_Handler::DEFAULT_TIMEOUT : ACE_OS::atoi (to));
+ ACE_Time_Value timeout (Options::instance ()->timeout ());
// Schedule the time between disconnects. This should really be a
// "tunable" parameter.
if (ACE_Reactor::instance ()->schedule_timer
(this, 0, timeout) == -1)
- ACE_ERROR ((LM_ERROR, "%p\n", "schedule_timer"));
+ ACE_ERROR ((LM_ERROR,
+ "%p\n",
+ "schedule_timer"));
// If there are events left in the queue, make sure we enable the
// <ACE_Reactor> appropriately to get them sent out.
if (this->msg_queue ()->is_empty () == 0
&& ACE_Reactor::instance ()->schedule_wakeup
(this, ACE_Event_Handler::WRITE_MASK) == -1)
- ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "schedule_wakeup"), -1);
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%p\n",
+ "schedule_wakeup"),
+ -1);
// First action is to wait to be notified of our supplier id.
this->do_action_ = &Peer_Handler::await_supplier_id;
@@ -106,11 +111,13 @@ Peer_Handler::xmit_stdin (void)
if (this->put (mb) == -1)
{
if (errno == EWOULDBLOCK) // The queue has filled up!
- ACE_ERROR ((LM_ERROR, "%p\n",
+ ACE_ERROR ((LM_ERROR,
+ "%p\n",
"gateway is flow controlled, so we're dropping events"));
else
- ACE_ERROR ((LM_ERROR, "%p\n", "transmission failure in xmit_stdin"));
-
+ ACE_ERROR ((LM_ERROR,
+ "%p\n",
+ "transmission failure in xmit_stdin"));
// Caller is responsible for freeing a ACE_Message_Block
// if failures occur.
mb->release ();
@@ -148,12 +155,18 @@ Peer_Handler::nonblk_put (ACE_Message_Block *mb)
if (this->msg_queue ()->enqueue_head
(mb,
(ACE_Time_Value *) &ACE_Time_Value::zero) == -1)
- ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "enqueue_head"), -1);
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%p\n",
+ "enqueue_head"),
+ -1);
// Tell ACE_Reactor to call us back when we can send again.
if (ACE_Reactor::instance ()->schedule_wakeup
(this, ACE_Event_Handler::WRITE_MASK) == -1)
- ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "schedule_wakeup"), -1);
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%p\n",
+ "schedule_wakeup"),
+ -1);
return 0;
}
else
@@ -204,7 +217,9 @@ Peer_Handler::handle_output (ACE_HANDLE)
if (ACE_Reactor::instance ()->cancel_wakeup
(this, ACE_Event_Handler::WRITE_MASK) == -1)
- ACE_ERROR ((LM_ERROR, "%p\n", "cancel_wakeup"));
+ ACE_ERROR ((LM_ERROR,
+ "%p\n",
+ "cancel_wakeup"));
}
}
return 0;
@@ -376,7 +391,7 @@ Peer_Handler::recv (ACE_Message_Block *&mb)
ACE_DEBUG ((LM_DEBUG, "(%t) supplier id = %d, cur len = %d, total bytes read = %d\n",
event->header_.supplier_id_, event->header_.len_, data_received + header_received));
- if (verbose)
+ if (Options::instance ()->verbose ())
ACE_DEBUG ((LM_DEBUG, "data_ = %*s\n", event->header_.len_ - 2, event->data_));
return data_received + header_received;
}
@@ -476,9 +491,10 @@ Peer_Handler::await_events (void)
event->header_.supplier_id_,
event->header_.len_,
this->total_bytes_));
- if (verbose)
- ACE_DEBUG ((LM_DEBUG, "data_ = %s\n", event->data_));
-
+ if (Options::instance ()->verbose ())
+ ACE_DEBUG ((LM_DEBUG,
+ "data_ = %s\n",
+ event->data_));
mb->release ();
return 0;
}
@@ -524,9 +540,11 @@ Peer_Handler::handle_close (ACE_HANDLE,
// Deregister this handler with the ACE_Reactor.
if (ACE_Reactor::instance ()->remove_handler
(this, mask) == -1)
- ACE_ERROR_RETURN ((LM_ERROR, "handle = %d: %p\n",
- this->get_handle (), "remove_handler"), -1);
-
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "handle = %d: %p\n",
+ this->get_handle (),
+ "remove_handler"),
+ -1);
// Close down the peer.
this->peer ().close ();
}
@@ -534,7 +552,6 @@ Peer_Handler::handle_close (ACE_HANDLE,
}
Peer_Acceptor::Peer_Acceptor (void)
- : addr_ (ACE_DEFAULT_PEER_SERVER_PORT)
{
// This object only gets allocated once and is just recycled
// forever. Thus, it acts like a Singleton.
@@ -608,7 +625,9 @@ Peer_Acceptor::fini (void)
int
Peer_Acceptor::init (int argc, char *argv[])
{
- this->parse_args (argc, argv);
+ Options::instance ()->parse_args (argc, argv);
+
+ this->addr_.set (Options::instance ()->port ());
ACE_Sig_Set sig_set;
sig_set.sig_add (SIGINT);
diff --git a/apps/Gateway/Peer/Peer.h b/apps/Gateway/Peer/Peer.h
index 78865481822..5fccfea68d6 100644
--- a/apps/Gateway/Peer/Peer.h
+++ b/apps/Gateway/Peer/Peer.h
@@ -100,9 +100,6 @@ protected:
// We'll allow up to 16 megabytes to be queued per-output
// channel!!!! This is clearly a policy in search of
// refinement...
-
- DEFAULT_TIMEOUT = 60
- // By default, disconnect the <Peer_Handler> every minute.
};
virtual int recv (ACE_Message_Block *&);