summaryrefslogtreecommitdiff
path: root/ACE/netsvcs
diff options
context:
space:
mode:
authorSteve Huston <shuston@riverace.com>2007-02-08 19:42:29 +0000
committerSteve Huston <shuston@riverace.com>2007-02-08 19:42:29 +0000
commit383d067fbfea847cf62336300407820246b547e1 (patch)
tree32efbc2851cbab7e74d32b886294bd0eb4ebbd0d /ACE/netsvcs
parentf5e2ea60eee73a8e2cb44c066462ef5abde266ac (diff)
downloadATCD-383d067fbfea847cf62336300407820246b547e1.tar.gz
ChangeLogTag:Thu Feb 8 19:40:30 UTC 2007 Steve Huston <shuston@riverace.com>
Diffstat (limited to 'ACE/netsvcs')
-rw-r--r--ACE/netsvcs/lib/Makefile.am2
-rw-r--r--ACE/netsvcs/lib/TS_Clerk_Handler.cpp16
-rw-r--r--ACE/netsvcs/lib/TS_Clerk_Handler.h11
-rw-r--r--ACE/netsvcs/lib/TS_Server_Handler.h3
-rw-r--r--ACE/netsvcs/lib/Time_Request_Reply.cpp205
-rw-r--r--ACE/netsvcs/lib/Time_Request_Reply.h136
-rw-r--r--ACE/netsvcs/lib/lib.mpc1
7 files changed, 360 insertions, 14 deletions
diff --git a/ACE/netsvcs/lib/Makefile.am b/ACE/netsvcs/lib/Makefile.am
index 54b8ed75617..c525ee11ec6 100644
--- a/ACE/netsvcs/lib/Makefile.am
+++ b/ACE/netsvcs/lib/Makefile.am
@@ -30,6 +30,7 @@ libnetsvcs_la_SOURCES = \
Name_Handler.cpp \
Server_Logging_Handler.cpp \
Server_Logging_Handler_T.cpp \
+ Time_Request_Reply.cpp \
TS_Clerk_Handler.cpp \
TS_Server_Handler.cpp \
Token_Handler.cpp
@@ -42,6 +43,7 @@ noinst_HEADERS = \
Server_Logging_Handler.h \
Server_Logging_Handler_T.cpp \
Server_Logging_Handler_T.h \
+ Time_Request_Reply.h \
TS_Clerk_Handler.h \
TS_Server_Handler.h \
Token_Handler.h
diff --git a/ACE/netsvcs/lib/TS_Clerk_Handler.cpp b/ACE/netsvcs/lib/TS_Clerk_Handler.cpp
index 2077c1162ae..ca9517350f4 100644
--- a/ACE/netsvcs/lib/TS_Clerk_Handler.cpp
+++ b/ACE/netsvcs/lib/TS_Clerk_Handler.cpp
@@ -187,14 +187,14 @@ ACE_TS_Clerk_Handler::handle_input (ACE_HANDLE)
else
{
// Get current local time
- ACE_UINT32 local_time = ACE_OS::time (0);
+ time_t local_time = ACE_OS::time (0);
// Compure delta time (difference between current local time and
// system time obtained from the server)
- long t = reply.time () - local_time;
+ time_t t = reply.time () - local_time;
// Compute round trip delay and adjust time accordingly
- ACE_UINT32 one_way_time = (local_time - this->start_time_)/2;
+ time_t one_way_time = (local_time - this->start_time_)/2;
t += one_way_time;
// Now update time info (to be retrieved by Clerk_Processor)
@@ -338,15 +338,15 @@ ACE_TS_Clerk_Processor::alloc (void)
if (this->shmem_->find (ACE_DEFAULT_TIME_SERVER_STR) == -1)
{
// Allocate the space out of shared memory for the system time entry
- void *temp = this->shmem_->malloc (sizeof (this->system_time_));
+ time_t *temp = (time_t *)(this->shmem_->malloc (2 * sizeof (time_t)));
// Give it a name binding
this->shmem_->bind (ACE_DEFAULT_TIME_SERVER_STR, temp);
// Set up pointers. Note that we add one to get to the second
// field in the structure
- this->system_time_.delta_time_ = (long *) temp;
- this->system_time_.last_local_time_ = ((long *) temp) + 1;
+ this->system_time_.delta_time_ = temp;
+ this->system_time_.last_local_time_ = temp + 1;
// Initialize
*(this->system_time_.delta_time_) = 0;
@@ -373,7 +373,7 @@ ACE_TS_Clerk_Processor::update_time ()
this->cur_sequence_num_++;
int count = 0;
- long total_delta = 0;
+ time_t total_delta = 0;
ACE_Time_Info time_info;
// Call send_request() on all handlers
@@ -421,7 +421,7 @@ ACE_TS_Clerk_Processor::update_time ()
*(this->system_time_.last_local_time_) = ACE_OS::time (0);
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Average delta time: %d\n"),
- *(this->system_time_.delta_time_)));
+ (int)(*(this->system_time_.delta_time_))));
return 0;
}
diff --git a/ACE/netsvcs/lib/TS_Clerk_Handler.h b/ACE/netsvcs/lib/TS_Clerk_Handler.h
index b322e82eef8..f549394971e 100644
--- a/ACE/netsvcs/lib/TS_Clerk_Handler.h
+++ b/ACE/netsvcs/lib/TS_Clerk_Handler.h
@@ -24,10 +24,11 @@
#include "ace/MMAP_Memory_Pool.h"
#include "ace/Malloc_T.h"
#include "ace/Null_Mutex.h"
-#include "ace/Time_Request_Reply.h"
#include "ace/svc_export.h"
#include "ace/os_include/os_dirent.h"
+#include "Time_Request_Reply.h"
+
/**
* @class ACE_Time_Info
*
@@ -37,7 +38,7 @@ class ACE_Time_Info
{
public:
- long delta_time_;
+ time_t delta_time_;
ACE_UINT32 sequence_num_;
};
@@ -157,7 +158,7 @@ private:
ACE_TS_Clerk_Processor *processor_;
/// Time at which request was sent (used to compute round trip delay)
- ACE_UINT32 start_time_;
+ time_t start_time_;
/// Next sequence number of time request (waiting for this update from
/// the server).
@@ -230,8 +231,8 @@ private:
struct System_Time
{
- long *delta_time_; // Difference between system time and local time
- long *last_local_time_; // Last local time
+ time_t *delta_time_; // Diff between system time and local time
+ time_t *last_local_time_; // Last local time
};
/// Clerk system time containing pointers to entries in shared memory
diff --git a/ACE/netsvcs/lib/TS_Server_Handler.h b/ACE/netsvcs/lib/TS_Server_Handler.h
index 142c98ecdc1..1fca9bce0fe 100644
--- a/ACE/netsvcs/lib/TS_Server_Handler.h
+++ b/ACE/netsvcs/lib/TS_Server_Handler.h
@@ -22,9 +22,10 @@
#include "ace/SOCK_Acceptor.h"
#include "ace/Svc_Handler.h"
-#include "ace/Time_Request_Reply.h"
#include "ace/svc_export.h"
+#include "Time_Request_Reply.h"
+
#if defined ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION_EXPORT
template class ACE_Svc_Export ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>;
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION_EXPORT */
diff --git a/ACE/netsvcs/lib/Time_Request_Reply.cpp b/ACE/netsvcs/lib/Time_Request_Reply.cpp
new file mode 100644
index 00000000000..d7044e8bbdc
--- /dev/null
+++ b/ACE/netsvcs/lib/Time_Request_Reply.cpp
@@ -0,0 +1,205 @@
+// $Id$
+
+#include "ace/Basic_Types.h"
+#include "ace/CDR_Base.h"
+#include "ace/Log_Msg.h"
+#include "ace/os_include/netinet/os_in.h"
+#include "ace/os_include/arpa/os_inet.h"
+
+#define ACE_BUILD_SVC_DLL
+
+#include "Time_Request_Reply.h"
+
+ACE_RCSID(lib, Time_Request_Reply, "$Id$")
+
+// Default "do nothing" constructor.
+
+ACE_Time_Request::ACE_Time_Request (void)
+{
+ ACE_TRACE ("ACE_Time_Request::ACE_Time_Request");
+}
+
+// Create a ACE_Time_Request message.
+
+ACE_Time_Request::ACE_Time_Request (ACE_INT32 t, // Type of request.
+ const time_t time,
+ ACE_Time_Value *timeout) // Max time waiting for request.
+{
+ ACE_TRACE ("ACE_Time_Request::ACE_Time_Request");
+ this->msg_type (t);
+
+ // If timeout is a NULL pointer, then block forever...
+ if (timeout == 0)
+ {
+ this->transfer_.block_forever_ = 1;
+ this->transfer_.sec_timeout_ = 0;
+ this->transfer_.usec_timeout_ = 0;
+ }
+ else // Do a "timed wait."
+ {
+ this->block_forever (0);
+ // Keep track of how long client is willing to wait.
+ this->transfer_.sec_timeout_ = timeout->sec ();
+ this->transfer_.usec_timeout_ = timeout->usec ();
+ }
+
+ // Copy time into request
+ this->transfer_.time_ = this->time_ = time;
+}
+
+// Initialize length_ in order to avoid problems with byte-ordering
+void
+ACE_Time_Request::init (void)
+{
+ ACE_TRACE ("ACE_Time_Request::init");
+// this->length (sizeof this->transfer_);
+}
+
+// Get the fixed size of message
+ssize_t
+ACE_Time_Request::size (void) const
+{
+ ACE_TRACE ("ACE_Time_Request::size");
+ return sizeof (this->transfer_);
+}
+
+// = Set/get the type of the message.
+ACE_INT32
+ACE_Time_Request::msg_type (void) const
+{
+ ACE_TRACE ("ACE_Time_Request::msg_type");
+ return this->transfer_.msg_type_;
+}
+
+void
+ACE_Time_Request::msg_type (ACE_INT32 t)
+{
+ ACE_TRACE ("ACE_Time_Request::msg_type");
+ this->transfer_.msg_type_ = t;
+}
+
+// = Set/get the blocking semantics.
+ACE_UINT32
+ACE_Time_Request::block_forever (void) const
+{
+ ACE_TRACE ("ACE_Time_Request::block_forever");
+ return this->transfer_.block_forever_;
+}
+
+void
+ACE_Time_Request::block_forever (ACE_UINT32 bs)
+{
+ ACE_TRACE ("ACE_Time_Request::block_forever");
+ this->transfer_.block_forever_ = bs;
+}
+
+// = Set/get the timeout.
+ACE_Time_Value
+ACE_Time_Request::timeout (void) const
+{
+ ACE_TRACE ("ACE_Time_Request::timeout");
+ return ACE_Time_Value (this->transfer_.sec_timeout_, this->transfer_.usec_timeout_);
+}
+
+void
+ACE_Time_Request::timeout (const ACE_Time_Value& timeout)
+{
+ ACE_TRACE ("ACE_Time_Request::timeout");
+ this->transfer_.sec_timeout_ = timeout.sec ();
+ this->transfer_.usec_timeout_ = timeout.usec ();
+}
+
+// = Set/get the time
+time_t
+ACE_Time_Request::time (void) const
+{
+ ACE_TRACE ("ACE_Time_Request::time");
+ return this->time_;
+}
+
+void
+ACE_Time_Request::time (time_t t)
+{
+ ACE_TRACE ("ACE_Time_Request::time");
+ this->time_ = t;
+}
+
+// Encode the transfer buffer into network byte order
+// so that it can be sent to the server.
+int
+ACE_Time_Request::encode (void *&buf)
+{
+ ACE_TRACE ("ACE_Time_Request::encode");
+ // Compute the length *before* doing the marshaling.
+
+ buf = (void *) &this->transfer_;
+ this->transfer_.block_forever_ = ACE_HTONL (this->transfer_.block_forever_);
+ this->transfer_.usec_timeout_ = ACE_HTONL (this->transfer_.usec_timeout_);
+ this->transfer_.msg_type_ = ACE_HTONL (this->transfer_.msg_type_);
+#if defined (ACE_LITTLE_ENDIAN)
+ ACE_UINT64 secs = this->transfer_.sec_timeout_;
+ ACE_CDR::swap_8 ((const char *)&secs, (char *)&this->transfer_.sec_timeout_);
+ secs = this->transfer_.time_;
+ ACE_CDR::swap_8 ((const char *)&secs, (char *)&this->transfer_.time_);
+#endif
+
+ return this->size (); // Always fixed
+}
+
+// Decode the transfer buffer into host byte byte order
+// so that it can be used by the server.
+int
+ACE_Time_Request::decode (void)
+{
+ ACE_TRACE ("ACE_Time_Request::decode");
+ // Decode
+ this->transfer_.block_forever_ = ACE_NTOHL (this->transfer_.block_forever_);
+ this->transfer_.usec_timeout_ = ACE_NTOHL (this->transfer_.usec_timeout_);
+ this->transfer_.msg_type_ = ACE_NTOHL (this->transfer_.msg_type_);
+#if defined (ACE_LITTLE_ENDIAN)
+ ACE_UINT64 secs = this->transfer_.sec_timeout_;
+ ACE_CDR::swap_8 ((const char *)&secs, (char *)&this->transfer_.sec_timeout_);
+ secs = this->transfer_.time_;
+ ACE_CDR::swap_8 ((const char *)&secs, (char *)&this->transfer_.time_);
+#endif
+
+ this->time_ = this->transfer_.time_;
+ return 0;
+}
+
+// Print out the current values of the ACE_Time_Request.
+
+void
+ACE_Time_Request::dump (void) const
+{
+#if defined (ACE_HAS_DUMP)
+ ACE_TRACE ("ACE_Time_Request::dump");
+ ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("*******\nlength = %d\n"),
+ this->size ()));
+ ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("message-type = ")));
+
+ switch (this->msg_type ())
+ {
+ case ACE_Time_Request::TIME_UPDATE:
+ ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("TIME_UPDATE\n")));
+ break;
+ default:
+ ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("<unknown type> = %d\n"), this->msg_type ()));
+ break;
+ }
+
+ if (this->block_forever ())
+ ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("blocking forever\n")));
+ else
+ {
+#if !defined (ACE_NLOGGING)
+ ACE_Time_Value tv = this->timeout ();
+#endif /* ! ACE_NLOGGING */
+ ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("waiting for %d secs and %d usecs\n"),
+ (int)(tv.sec ()), tv.usec ()));
+ }
+ ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("*******\ntime = %d\n"),
+ (int)(this->time ())));
+ ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("+++++++\n")));
+#endif /* ACE_HAS_DUMP */
+}
diff --git a/ACE/netsvcs/lib/Time_Request_Reply.h b/ACE/netsvcs/lib/Time_Request_Reply.h
new file mode 100644
index 00000000000..530c5693899
--- /dev/null
+++ b/ACE/netsvcs/lib/Time_Request_Reply.h
@@ -0,0 +1,136 @@
+// -*- C++ -*-
+
+//=============================================================================
+/**
+ * @file Time_Request_Reply.h
+ *
+ * $Id$
+ *
+ * Define the format used to exchange messages between the
+ * ACE time server and clerks.
+ *
+ * @author Prashant Jain
+ */
+//=============================================================================
+
+
+#ifndef ACE_TIME_REQUEST_REPLY_H
+#define ACE_TIME_REQUEST_REPLY_H
+#include /**/ "ace/pre.h"
+
+#include "ace/Time_Value.h"
+#include "ace/svc_export.h"
+
+#if !defined (ACE_LACKS_PRAGMA_ONCE)
+# pragma once
+#endif /* ACE_LACKS_PRAGMA_ONCE */
+
+/**
+ * @class ACE_Time_Request
+ *
+ * @brief Message format for delivering requests to the ACE_Time Server.
+ *
+ * This class is implemented to minimize data copying.
+ * In particular, all marshaling is done in situ...
+ */
+class ACE_Svc_Export ACE_Time_Request
+{
+public:
+ enum Constants
+ {
+ /// Request message types.
+ TIME_UPDATE = 01,
+
+ /// Class-specific constant values.
+ MAX_TIME_LEN = MAXPATHLEN + 1
+ };
+
+ /// Default constructor.
+ ACE_Time_Request (void);
+
+ /**
+ * Create a ACE_Time_Request message.
+ * @param msg_type Type of request.
+ * @param time Time.
+ * @param timeout Max time waiting for request.
+ */
+ ACE_Time_Request (ACE_INT32 msg_type,
+ const time_t time,
+ ACE_Time_Value *timeout = 0);
+
+ /**
+ * Initialize length_ in order to ensure correct byte ordering before a
+ * request is sent.
+ * @deprecated This method is a no-op.
+ */
+ void init (void);
+
+ // Get the fixed size of message
+ ssize_t size (void) const;
+
+ /// Get the type of the message.
+ ACE_INT32 msg_type (void) const;
+
+ /// Set the type of the message.
+ void msg_type (ACE_INT32);
+
+ /// Get the time
+ time_t time (void) const;
+
+ // Set the time
+ void time (time_t t);
+
+ /// Get the blocking semantics.
+ ACE_UINT32 block_forever (void) const;
+
+ /// Set the blocking semantics.
+ void block_forever (ACE_UINT32);
+
+ /// Get the timeout.
+ ACE_Time_Value timeout (void) const;
+
+ /// Set the timeout.
+ void timeout (const ACE_Time_Value& timeout);
+
+ /// Encode the message before transmission.
+ int encode (void *&);
+
+ /// Decode message after reception.
+ int decode (void);
+
+ /// Print out the values of the message for debugging purposes.
+ void dump (void) const;
+
+private:
+ // = The 5 fields in the <Transfer> struct are transmitted to the server.
+ // The remaining 2 fields are not tranferred -- they are used only on
+ // the server-side to simplify lookups.
+
+ struct Transfer
+ {
+ /// Type of the request (i.e., <TIME_UPDATE>)
+ ACE_INT32 msg_type_;
+
+ /// Indicates if we should block forever. If 0, then sec_timeout_
+ /// and usec_timeout_ indicates how long we should wait.
+ ACE_UINT32 block_forever_;
+
+ /// Max seconds willing to wait for name if not blocking forever.
+ ACE_UINT64 sec_timeout_;
+
+ /// Max micro seconds to wait for name if not blocking forever.
+ ACE_UINT32 usec_timeout_;
+
+ /// The data portion contains <time_>
+ ACE_UINT64 time_;
+ };
+
+ /// Transfer buffer.
+ Transfer transfer_;
+
+ /// Time
+ time_t time_;
+};
+
+#include /**/ "ace/post.h"
+#endif /* ACE_TIME_REQUEST_REPLY_H */
diff --git a/ACE/netsvcs/lib/lib.mpc b/ACE/netsvcs/lib/lib.mpc
index d1e2f34a9fa..4a3e04a17f7 100644
--- a/ACE/netsvcs/lib/lib.mpc
+++ b/ACE/netsvcs/lib/lib.mpc
@@ -6,6 +6,7 @@ project(netsvcs): acelib {
sharedname = netsvcs
dynamicflags += ACE_NETSVCS_BUILD_DLL
Source_Files {
+ Time_Request_Reply.cpp
TS_Server_Handler.cpp
TS_Clerk_Handler.cpp
Client_Logging_Handler.cpp