diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 1997-04-16 00:47:42 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 1997-04-16 00:47:42 +0000 |
commit | 190090acf749337157815aa5cb7029b38a5dcc9d (patch) | |
tree | 242541c01b271df2241e17999c519b49f806a768 /netsvcs | |
parent | 8e4510e9774d8fc0ee8d8d5afd09aa09a0c24d12 (diff) | |
download | ATCD-190090acf749337157815aa5cb7029b38a5dcc9d.tar.gz |
*** empty log message ***
Diffstat (limited to 'netsvcs')
-rw-r--r-- | netsvcs/lib/Client_Logging_Handler.cpp | 55 | ||||
-rw-r--r-- | netsvcs/lib/Client_Logging_Handler.h | 55 | ||||
-rw-r--r-- | netsvcs/lib/Logging_Strategy.cpp | 27 | ||||
-rw-r--r-- | netsvcs/lib/Logging_Strategy.h | 27 | ||||
-rw-r--r-- | netsvcs/lib/Name_Handler.cpp | 164 | ||||
-rw-r--r-- | netsvcs/lib/Name_Handler.h | 166 | ||||
-rw-r--r-- | netsvcs/lib/Server_Logging_Handler.cpp | 98 | ||||
-rw-r--r-- | netsvcs/lib/Server_Logging_Handler.h | 98 | ||||
-rw-r--r-- | netsvcs/lib/TS_Clerk_Handler.cpp | 210 | ||||
-rw-r--r-- | netsvcs/lib/TS_Clerk_Handler.h | 207 | ||||
-rw-r--r-- | netsvcs/lib/TS_Server_Handler.cpp | 80 | ||||
-rw-r--r-- | netsvcs/lib/TS_Server_Handler.h | 80 | ||||
-rw-r--r-- | netsvcs/lib/Token_Handler.cpp | 232 | ||||
-rw-r--r-- | netsvcs/lib/Token_Handler.h | 234 |
14 files changed, 856 insertions, 877 deletions
diff --git a/netsvcs/lib/Client_Logging_Handler.cpp b/netsvcs/lib/Client_Logging_Handler.cpp index 9d140dbc650..8e600b16529 100644 --- a/netsvcs/lib/Client_Logging_Handler.cpp +++ b/netsvcs/lib/Client_Logging_Handler.cpp @@ -3,64 +3,9 @@ // Client_Logging_Handler.cpp #define ACE_BUILD_SVC_DLL -#include "ace/Service_Config.h" -#include "ace/Connector.h" #include "ace/Get_Opt.h" -#include "ace/SOCK_Connector.h" -#include "ace/SOCK_Stream.h" -#include "ace/FIFO_Recv_Msg.h" #include "Client_Logging_Handler.h" -class ACE_Svc_Export ACE_Client_Logging_Handler : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> - // = TITLE - // This client logging daemon is a mediator that receives logging - // records from local applications processes and forwards them to - // the server logging daemon running on another host. -{ -public: - // = Initialization and termination. - - ACE_Client_Logging_Handler (const char rendezvous[] = 0); - // Default constructor. - - virtual int open (void * = 0); - // Activate this instance of the <ACE_Client_Logging_Handler> - // (called by the <ACE_Client_Logging_Connector>). - - virtual ACE_HANDLE get_handle (void) const; - // Return the handle of the message_fifo_; - - virtual int close (u_long); - // Called when object is removed from the ACE_Reactor. - -protected: - virtual int handle_signal (int signum, siginfo_t *, ucontext_t *); - // Handle SIGPIPE. - - virtual int handle_input (ACE_HANDLE); - // Receive logging records from applications. - - virtual int handle_exception (ACE_HANDLE); - // Receive logging records from applications. This is necessary to handle - // madness with UNIX select, which can't deal with MSG_BAND data easily due - // to its overly simple interface... This just calls <handle_input>. - - virtual int handle_output (ACE_HANDLE); - // Called back when it's ok to send. - - int send (ACE_Log_Record &log_record); - // Send the <log_record> to the logging server. - - ACE_FIFO_Recv_Msg message_fifo_; - // Message queue we use to receive logging records from clients. - - ACE_HANDLE logging_output_; - // This is either a SOCKET (if we're connected to a logging server) - // or ACE_STDOUT. - - static void stderr_output (int = 0); -}; - ACE_Client_Logging_Handler::ACE_Client_Logging_Handler (const char rendezvous[]) : logging_output_ (ACE_STDOUT) { diff --git a/netsvcs/lib/Client_Logging_Handler.h b/netsvcs/lib/Client_Logging_Handler.h index 04e5ae9a0de..6deeed2100f 100644 --- a/netsvcs/lib/Client_Logging_Handler.h +++ b/netsvcs/lib/Client_Logging_Handler.h @@ -1,7 +1,6 @@ /* -*- C++ -*- */ // $Id$ - // ============================================================================ // // = LIBRARY @@ -18,7 +17,59 @@ #if !defined (ACE_CLIENT_LOGGER_H) #define ACE_CLIENT_LOGGER_H -#include "ace/OS.h" +#include "ace/Connector.h" +#include "ace/SOCK_Connector.h" +#include "ace/FIFO_Recv_Msg.h" + +class ACE_Svc_Export ACE_Client_Logging_Handler : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> + // = TITLE + // This client logging daemon is a mediator that receives logging + // records from local applications processes and forwards them to + // the server logging daemon running on another host. +{ +public: + // = Initialization and termination. + + ACE_Client_Logging_Handler (const char rendezvous[] = 0); + // Default constructor. + + virtual int open (void * = 0); + // Activate this instance of the <ACE_Client_Logging_Handler> + // (called by the <ACE_Client_Logging_Connector>). + + virtual ACE_HANDLE get_handle (void) const; + // Return the handle of the message_fifo_; + + virtual int close (u_long); + // Called when object is removed from the ACE_Reactor. + +protected: + virtual int handle_signal (int signum, siginfo_t *, ucontext_t *); + // Handle SIGPIPE. + + virtual int handle_input (ACE_HANDLE); + // Receive logging records from applications. + + virtual int handle_exception (ACE_HANDLE); + // Receive logging records from applications. This is necessary to handle + // madness with UNIX select, which can't deal with MSG_BAND data easily due + // to its overly simple interface... This just calls <handle_input>. + + virtual int handle_output (ACE_HANDLE); + // Called back when it's ok to send. + + int send (ACE_Log_Record &log_record); + // Send the <log_record> to the logging server. + + ACE_FIFO_Recv_Msg message_fifo_; + // Message queue we use to receive logging records from clients. + + ACE_HANDLE logging_output_; + // This is either a SOCKET (if we're connected to a logging server) + // or ACE_STDOUT. + + static void stderr_output (int = 0); +}; ACE_SVC_FACTORY_DECLARE (ACE_Client_Logging_Connector) diff --git a/netsvcs/lib/Logging_Strategy.cpp b/netsvcs/lib/Logging_Strategy.cpp index 2243f01eacf..32538a30971 100644 --- a/netsvcs/lib/Logging_Strategy.cpp +++ b/netsvcs/lib/Logging_Strategy.cpp @@ -2,37 +2,10 @@ // $Id$ #define ACE_BUILD_SVC_DLL -#include <iostream.h> #include <fstream.h> #include "ace/Get_Opt.h" - -#include "ace/Service_Object.h" #include "Logging_Strategy.h" -class ACE_Logging_Strategy : public ACE_Service_Object - // = TITLE - // This class provides the hooks to control the output produced - // by any of the network services. - // - // = DESCRIPTION - // Depending upon when this service is invoked and with what - // flags, the output of other network services can be - // controlled. The output can be streamed to stderr, to a file, - // to a logging daemon, or it can be set to be "silent". -{ -public: - virtual int init (int argc, char *argv[]); - // Dynamic linking hook. - - int parse_args (int argc, char *argv[]); - // Parse svc.conf arguments. -private: - void tokenize (char *flag_string); - // Tokenize to set all the flags - u_long flags_; - char *filename_; -}; - // Parse the string containing all the flags and set the flags accordingly void ACE_Logging_Strategy::tokenize (char *flag_string) diff --git a/netsvcs/lib/Logging_Strategy.h b/netsvcs/lib/Logging_Strategy.h index 733003eebae..06290131be5 100644 --- a/netsvcs/lib/Logging_Strategy.h +++ b/netsvcs/lib/Logging_Strategy.h @@ -1,7 +1,6 @@ /* -*- C++ -*- */ // $Id$ - // ============================================================================ // // = LIBRARY @@ -18,7 +17,31 @@ #if !defined (ACE_LOGGING_STRATEGY_H) #define ACE_LOGGING_STRATEGY_H -#include "ace/OS.h" +#include "ace/Service_Object.h" + +class ACE_Logging_Strategy : public ACE_Service_Object + // = TITLE + // This class provides the hooks to control the output produced + // by any of the network services. + // + // = DESCRIPTION + // Depending upon when this service is invoked and with what + // flags, the output of other network services can be + // controlled. The output can be streamed to stderr, to a file, + // to a logging daemon, or it can be set to be "silent". +{ +public: + virtual int init (int argc, char *argv[]); + // Dynamic linking hook. + + int parse_args (int argc, char *argv[]); + // Parse svc.conf arguments. +private: + void tokenize (char *flag_string); + // Tokenize to set all the flags + u_long flags_; + char *filename_; +}; ACE_SVC_FACTORY_DECLARE (ACE_Logging_Strategy) diff --git a/netsvcs/lib/Name_Handler.cpp b/netsvcs/lib/Name_Handler.cpp index 67fecd82109..55248dc94f1 100644 --- a/netsvcs/lib/Name_Handler.cpp +++ b/netsvcs/lib/Name_Handler.cpp @@ -6,9 +6,6 @@ #include "ace/Set.h" #include "ace/Get_Opt.h" #include "ace/Naming_Context.h" -#include "ace/Acceptor.h" -#include "ace/SOCK_Acceptor.h" -#include "ace/SOCK_Stream.h" #include "ace/Name_Request_Reply.h" #include "Name_Handler.h" @@ -18,167 +15,6 @@ // Simple macro that does bitwise AND and then right shift bits by 3 #define ACE_LIST_MAP(INDEX, MASK) (((unsigned long) (INDEX & MASK)) >> 3) -// Forward declaration. -class ACE_Naming_Context; - -class ACE_Svc_Export ACE_Name_Handler : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> - // = TITLE - // Product object created by <ACE_Name_Acceptor>. An - // <ACE_Name_Handler> exchanges messages with a <ACE_Name_Proxy> - // object on the client-side. - // - // = DESCRIPTION - // This class is the main workhorse of the <ACE_Name_Server>. It - // handles client requests to bind, rebind, resolve, and unbind - // names. It also schedules and handles timeouts that are used to - // support "timed waits." Clients used timed waits to bound the - // amount of time they block trying to get a name. -{ - friend class ACE_Shutup_GPlusPlus; // Turn off g++ warning -public: - typedef int (ACE_Name_Handler::*OPERATION) (void); - // Pointer to a member function of ACE_Name_Handler returning int - - typedef int (ACE_Naming_Context::*LIST_OP) (ACE_PWSTRING_SET &, const ACE_WString &); - // Pointer to a member function of ACE_Naming_Context returning int - - typedef ACE_Name_Request (ACE_Name_Handler::*REQUEST) (ACE_WString *); - // Pointer to a member function of ACE_Name_Handler returning ACE_Name_Request - - // = Initialization and termination. - - ACE_Name_Handler (ACE_Thread_Manager * = 0); - // Default constructor. - - virtual int open (void * = 0); - // Activate this instance of the <ACE_Name_Handler> (called by the - // <ACE_Strategy_Acceptor>). - -protected: - // = Helper routines for the operations exported to clients. - - virtual int abandon (void); - // Give up waiting (e.g., when a timeout occurs or a client shuts - // down unexpectedly). - - // = Low level routines for framing requests, dispatching - // operations, and returning replies. - - virtual int recv_request (void); - // Receive, frame, and decode the client's request. - - virtual int dispatch (void); - // Dispatch the appropriate operation to handle the client's - // request. - - virtual int send_reply (ACE_UINT32 status, ACE_UINT32 errnum = 0); - // Create and send a reply to the client. - - virtual int send_request (ACE_Name_Request &); - // Special kind of reply - - // = Demultiplexing hooks. - virtual ACE_HANDLE get_handle (void) const; - // Return the underlying <ACE_HANDLE>. - - virtual int handle_input (ACE_HANDLE); - // Callback method invoked by the <ACE_Reactor> when client events - // arrive. - - // = Timer hook. - virtual int handle_timeout (const ACE_Time_Value &tv, const void *arg); - // Enable clients to limit the amount of time they wait for a name. - -private: - - OPERATION op_table_[ACE_Name_Request::MAX_ENUM]; - // Table of pointers to member functions - - struct LIST_ENTRY - { - LIST_OP operation_; - // A member function pointer that performs the appropriate - // operation (e.g., LIST_NAMES, LIST_VALUES, or LIST_TYPES). - - REQUEST request_factory_; - // A member function pointer that serves as a factory to create a - // request that is passed back to the client. - - char *description_; - // Name of the operation we're dispatching (used for debugging). - }; - - LIST_ENTRY list_table_[ACE_Name_Request::MAX_LIST]; - // This is the table of pointers to functions that we use to - // simplify the handling of list requests. - - ACE_Naming_Context *naming_context_; - // ACE_Naming_Context of this Handler. - - ACE_Name_Request name_request_; - // Cache request from the client. - - ACE_Name_Request name_request_back_; - // Special kind of reply for resolve and listnames. - - ACE_Name_Reply name_reply_; - // Cache reply to the client. - - ACE_INET_Addr addr_; - // Address of client we are connected with. - - ~ACE_Name_Handler (void); - // Ensure dynamic allocation... - - int bind (void); - // Handle binds. - - int rebind (void); - // Handle rebinds. - - int shared_bind (int rebind); - // Handle binds and rebinds. - - int resolve (void); - // Handle find requests. - - int unbind (void); - // Handle unbind requests. - - int lists (void); - // Handle LIST_NAMES, LIST_VALUES, and LIST_TYPES requests. - - int lists_entries (void); - // Handle LIST_NAME_ENTRIES, LIST_VALUE_ENTRIES, and - // LIST_TYPE_ENTRIES requests. - - ACE_Name_Request name_request (ACE_WString *one_name); - // Create a name request. - - ACE_Name_Request value_request (ACE_WString *one_name); - // Create a value request. - - ACE_Name_Request type_request (ACE_WString *one_name); - // Create a type request. -}; - -class ACE_Name_Acceptor : public ACE_Strategy_Acceptor<ACE_Name_Handler, ACE_SOCK_ACCEPTOR> - // = TITLE - // This class contains the service-specific methods that can't - // easily be factored into the <ACE_Strategy_Acceptor>. -{ -public: - virtual int init (int argc, char *argv[]); - // Dynamic linking hook. - - int parse_args (int argc, char *argv[]); - // Parse svc.conf arguments. - -private: - ACE_Schedule_All_Reactive_Strategy<ACE_Name_Handler> scheduling_strategy_; - // The scheduling strategy is designed for Reactive services. -}; - int ACE_Name_Acceptor::parse_args (int argc, char *argv[]) { diff --git a/netsvcs/lib/Name_Handler.h b/netsvcs/lib/Name_Handler.h index 52cfebed863..b37525cdac3 100644 --- a/netsvcs/lib/Name_Handler.h +++ b/netsvcs/lib/Name_Handler.h @@ -10,14 +10,176 @@ // Name_Handler.h // // = AUTHOR -// Prashant Jain, Gerhard Lenzer and Douglas C. Schmidt +// Prashant Jain, Gerhard Lenzer, and Douglas C. Schmidt // // ============================================================================ #if !defined (ACE_NAME_HANDLER_H) #define ACE_NAME_HANDLER_H -#include "ace/OS.h" +#include "ace/Acceptor.h" +#include "ace/SOCK_Acceptor.h" + +// Forward declaration. +class ACE_Naming_Context; + +class ACE_Svc_Export ACE_Name_Handler : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> + // = TITLE + // Product object created by <ACE_Name_Acceptor>. An + // <ACE_Name_Handler> exchanges messages with a <ACE_Name_Proxy> + // object on the client-side. + // + // = DESCRIPTION + // This class is the main workhorse of the <ACE_Name_Server>. It + // handles client requests to bind, rebind, resolve, and unbind + // names. It also schedules and handles timeouts that are used to + // support "timed waits." Clients used timed waits to bound the + // amount of time they block trying to get a name. +{ + friend class ACE_Shutup_GPlusPlus; // Turn off g++ warning +public: + typedef int (ACE_Name_Handler::*OPERATION) (void); + // Pointer to a member function of ACE_Name_Handler returning int + + typedef int (ACE_Naming_Context::*LIST_OP) (ACE_PWSTRING_SET &, const ACE_WString &); + // Pointer to a member function of ACE_Naming_Context returning int + + typedef ACE_Name_Request (ACE_Name_Handler::*REQUEST) (ACE_WString *); + // Pointer to a member function of ACE_Name_Handler returning ACE_Name_Request + + // = Initialization and termination. + + ACE_Name_Handler (ACE_Thread_Manager * = 0); + // Default constructor. + + virtual int open (void * = 0); + // Activate this instance of the <ACE_Name_Handler> (called by the + // <ACE_Strategy_Acceptor>). + +protected: + // = Helper routines for the operations exported to clients. + + virtual int abandon (void); + // Give up waiting (e.g., when a timeout occurs or a client shuts + // down unexpectedly). + + // = Low level routines for framing requests, dispatching + // operations, and returning replies. + + virtual int recv_request (void); + // Receive, frame, and decode the client's request. + + virtual int dispatch (void); + // Dispatch the appropriate operation to handle the client's + // request. + + virtual int send_reply (ACE_UINT32 status, ACE_UINT32 errnum = 0); + // Create and send a reply to the client. + + virtual int send_request (ACE_Name_Request &); + // Special kind of reply + + // = Demultiplexing hooks. + virtual ACE_HANDLE get_handle (void) const; + // Return the underlying <ACE_HANDLE>. + + virtual int handle_input (ACE_HANDLE); + // Callback method invoked by the <ACE_Reactor> when client events + // arrive. + + // = Timer hook. + virtual int handle_timeout (const ACE_Time_Value &tv, const void *arg); + // Enable clients to limit the amount of time they wait for a name. + +private: + + OPERATION op_table_[ACE_Name_Request::MAX_ENUM]; + // Table of pointers to member functions + + struct LIST_ENTRY + { + LIST_OP operation_; + // A member function pointer that performs the appropriate + // operation (e.g., LIST_NAMES, LIST_VALUES, or LIST_TYPES). + + REQUEST request_factory_; + // A member function pointer that serves as a factory to create a + // request that is passed back to the client. + + char *description_; + // Name of the operation we're dispatching (used for debugging). + }; + + LIST_ENTRY list_table_[ACE_Name_Request::MAX_LIST]; + // This is the table of pointers to functions that we use to + // simplify the handling of list requests. + + ACE_Naming_Context *naming_context_; + // ACE_Naming_Context of this Handler. + + ACE_Name_Request name_request_; + // Cache request from the client. + + ACE_Name_Request name_request_back_; + // Special kind of reply for resolve and listnames. + + ACE_Name_Reply name_reply_; + // Cache reply to the client. + + ACE_INET_Addr addr_; + // Address of client we are connected with. + + ~ACE_Name_Handler (void); + // Ensure dynamic allocation... + + int bind (void); + // Handle binds. + + int rebind (void); + // Handle rebinds. + + int shared_bind (int rebind); + // Handle binds and rebinds. + + int resolve (void); + // Handle find requests. + + int unbind (void); + // Handle unbind requests. + + int lists (void); + // Handle LIST_NAMES, LIST_VALUES, and LIST_TYPES requests. + + int lists_entries (void); + // Handle LIST_NAME_ENTRIES, LIST_VALUE_ENTRIES, and + // LIST_TYPE_ENTRIES requests. + + ACE_Name_Request name_request (ACE_WString *one_name); + // Create a name request. + + ACE_Name_Request value_request (ACE_WString *one_name); + // Create a value request. + + ACE_Name_Request type_request (ACE_WString *one_name); + // Create a type request. +}; + +class ACE_Name_Acceptor : public ACE_Strategy_Acceptor<ACE_Name_Handler, ACE_SOCK_ACCEPTOR> + // = TITLE + // This class contains the service-specific methods that can't + // easily be factored into the <ACE_Strategy_Acceptor>. +{ +public: + virtual int init (int argc, char *argv[]); + // Dynamic linking hook. + + int parse_args (int argc, char *argv[]); + // Parse svc.conf arguments. + +private: + ACE_Schedule_All_Reactive_Strategy<ACE_Name_Handler> scheduling_strategy_; + // The scheduling strategy is designed for Reactive services. +}; ACE_SVC_FACTORY_DECLARE (ACE_Name_Acceptor) diff --git a/netsvcs/lib/Server_Logging_Handler.cpp b/netsvcs/lib/Server_Logging_Handler.cpp index cdf34c24ead..57a665da2c0 100644 --- a/netsvcs/lib/Server_Logging_Handler.cpp +++ b/netsvcs/lib/Server_Logging_Handler.cpp @@ -2,85 +2,15 @@ // Server_Logging_Handler.cpp #define ACE_BUILD_SVC_DLL -#include "ace/Synch.h" -#include "ace/TLI_Acceptor.h" -#include "ace/SOCK_Acceptor.h" - #include "ace/Get_Opt.h" -#include "ace/Acceptor.h" #include "Server_Logging_Handler.h" -template <ACE_PEER_STREAM_1, class COUNTER, ACE_SYNCH_1> -class ACE_Server_Logging_Handler : public ACE_Svc_Handler<ACE_PEER_STREAM_2, ACE_SYNCH_2> -{ - // = TITLE - // Product object created by an <ACE_Server_Logging_Acceptor>. An - // <ACE_Server_Logging_Handler> receives, frames, and processes logging - // records. - // - // = DESCRIPTION - // Defines the classes that perform server logging daemon - // functionality. -public: - ACE_Server_Logging_Handler (ACE_Thread_Manager * = 0); - - virtual int open (void * = 0); - // Hook called by <Server_Logging_Acceptor> when connection is - // established. - - virtual int handle_input (ACE_HANDLE = ACE_INVALID_HANDLE); - // Process remote logging records. - -protected: - int handle_logging_record (void); - // Receive the logging record from a client. - -#if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) - static COUNTER request_count_; - // Count the number of logging records that arrive. -#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */ - - char host_name_[MAXHOSTNAMELEN + 1]; - // Name of the host we are connected to. -}; - -#if !defined (ACE_HAS_TLI) -#define LOGGING_PEER_ACCEPTOR ACE_SOCK_ACCEPTOR -#define LOGGING_PEER_STREAM ACE_SOCK_STREAM -#else /* use sockets */ -#define LOGGING_PEER_ACCEPTOR ACE_TLI_ACCEPTOR -#define LOGGING_PEER_STREAM ACE_TLI_STREAM -#endif /* ACE_HAS_TLI */ - #if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) // Track number of requests. template <ACE_PEER_STREAM_1, class COUNTER, ACE_SYNCH_1> COUNTER ACE_Server_Logging_Handler<ACE_PEER_STREAM_2, COUNTER, ACE_SYNCH_2>::request_count_ = (COUNTER) 0; #endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */ -typedef ACE_Server_Logging_Handler<LOGGING_PEER_STREAM, u_long, ACE_NULL_SYNCH> - SERVER_LOGGING_HANDLER; - -class ACE_Server_Logging_Acceptor : public ACE_Strategy_Acceptor<SERVER_LOGGING_HANDLER, LOGGING_PEER_ACCEPTOR> - // = TITLE - // This class implements the ACE single-threaded logging service. - // - // = DESCRIPTION - // This class contains the service-specific methods that can't - // easily be factored into the <ACE_Strategy_Acceptor>. -{ -public: - virtual int init (int argc, char *argv[]); - // Dynamic linking hook. - - int parse_args (int argc, char *argv[]); - // Parse svc.conf arguments. - -private: - ACE_Schedule_All_Reactive_Strategy<SERVER_LOGGING_HANDLER> scheduling_strategy_; - // The scheduling strategy is designed for Reactive services. -}; - int ACE_Server_Logging_Acceptor::parse_args (int argc, char *argv[]) { @@ -261,34 +191,6 @@ ACE_Server_Logging_Handler<ACE_PEER_STREAM_2, COUNTER, ACE_SYNCH_2>::handle_inpu return this->handle_logging_record () > 0 ? 0 : -1; } -#if !defined (ACE_HAS_THREADS) -typedef u_long COUNTER; -#define ACE_LOGGER_SYNCH ACE_NULL_SYNCH -#else -typedef ACE_Atomic_Op <ACE_Thread_Mutex, u_long> COUNTER; -#define ACE_LOGGER_SYNCH ACE_MT_SYNCH -#endif /* ACE_HAS_THREADS */ - -class ACE_Svc_Export ACE_Thr_Server_Logging_Handler : public ACE_Server_Logging_Handler<LOGGING_PEER_STREAM, COUNTER, ACE_LOGGER_SYNCH> - // = TITLE - // Product object created by a <ACE_Thr_Server_Logging_Acceptor>. An - // <ACE_Thr_Server_Logging_Handler> receives, frames, and processes - // logging records. - // - // = DESCRIPTION - // Each client is handled in its own separate thread. -{ -public: - ACE_Thr_Server_Logging_Handler (ACE_Thread_Manager * = 0); - - virtual int open (void * = 0); - // Override activation definition in the ACE_Svc_Handler class (will - // spawn a new thread if we've got threads). - - virtual int svc (void); - // Process remote logging records. -}; - class ACE_Thr_Server_Logging_Acceptor : public ACE_Strategy_Acceptor<ACE_Thr_Server_Logging_Handler, LOGGING_PEER_ACCEPTOR> // = TITLE // This class implements the ACE multi-threaded logging service. diff --git a/netsvcs/lib/Server_Logging_Handler.h b/netsvcs/lib/Server_Logging_Handler.h index 03730b0d1d5..863d3925aed 100644 --- a/netsvcs/lib/Server_Logging_Handler.h +++ b/netsvcs/lib/Server_Logging_Handler.h @@ -18,7 +18,103 @@ #if !defined (ACE_SERVER_LOGGING_HANDLER_H) #define ACE_SERVER_LOGGING_HANDLER_H -#include "ace/OS.h" +#include "ace/Synch.h" +#include "ace/TLI_Acceptor.h" +#include "ace/SOCK_Acceptor.h" +#include "ace/Acceptor.h" + +template <ACE_PEER_STREAM_1, class COUNTER, ACE_SYNCH_1> +class ACE_Server_Logging_Handler : public ACE_Svc_Handler<ACE_PEER_STREAM_2, ACE_SYNCH_2> +{ + // = TITLE + // Product object created by an <ACE_Server_Logging_Acceptor>. An + // <ACE_Server_Logging_Handler> receives, frames, and processes logging + // records. + // + // = DESCRIPTION + // Defines the classes that perform server logging daemon + // functionality. +public: + ACE_Server_Logging_Handler (ACE_Thread_Manager * = 0); + + virtual int open (void * = 0); + // Hook called by <Server_Logging_Acceptor> when connection is + // established. + + virtual int handle_input (ACE_HANDLE = ACE_INVALID_HANDLE); + // Process remote logging records. + +protected: + int handle_logging_record (void); + // Receive the logging record from a client. + +#if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) + static COUNTER request_count_; + // Count the number of logging records that arrive. +#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */ + + char host_name_[MAXHOSTNAMELEN + 1]; + // Name of the host we are connected to. +}; + +#if !defined (ACE_HAS_TLI) +#define LOGGING_PEER_ACCEPTOR ACE_SOCK_ACCEPTOR +#define LOGGING_PEER_STREAM ACE_SOCK_STREAM +#else /* use sockets */ +#define LOGGING_PEER_ACCEPTOR ACE_TLI_ACCEPTOR +#define LOGGING_PEER_STREAM ACE_TLI_STREAM +#endif /* ACE_HAS_TLI */ + +typedef ACE_Server_Logging_Handler<LOGGING_PEER_STREAM, u_long, ACE_NULL_SYNCH> + SERVER_LOGGING_HANDLER; + +class ACE_Server_Logging_Acceptor : public ACE_Strategy_Acceptor<SERVER_LOGGING_HANDLER, LOGGING_PEER_ACCEPTOR> + // = TITLE + // This class implements the ACE single-threaded logging service. + // + // = DESCRIPTION + // This class contains the service-specific methods that can't + // easily be factored into the <ACE_Strategy_Acceptor>. +{ +public: + virtual int init (int argc, char *argv[]); + // Dynamic linking hook. + + int parse_args (int argc, char *argv[]); + // Parse svc.conf arguments. + +private: + ACE_Schedule_All_Reactive_Strategy<SERVER_LOGGING_HANDLER> scheduling_strategy_; + // The scheduling strategy is designed for Reactive services. +}; + +#if !defined (ACE_HAS_THREADS) +typedef u_long COUNTER; +#define ACE_LOGGER_SYNCH ACE_NULL_SYNCH +#else +typedef ACE_Atomic_Op <ACE_Thread_Mutex, u_long> COUNTER; +#define ACE_LOGGER_SYNCH ACE_MT_SYNCH +#endif /* ACE_HAS_THREADS */ + +class ACE_Svc_Export ACE_Thr_Server_Logging_Handler : public ACE_Server_Logging_Handler<LOGGING_PEER_STREAM, COUNTER, ACE_LOGGER_SYNCH> + // = TITLE + // Product object created by a <ACE_Thr_Server_Logging_Acceptor>. An + // <ACE_Thr_Server_Logging_Handler> receives, frames, and processes + // logging records. + // + // = DESCRIPTION + // Each client is handled in its own separate thread. +{ +public: + ACE_Thr_Server_Logging_Handler (ACE_Thread_Manager * = 0); + + virtual int open (void * = 0); + // Override activation definition in the ACE_Svc_Handler class (will + // spawn a new thread if we've got threads). + + virtual int svc (void); + // Process remote logging records. +}; ACE_SVC_FACTORY_DECLARE (ACE_Server_Logging_Acceptor) ACE_SVC_FACTORY_DECLARE (ACE_Thr_Server_Logging_Acceptor) diff --git a/netsvcs/lib/TS_Clerk_Handler.cpp b/netsvcs/lib/TS_Clerk_Handler.cpp index dfdfb84f00e..51fb22cfa10 100644 --- a/netsvcs/lib/TS_Clerk_Handler.cpp +++ b/netsvcs/lib/TS_Clerk_Handler.cpp @@ -3,220 +3,10 @@ // TS_Clerk_Handler.cpp #define ACE_BUILD_SVC_DLL -#include "ace/Service_Config.h" -#include "ace/Connector.h" #include "ace/Get_Opt.h" -#include "ace/SOCK_Connector.h" -#include "ace/SOCK_Stream.h" -#include "ace/Svc_Handler.h" #include "ace/Time_Request_Reply.h" -#include "ace/OS.h" -#include "ace/Malloc.h" #include "TS_Clerk_Handler.h" -// A simple struct containing delta time and a sequence number -struct ACE_Time_Info -{ - long delta_time_; - ACE_UINT32 sequence_num_; -}; - -class ACE_TS_Clerk_Processor; // forward declaration - -class ACE_Svc_Export ACE_TS_Clerk_Handler : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> - // = TITLE - // The Clerk Handler provides the interface that is used by the - // Clerk Processor to send time update requests to all the - // servers. It obtains these updates from the servers and passes - // the updates to the Clerk Processor - // - // = DESCRIPTION - // The Clerk Processor uses send_request() to send a request for - // time update to a server. The Clerk Handler internally computes - // the round trip delay for the reply to come back. Once it gets - // the reply back from the server (handle_input), it adjusts the - // system time using the round trip delay estimate and then - // passes the delta time by reference back to the Clerk Processor. -{ -public: - ACE_TS_Clerk_Handler (ACE_TS_Clerk_Processor *processor = 0, - ACE_INET_Addr &addr = (ACE_INET_Addr &) ACE_Addr::sap_any); - // Default constructor. - - // = Set/get the current state - enum State - { - IDLE = 1, // Prior to initialization. - CONNECTING, // During connection establishment. - ESTABLISHED, // Connection is established and active. - DISCONNECTING, // In the process of disconnecting. - FAILED // Connection has failed. - }; - - // = Set/get the current state. - State state (void); - void state (State); - - // = Set/get the current retry timeout delay. - int timeout (void); - void timeout (int); - - // = Set/get the maximum retry timeout delay. - int max_timeout (void); - void max_timeout (int); - - virtual int open (void * = 0); - // Activate this instance of the <ACE_TS_Clerk_Handler> - // (called by the <ACE_TS_Clerk_Processor>). - - virtual ACE_HANDLE get_handle (void) const; - // Return the handle of the message_fifo_; - - virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE, - ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK); - // Called when object is removed from the ACE_Reactor - - virtual int handle_input (ACE_HANDLE); - // Receive time update from a server. - - virtual int handle_timeout (const ACE_Time_Value &tv, - const void *arg); - // Restart connection asynchronously when timeout occurs. - - void remote_addr (ACE_INET_Addr &addr); - ACE_INET_Addr &remote_addr (void); - // Get/Set remote addr - - int send_request (ACE_UINT32 sequence_num, ACE_Time_Info &time_info); - // Send request for time update to the server as well as return the - // current time info by reference. - -protected: - virtual int handle_signal (int signum, siginfo_t *, ucontext_t *); - // Handle SIGPIPE. - - static void stderr_output (int = 0); - - enum - { - MAX_RETRY_TIMEOUT = 300 // 5 minutes is the maximum timeout. - }; -private: - int recv_reply (ACE_Time_Request &reply); - // Receive a reply from a server containing time update - - int reinitiate_connection (void); - // Reinitiate connection with the server - - State state_; - // The current state of the connection - - int timeout_; - // Amount of time to wait between reconnection attempts - - int max_timeout_; - // Maximum amount of time to wait between reconnection attempts - - ACE_INET_Addr remote_addr_; - // Remote Addr used for connecting to the server - - ACE_TS_Clerk_Processor *processor_; - // Instance of Clerk Processor used for re-establishing connections - - ACE_UINT32 start_time_; - // Time at which request was sent (used to compute round trip delay) - - ACE_UINT32 cur_sequence_num_; - // Next sequence number of time request (waiting for this update from - // the server). - - ACE_Time_Info time_info_; - // Record of current delta time and current sequence number -}; - -class ACE_TS_Clerk_Processor : public ACE_Connector <ACE_TS_Clerk_Handler, ACE_SOCK_CONNECTOR> - // = TITLE - // This class manages all the connections to the servers along - // with querying them periodically for time updates. - // = DESCRIPTION - // The Clerk Processor creates connections to all the servers and - // creates an ACE_TS_Clerk_Handler for each connection to handle - // the requests and replies. It periodically sends a request for - // time update through each of the handlers and uses the replies for - // computing a synchronized system time. -{ -public: - ACE_TS_Clerk_Processor (void); - // Default constructor - - virtual int handle_timeout (const ACE_Time_Value &tv, - const void *arg); - // Query servers for time periodically (timeout value) - - int initiate_connection (ACE_TS_Clerk_Handler *, ACE_Synch_Options &); - // Set up connections to all servers - -protected: - // = Dynamic linking hooks. - virtual int init (int argc, char *argv[]); - // Called when service is linked. - - virtual int fini (void); - // Called when service is unlinked. - - virtual int info (char **strp, size_t length) const; - // Called to determine info about the service. - - // = Scheduling hooks. - virtual int suspend (void); - virtual int resume (void); - -private: - int parse_args (int argc, char *argv[]); - // Parse svc.conf arguments. - - void alloc (void); - // Allocate entry in shared memory for system time - - int update_time (); - // Update delta_time using times obtained from all servers - - typedef ACE_Malloc <ACE_MMAP_MEMORY_POOL, ACE_Null_Mutex> MALLOC; - typedef ACE_Allocator_Adapter<MALLOC> ALLOCATOR; - ALLOCATOR *shmem_; - // Allocator (used for reading/writing system time from/to shared memory) - - typedef ACE_Unbounded_Set <ACE_TS_Clerk_Handler *> HANDLER_SET; - typedef ACE_Unbounded_Set_Iterator <ACE_TS_Clerk_Handler *> HANDLER_SET_ITERATOR; - HANDLER_SET handler_set_; - // Set of TS_Clerk_Handlers and iterator over the set. - - struct System_Time - { - long *delta_time_; // Difference between system time and local time - long *last_local_time_; // Last local time - }; - - System_Time system_time_; - // Clerk system time containing pointers to entries in shared memory - - int timer_id_; - // Timer id returned by Reactor - - int timeout_; - // Time period for updating system time - - LPCTSTR poolname_; - // Pool name for backing store - - int blocking_semantics_; - // Do a blocking/non-blocking connect - - ACE_UINT32 cur_sequence_num_; - // Sequence number of next expected update from servers -}; - - ACE_TS_Clerk_Handler::ACE_TS_Clerk_Handler (ACE_TS_Clerk_Processor *processor, ACE_INET_Addr &addr) : state_ (ACE_TS_Clerk_Handler::IDLE), diff --git a/netsvcs/lib/TS_Clerk_Handler.h b/netsvcs/lib/TS_Clerk_Handler.h index a1dcccdd4d9..1fa50763d85 100644 --- a/netsvcs/lib/TS_Clerk_Handler.h +++ b/netsvcs/lib/TS_Clerk_Handler.h @@ -1,7 +1,6 @@ /* -*- C++ -*- */ // $Id$ - // ============================================================================ // // = LIBRARY @@ -18,6 +17,212 @@ #if !defined (ACE_TS_CLERK_HANDLER_H) #define ACE_TS_CLERK_HANDLER_H +#include "ace/Connector.h" +#include "ace/SOCK_Connector.h" +#include "ace/Malloc.h" + +// A simple struct containing delta time and a sequence number +struct ACE_Time_Info +{ + long delta_time_; + ACE_UINT32 sequence_num_; +}; + +class ACE_TS_Clerk_Processor; // forward declaration + +class ACE_Svc_Export ACE_TS_Clerk_Handler : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> + // = TITLE + // The Clerk Handler provides the interface that is used by the + // Clerk Processor to send time update requests to all the + // servers. It obtains these updates from the servers and passes + // the updates to the Clerk Processor + // + // = DESCRIPTION + // The Clerk Processor uses send_request() to send a request for + // time update to a server. The Clerk Handler internally computes + // the round trip delay for the reply to come back. Once it gets + // the reply back from the server (handle_input), it adjusts the + // system time using the round trip delay estimate and then + // passes the delta time by reference back to the Clerk Processor. +{ +public: + ACE_TS_Clerk_Handler (ACE_TS_Clerk_Processor *processor = 0, + ACE_INET_Addr &addr = (ACE_INET_Addr &) ACE_Addr::sap_any); + // Default constructor. + + // = Set/get the current state + enum State + { + IDLE = 1, // Prior to initialization. + CONNECTING, // During connection establishment. + ESTABLISHED, // Connection is established and active. + DISCONNECTING, // In the process of disconnecting. + FAILED // Connection has failed. + }; + + // = Set/get the current state. + State state (void); + void state (State); + + // = Set/get the current retry timeout delay. + int timeout (void); + void timeout (int); + + // = Set/get the maximum retry timeout delay. + int max_timeout (void); + void max_timeout (int); + + virtual int open (void * = 0); + // Activate this instance of the <ACE_TS_Clerk_Handler> + // (called by the <ACE_TS_Clerk_Processor>). + + virtual ACE_HANDLE get_handle (void) const; + // Return the handle of the message_fifo_; + + virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE, + ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK); + // Called when object is removed from the ACE_Reactor + + virtual int handle_input (ACE_HANDLE); + // Receive time update from a server. + + virtual int handle_timeout (const ACE_Time_Value &tv, + const void *arg); + // Restart connection asynchronously when timeout occurs. + + void remote_addr (ACE_INET_Addr &addr); + ACE_INET_Addr &remote_addr (void); + // Get/Set remote addr + + int send_request (ACE_UINT32 sequence_num, ACE_Time_Info &time_info); + // Send request for time update to the server as well as return the + // current time info by reference. + +protected: + virtual int handle_signal (int signum, siginfo_t *, ucontext_t *); + // Handle SIGPIPE. + + static void stderr_output (int = 0); + + enum + { + MAX_RETRY_TIMEOUT = 300 // 5 minutes is the maximum timeout. + }; +private: + int recv_reply (ACE_Time_Request &reply); + // Receive a reply from a server containing time update + + int reinitiate_connection (void); + // Reinitiate connection with the server + + State state_; + // The current state of the connection + + int timeout_; + // Amount of time to wait between reconnection attempts + + int max_timeout_; + // Maximum amount of time to wait between reconnection attempts + + ACE_INET_Addr remote_addr_; + // Remote Addr used for connecting to the server + + ACE_TS_Clerk_Processor *processor_; + // Instance of Clerk Processor used for re-establishing connections + + ACE_UINT32 start_time_; + // Time at which request was sent (used to compute round trip delay) + + ACE_UINT32 cur_sequence_num_; + // Next sequence number of time request (waiting for this update from + // the server). + + ACE_Time_Info time_info_; + // Record of current delta time and current sequence number +}; + +class ACE_TS_Clerk_Processor : public ACE_Connector <ACE_TS_Clerk_Handler, ACE_SOCK_CONNECTOR> + // = TITLE + // This class manages all the connections to the servers along + // with querying them periodically for time updates. + // = DESCRIPTION + // The Clerk Processor creates connections to all the servers and + // creates an ACE_TS_Clerk_Handler for each connection to handle + // the requests and replies. It periodically sends a request for + // time update through each of the handlers and uses the replies for + // computing a synchronized system time. +{ +public: + ACE_TS_Clerk_Processor (void); + // Default constructor + + virtual int handle_timeout (const ACE_Time_Value &tv, + const void *arg); + // Query servers for time periodically (timeout value) + + int initiate_connection (ACE_TS_Clerk_Handler *, ACE_Synch_Options &); + // Set up connections to all servers + +protected: + // = Dynamic linking hooks. + virtual int init (int argc, char *argv[]); + // Called when service is linked. + + virtual int fini (void); + // Called when service is unlinked. + + virtual int info (char **strp, size_t length) const; + // Called to determine info about the service. + + // = Scheduling hooks. + virtual int suspend (void); + virtual int resume (void); + +private: + int parse_args (int argc, char *argv[]); + // Parse svc.conf arguments. + + void alloc (void); + // Allocate entry in shared memory for system time + + int update_time (); + // Update delta_time using times obtained from all servers + + typedef ACE_Malloc <ACE_MMAP_MEMORY_POOL, ACE_Null_Mutex> MALLOC; + typedef ACE_Allocator_Adapter<MALLOC> ALLOCATOR; + ALLOCATOR *shmem_; + // Allocator (used for reading/writing system time from/to shared memory) + + typedef ACE_Unbounded_Set <ACE_TS_Clerk_Handler *> HANDLER_SET; + typedef ACE_Unbounded_Set_Iterator <ACE_TS_Clerk_Handler *> HANDLER_SET_ITERATOR; + HANDLER_SET handler_set_; + // Set of TS_Clerk_Handlers and iterator over the set. + + struct System_Time + { + long *delta_time_; // Difference between system time and local time + long *last_local_time_; // Last local time + }; + + System_Time system_time_; + // Clerk system time containing pointers to entries in shared memory + + int timer_id_; + // Timer id returned by Reactor + + int timeout_; + // Time period for updating system time + + LPCTSTR poolname_; + // Pool name for backing store + + int blocking_semantics_; + // Do a blocking/non-blocking connect + + ACE_UINT32 cur_sequence_num_; + // Sequence number of next expected update from servers +}; + ACE_SVC_FACTORY_DECLARE (ACE_TS_Clerk_Processor) #endif /* ACE_TS_CLERK_HANDLER_H */ diff --git a/netsvcs/lib/TS_Server_Handler.cpp b/netsvcs/lib/TS_Server_Handler.cpp index 2b3944081a6..86cc4f3cb1d 100644 --- a/netsvcs/lib/TS_Server_Handler.cpp +++ b/netsvcs/lib/TS_Server_Handler.cpp @@ -5,89 +5,9 @@ #include "ace/SString.h" #include "ace/Set.h" #include "ace/Get_Opt.h" -#include "ace/Acceptor.h" -#include "ace/SOCK_Acceptor.h" -#include "ace/SOCK_Stream.h" #include "ace/Time_Request_Reply.h" #include "TS_Server_Handler.h" -class ACE_Svc_Export ACE_TS_Server_Handler : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> - // = TITLE - // Product object created by <ACE_TS_Server_Acceptor>. - // - // = DESCRIPTION -{ - friend class ACE_Shutup_GPlusPlus; // Turn off g++ warning -public: - // = Initialization and termination. - - ACE_TS_Server_Handler (ACE_Thread_Manager * = 0); - // Default constructor. - - virtual int open (void * = 0); - // Activate this instance of the <ACE_TS_Server_Handler> (called by the - // <ACE_Strategy_Acceptor>). - - ~ACE_TS_Server_Handler (void); - // Must be allocated dynamically. - -protected: - // = Helper routines for the operations exported to clients. - - virtual int abandon (void); - // Give up waiting (e.g., when a timeout occurs or a client shuts - // down unexpectedly). - - // = Low level routines for framing requests, dispatching - // operations, and returning replies. - - virtual int recv_request (void); - // Receive, frame, and decode the client's request. - - virtual int dispatch (void); - // Dispatch the appropriate operation to handle the client's - // request. - - virtual int send_request (ACE_Time_Request &); - // Special kind of reply - - // = Demultiplexing hooks. - virtual ACE_HANDLE get_handle (void) const; - // Return the underlying <ACE_HANDLE>. - - virtual int handle_input (ACE_HANDLE); - // Callback method invoked by the <ACE_Reactor> when client events - // arrive. - - // = Timer hook. - virtual int handle_timeout (const ACE_Time_Value &tv, const void *arg); - // Enable clients to limit the amount of time they wait. - -private: - ACE_Time_Request time_request_; - // Cache request from the client. - - ACE_INET_Addr addr_; - // Address of client we are connected with. -}; - -class ACE_TS_Server_Acceptor : public ACE_Strategy_Acceptor<ACE_TS_Server_Handler, ACE_SOCK_ACCEPTOR> - // = TITLE - // This class contains the service-specific methods that can't - // easily be factored into the <ACE_Strategy_Acceptor>. -{ -public: - virtual int init (int argc, char *argv[]); - // Dynamic linking hook. - - int parse_args (int argc, char *argv[]); - // Parse svc.conf arguments. - -private: - ACE_Schedule_All_Reactive_Strategy<ACE_TS_Server_Handler> scheduling_strategy_; - // The scheduling strategy is designed for Reactive services. -}; - int ACE_TS_Server_Acceptor::parse_args (int argc, char *argv[]) { diff --git a/netsvcs/lib/TS_Server_Handler.h b/netsvcs/lib/TS_Server_Handler.h index 6fff595c215..3cea3bd9de6 100644 --- a/netsvcs/lib/TS_Server_Handler.h +++ b/netsvcs/lib/TS_Server_Handler.h @@ -17,7 +17,85 @@ #if !defined (ACE_TS_SERVER_HANDLER_H) #define ACE_TS_SERVER_HANDLER_H -#include "ace/OS.h" +#include "ace/Acceptor.h" +#include "ace/SOCK_Acceptor.h" + +class ACE_Svc_Export ACE_TS_Server_Handler : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> + // = TITLE + // Product object created by <ACE_TS_Server_Acceptor>. + // + // = DESCRIPTION +{ + friend class ACE_Shutup_GPlusPlus; // Turn off g++ warning +public: + // = Initialization and termination. + + ACE_TS_Server_Handler (ACE_Thread_Manager * = 0); + // Default constructor. + + virtual int open (void * = 0); + // Activate this instance of the <ACE_TS_Server_Handler> (called by the + // <ACE_Strategy_Acceptor>). + + ~ACE_TS_Server_Handler (void); + // Must be allocated dynamically. + +protected: + // = Helper routines for the operations exported to clients. + + virtual int abandon (void); + // Give up waiting (e.g., when a timeout occurs or a client shuts + // down unexpectedly). + + // = Low level routines for framing requests, dispatching + // operations, and returning replies. + + virtual int recv_request (void); + // Receive, frame, and decode the client's request. + + virtual int dispatch (void); + // Dispatch the appropriate operation to handle the client's + // request. + + virtual int send_request (ACE_Time_Request &); + // Special kind of reply + + // = Demultiplexing hooks. + virtual ACE_HANDLE get_handle (void) const; + // Return the underlying <ACE_HANDLE>. + + virtual int handle_input (ACE_HANDLE); + // Callback method invoked by the <ACE_Reactor> when client events + // arrive. + + // = Timer hook. + virtual int handle_timeout (const ACE_Time_Value &tv, const void *arg); + // Enable clients to limit the amount of time they wait. + +private: + ACE_Time_Request time_request_; + // Cache request from the client. + + ACE_INET_Addr addr_; + // Address of client we are connected with. +}; + +class ACE_TS_Server_Acceptor : public ACE_Strategy_Acceptor<ACE_TS_Server_Handler, ACE_SOCK_ACCEPTOR> + // = TITLE + // This class contains the service-specific methods that can't + // easily be factored into the <ACE_Strategy_Acceptor>. +{ +public: + virtual int init (int argc, char *argv[]); + // Dynamic linking hook. + + int parse_args (int argc, char *argv[]); + // Parse svc.conf arguments. + +private: + ACE_Schedule_All_Reactive_Strategy<ACE_TS_Server_Handler> scheduling_strategy_; + // The scheduling strategy is designed for Reactive services. +}; ACE_SVC_FACTORY_DECLARE (ACE_TS_Server_Acceptor) diff --git a/netsvcs/lib/Token_Handler.cpp b/netsvcs/lib/Token_Handler.cpp index e8165cd0ef4..bd79e90fc71 100644 --- a/netsvcs/lib/Token_Handler.cpp +++ b/netsvcs/lib/Token_Handler.cpp @@ -5,240 +5,8 @@ #define ACE_BUILD_SVC_DLL #include "ace/Get_Opt.h" -#include "ace/Acceptor.h" -#include "ace/SOCK_Acceptor.h" -#include "ace/Token_Request_Reply.h" -#include "ace/Token_Collection.h" -#include "ace/Local_Tokens.h" #include "Token_Handler.h" -class ACE_Svc_Export ACE_Token_Handler : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> - // = TITLE - // Product object created by an <ACE_Token_Acceptor>. A - // <Token_Handler> exchanges messages with a <Token_Proxy> object - // on the client-side. - // - // = DESCRIPTION - // This class is the main workhorse of the ACE Token service. It - // receives token operation requests from remote clients and turns - // them into calls on local tokens (acquire, release, renew, and - // remove). In OMG CORBA terms, it is an object adapter. It also - // schedules and handles timeouts that are used to support "timed - // waits." Clients used timed waits to bound the amount of time - // they block trying to get a token. - -{ -public: - // = Initialization and termination. - - ACE_Token_Handler (ACE_Thread_Manager * = 0); - // Default constructor. - - // = Accessor and mutator methods. - - // = Remote operations "exported" to a client. - virtual int acquire (ACE_Token_Proxy *proxy); - // Try to acquire the token. - // Precondition: client *may* hold the token already (i.e., - // supports recursive acquisitions). - - virtual int try_acquire (ACE_Token_Proxy *proxy); - // Try to acquire the token. - - virtual int release (ACE_Token_Proxy *proxy); - // Release the token and allow the next client that is waiting to - // proceed. Preconditions: client must hold the token. - - virtual int renew (ACE_Token_Proxy *proxy); - // Yield the token if any clients are waiting, otherwise keep the - // token. Preconditions: client must hold the token. - - virtual int remove (ACE_Token_Proxy *proxy); - // Remove the specified token from the Token_Map. Preconditions: - // ACE_Token must exist. @@ Any other preconditions, e.g., must - // client hold token, must there be no waiters, etc.? - - void sleep_hook (void); - // Called by TS_[Mutex,RLock,WLock] when we hold the mutex and - // someone wants it. - - void token_acquired (ACE_TPQ_Entry *); - // Called by TS_[Mutex,RLock,WLock] when we are waiting and acquire - // the mutex. - -protected: - // = Low level routines for framing requests, dispatching - // operations, and returning replies. - - virtual int abandon (int send_error); - // Our connection has been closed. - - virtual int recv_request (void); - // Receive, frame, and decode the client's request. - - virtual int dispatch (void); - // Dispatch the appropriate operation to handle the client's - // request. - - virtual int send_reply (ACE_UINT32 errnum); - // Create and send a reply to the client. - - // = Demultiplexing hooks. - virtual int handle_input (ACE_HANDLE); - // Callback method invoked by the <ACE_Reactor> when client events - // arrive. - - // = Timer hook. - virtual int handle_timeout (const ACE_Time_Value &tv, const void *arg); - // Enable clients to limit the amount of time they wait for a token. - - ACE_Token_Proxy *get_proxy (void); - // return a proxy for the calling client_id and token name. - -private: - - virtual ACE_Token_Proxy *create_proxy (void); - // Switches on the type of token_request_ and creates a new - // Token_Proxy. - - ACE_Synch_Options request_options_; - // Keeps track of the synchronization options (i.e., the timeout - // interval). - - ACE_Token_Collection collection_; - // collection of the client's token proxies. - - int timeout_id_; - // ID returned by the Reactor that is used to kill registered timers - // when a token operation times out. - - ACE_Token_Request token_request_; - // Cache request from the client. - - ACE_Token_Reply token_reply_; - // Cache reply to the client. -}; - -// = DESCRIPTION of ACE_TS_* classes: -// When Tokens are released, waiting token proxies are notified -// when the releasing thread calls token_acquired on the waiting -// proxy. The Token Server specializes ACE_Token_Proxy to -// redefine the implementation of token_acquired. When -// token_acquired is called, the Token_Handler can then send the -// response back over the socket connection to unblock the -// client side. -// Since only the Token_Handler uses ACE_TS_Mutex, we've moved -// the definition to the .cpp file. - -class ACE_TS_Mutex : public ACE_Local_Mutex - // = TITLE - // ACE_TS_Mutex -- ACE_*T*oken_*S*erver_Mutex -{ -public: - ACE_TS_Mutex (const char *name, - ACE_Token_Handler *th); - // Creation. - -protected: - virtual void sleep_hook (void); - // Somebody wants our token! - - virtual void token_acquired (ACE_TPQ_Entry *); - // We've been taken off the waiters list and given the token! Call - // the Token_Handler associated at construction, so it can tell the - // remote client. - - ACE_TS_Mutex (const ACE_TS_Mutex &); - // Duplication. - - virtual ACE_Token_Proxy *clone (void) const; - // Return a deep copy. - -private: - ACE_Token_Handler* th_; - // The Token Handler associated with this proxy. Set at - // construction and notified when blocking acquires succeed. -}; - -class ACE_TS_RLock : public ACE_Local_RLock - // = TITLE - // ACE_TS_RLock -- ACE_*T*oken_*S*erver_RLock -{ -public: - ACE_TS_RLock (const char *name, - ACE_Token_Handler *th); - // Creation. - -protected: - virtual void sleep_hook (void); - // Somebody wants our token! - - virtual void token_acquired (ACE_TPQ_Entry *); - // We've been taken off the waiters list and given the token! Call - // the Token_Handler associated at construction, so it can tell the - // remote client. - - ACE_TS_RLock (const ACE_TS_RLock&); - // Duplication. - - virtual ACE_Token_Proxy *clone (void) const; - // Return a deep copy. - -private: - ACE_Token_Handler* th_; - // the Token Handler associated with this proxy. Set at - // construction and notified when blocking acquires succeed. -}; - -class ACE_TS_WLock : public ACE_Local_WLock - // = TITLE - // ACE_TS_WLock -- ACE_*T*oken_*S*erver_WLock -{ -public: - ACE_TS_WLock (const char *name, - ACE_Token_Handler *th); - // Creation. - -protected: - virtual void sleep_hook (void); - // Somebody wants our token! - - virtual void token_acquired (ACE_TPQ_Entry *); - // We've been taken off the waiters list and given the token! Call - // the Token_Handler associated at construction, so it can tell the - // remote client. - - ACE_TS_WLock (const ACE_TS_WLock&); - // Duplication. - - virtual ACE_Token_Proxy *clone (void) const; - // Return a deep copy. - -private: - ACE_Token_Handler* th_; - // the Token Handler associated with this proxy. Set at - // construction and notified when blocking acquires succeed. -}; - -// ************************************************************ - -class ACE_Token_Acceptor : public ACE_Strategy_Acceptor<ACE_Token_Handler, ACE_SOCK_ACCEPTOR> - // = TITLE - // This class contains the service-specific methods that can't - // easily be factored into the <ACE_Strategy_Acceptor>. -{ -public: - virtual int init (int argc, char *argv[]); - // Dynamic linking hook. - - int parse_args (int argc, char *argv[]); - // Parse svc.conf arguments. - -private: - ACE_Schedule_All_Reactive_Strategy<ACE_Token_Handler> scheduling_strategy_; - // The scheduling strategy is designed for Reactive services. -}; - int ACE_Token_Acceptor::parse_args (int argc, char *argv[]) { diff --git a/netsvcs/lib/Token_Handler.h b/netsvcs/lib/Token_Handler.h index 75d51c7f2b2..a9279ad9ba2 100644 --- a/netsvcs/lib/Token_Handler.h +++ b/netsvcs/lib/Token_Handler.h @@ -1,7 +1,6 @@ /* -*- C++ -*- */ // $Id$ - // ============================================================================ // // = LIBRARY @@ -19,7 +18,238 @@ #if !defined (ACE_TOKEN_HANDLER_H) #define ACE_TOKEN_HANDLER_H -#include "ace/OS.h" +#include "ace/Acceptor.h" +#include "ace/SOCK_Acceptor.h" +#include "ace/Local_Tokens.h" +#include "ace/Token_Collection.h" +#include "ace/Token_Request_Reply.h" + +class ACE_Svc_Export ACE_Token_Handler : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> + // = TITLE + // Product object created by an <ACE_Token_Acceptor>. A + // <Token_Handler> exchanges messages with a <Token_Proxy> object + // on the client-side. + // + // = DESCRIPTION + // This class is the main workhorse of the ACE Token service. It + // receives token operation requests from remote clients and turns + // them into calls on local tokens (acquire, release, renew, and + // remove). In OMG CORBA terms, it is an object adapter. It also + // schedules and handles timeouts that are used to support "timed + // waits." Clients used timed waits to bound the amount of time + // they block trying to get a token. + +{ +public: + // = Initialization and termination. + + ACE_Token_Handler (ACE_Thread_Manager * = 0); + // Default constructor. + + // = Accessor and mutator methods. + + // = Remote operations "exported" to a client. + virtual int acquire (ACE_Token_Proxy *proxy); + // Try to acquire the token. + // Precondition: client *may* hold the token already (i.e., + // supports recursive acquisitions). + + virtual int try_acquire (ACE_Token_Proxy *proxy); + // Try to acquire the token. + + virtual int release (ACE_Token_Proxy *proxy); + // Release the token and allow the next client that is waiting to + // proceed. Preconditions: client must hold the token. + + virtual int renew (ACE_Token_Proxy *proxy); + // Yield the token if any clients are waiting, otherwise keep the + // token. Preconditions: client must hold the token. + + virtual int remove (ACE_Token_Proxy *proxy); + // Remove the specified token from the Token_Map. Preconditions: + // ACE_Token must exist. @@ Any other preconditions, e.g., must + // client hold token, must there be no waiters, etc.? + + void sleep_hook (void); + // Called by TS_[Mutex,RLock,WLock] when we hold the mutex and + // someone wants it. + + void token_acquired (ACE_TPQ_Entry *); + // Called by TS_[Mutex,RLock,WLock] when we are waiting and acquire + // the mutex. + +protected: + // = Low level routines for framing requests, dispatching + // operations, and returning replies. + + virtual int abandon (int send_error); + // Our connection has been closed. + + virtual int recv_request (void); + // Receive, frame, and decode the client's request. + + virtual int dispatch (void); + // Dispatch the appropriate operation to handle the client's + // request. + + virtual int send_reply (ACE_UINT32 errnum); + // Create and send a reply to the client. + + // = Demultiplexing hooks. + virtual int handle_input (ACE_HANDLE); + // Callback method invoked by the <ACE_Reactor> when client events + // arrive. + + // = Timer hook. + virtual int handle_timeout (const ACE_Time_Value &tv, const void *arg); + // Enable clients to limit the amount of time they wait for a token. + + ACE_Token_Proxy *get_proxy (void); + // return a proxy for the calling client_id and token name. + +private: + + virtual ACE_Token_Proxy *create_proxy (void); + // Switches on the type of token_request_ and creates a new + // Token_Proxy. + + ACE_Synch_Options request_options_; + // Keeps track of the synchronization options (i.e., the timeout + // interval). + + ACE_Token_Collection collection_; + // collection of the client's token proxies. + + int timeout_id_; + // ID returned by the Reactor that is used to kill registered timers + // when a token operation times out. + + ACE_Token_Request token_request_; + // Cache request from the client. + + ACE_Token_Reply token_reply_; + // Cache reply to the client. +}; + +// = DESCRIPTION of ACE_TS_* classes: +// When Tokens are released, waiting token proxies are notified +// when the releasing thread calls token_acquired on the waiting +// proxy. The Token Server specializes ACE_Token_Proxy to +// redefine the implementation of token_acquired. When +// token_acquired is called, the Token_Handler can then send the +// response back over the socket connection to unblock the +// client side. +// Since only the Token_Handler uses ACE_TS_Mutex, we've moved +// the definition to the .cpp file. + +class ACE_TS_Mutex : public ACE_Local_Mutex + // = TITLE + // ACE_TS_Mutex -- ACE_*T*oken_*S*erver_Mutex +{ +public: + ACE_TS_Mutex (const char *name, + ACE_Token_Handler *th); + // Creation. + +protected: + virtual void sleep_hook (void); + // Somebody wants our token! + + virtual void token_acquired (ACE_TPQ_Entry *); + // We've been taken off the waiters list and given the token! Call + // the Token_Handler associated at construction, so it can tell the + // remote client. + + ACE_TS_Mutex (const ACE_TS_Mutex &); + // Duplication. + + virtual ACE_Token_Proxy *clone (void) const; + // Return a deep copy. + +private: + ACE_Token_Handler* th_; + // The Token Handler associated with this proxy. Set at + // construction and notified when blocking acquires succeed. +}; + +class ACE_TS_RLock : public ACE_Local_RLock + // = TITLE + // ACE_TS_RLock -- ACE_*T*oken_*S*erver_RLock +{ +public: + ACE_TS_RLock (const char *name, + ACE_Token_Handler *th); + // Creation. + +protected: + virtual void sleep_hook (void); + // Somebody wants our token! + + virtual void token_acquired (ACE_TPQ_Entry *); + // We've been taken off the waiters list and given the token! Call + // the Token_Handler associated at construction, so it can tell the + // remote client. + + ACE_TS_RLock (const ACE_TS_RLock&); + // Duplication. + + virtual ACE_Token_Proxy *clone (void) const; + // Return a deep copy. + +private: + ACE_Token_Handler* th_; + // the Token Handler associated with this proxy. Set at + // construction and notified when blocking acquires succeed. +}; + +class ACE_TS_WLock : public ACE_Local_WLock + // = TITLE + // ACE_TS_WLock -- ACE_*T*oken_*S*erver_WLock +{ +public: + ACE_TS_WLock (const char *name, + ACE_Token_Handler *th); + // Creation. + +protected: + virtual void sleep_hook (void); + // Somebody wants our token! + + virtual void token_acquired (ACE_TPQ_Entry *); + // We've been taken off the waiters list and given the token! Call + // the Token_Handler associated at construction, so it can tell the + // remote client. + + ACE_TS_WLock (const ACE_TS_WLock&); + // Duplication. + + virtual ACE_Token_Proxy *clone (void) const; + // Return a deep copy. + +private: + ACE_Token_Handler* th_; + // the Token Handler associated with this proxy. Set at + // construction and notified when blocking acquires succeed. +}; + +// ************************************************************ + +class ACE_Token_Acceptor : public ACE_Strategy_Acceptor<ACE_Token_Handler, ACE_SOCK_ACCEPTOR> + // = TITLE + // This class contains the service-specific methods that can't + // easily be factored into the <ACE_Strategy_Acceptor>. +{ +public: + virtual int init (int argc, char *argv[]); + // Dynamic linking hook. + + int parse_args (int argc, char *argv[]); + // Parse svc.conf arguments. + +private: + ACE_Schedule_All_Reactive_Strategy<ACE_Token_Handler> scheduling_strategy_; + // The scheduling strategy is designed for Reactive services. +}; ACE_SVC_FACTORY_DECLARE (ACE_Token_Acceptor) |