diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 1997-09-18 05:50:48 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 1997-09-18 05:50:48 +0000 |
commit | 116620d5fe305698194b5221bc71199d0ae91c77 (patch) | |
tree | a9e6c2de2e539483a58595e85940a74156e45a87 | |
parent | 78a6ba1453b29ff59b3bda5ba9ca330ac6909891 (diff) | |
download | ATCD-116620d5fe305698194b5221bc71199d0ae91c77.tar.gz |
*** empty log message ***
-rw-r--r-- | ChangeLog-97b | 18 | ||||
-rw-r--r-- | ace/ACE.cpp | 71 | ||||
-rw-r--r-- | ace/ACE.h | 6 | ||||
-rw-r--r-- | ace/Log_Msg.cpp | 52 | ||||
-rw-r--r-- | ace/OS.h | 6 | ||||
-rw-r--r-- | examples/IPC_SAP/SPIPE_SAP/producer_msg.cpp | 13 | ||||
-rw-r--r-- | netsvcs/lib/Client_Logging_Handler.cpp | 279 | ||||
-rw-r--r-- | netsvcs/lib/Client_Logging_Handler.h | 68 | ||||
-rw-r--r-- | netsvcs/servers/main.cpp | 2 | ||||
-rw-r--r-- | netsvcs/servers/svc.conf | 2 |
10 files changed, 302 insertions, 215 deletions
diff --git a/ChangeLog-97b b/ChangeLog-97b index a5e8dfaf40e..b359032e229 100644 --- a/ChangeLog-97b +++ b/ChangeLog-97b @@ -1,4 +1,20 @@ -Wed Sep 17 17:25:32 1997 Douglas C. Schmidt <schmidt@flamenco.cs.wustl.edu> +Thu Sep 18 00:21:33 1997 Douglas C. Schmidt <schmidt@tango.cs.wustl.edu> + + * ace/Log_Msg.cpp: Changed over to using ACE_SPIPEs for the + logging mechanism rather than ACE_FIFOs to conform to the + changes to Client_Logging_Handler. + + * netsvcs/lib/Client_Logging_Handler.cpp: + Completely rewrote the Client Logging Daemon so that it uses + ACE_SPIPEs by default, rather than ACE_FIFOs. This is more + portable and makes it easier to write a generic client logging + daemon... If a platform doesn't support ACE_SPIPEs, then we + revert to using sockets. + +Wed Sep 17 22:47:20 1997 Douglas C. Schmidt <schmidt@tango.cs.wustl.edu> + + * ace/ACE: Added two new varargs methods for send() and recv(). + These are modeled after the ones that are in, e.g., ACE_SOCK_IO. * ace/Log_Msg.cpp (open): In the UNICODE version the compiler complains about mixed wchar/char usage in Log_Msg.cpp: diff --git a/ace/ACE.cpp b/ace/ACE.cpp index ba3caa669a1..a36c9a1e381 100644 --- a/ace/ACE.cpp +++ b/ace/ACE.cpp @@ -474,6 +474,77 @@ ACE::basename (const wchar_t *pathname, wchar_t delim) } #endif /* ACE_HAS_UNICODE */ +// Send N char *ptrs and int lengths. Note that the char *'s precede +// the ints (basically, an varargs version of writev). The count N is +// the *total* number of trailing arguments, *not* a couple of the +// number of tuple pairs! + +ssize_t +ACE::send (ACE_HANDLE handle, size_t n, ...) +{ + ACE_TRACE ("ACE_SOCK_IO::send"); + + va_list argp; + size_t total_tuples = n / 2; + iovec *iovp; +#if defined (ACE_HAS_ALLOCA) + iovp = (iovec *) alloca (total_tuples * sizeof (iovec)); +#else + ACE_NEW_RETURN (iovp, iovec[total_tuples], -1); +#endif /* !defined (ACE_HAS_ALLOCA) */ + + va_start (argp, n); + + for (size_t i = 0; i < total_tuples; i++) + { + iovp[i].iov_base = va_arg (argp, char *); + iovp[i].iov_len = va_arg (argp, int); + } + + ssize_t result = ACE_OS::writev (handle, iovp, total_tuples); +#if !defined (ACE_HAS_ALLOCA) + delete [] iovp; +#endif /* !defined (ACE_HAS_ALLOCA) */ + va_end (argp); + return result; +} + +// This is basically an interface to ACE_OS::readv, that doesn't use +// the struct iovec explicitly. The ... can be passed as an arbitrary +// number of (char *ptr, int len) tuples. However, the count N is the +// *total* number of trailing arguments, *not* a couple of the number +// of tuple pairs! + +ssize_t +ACE::recv (ACE_HANDLE handle, size_t n, ...) +{ + ACE_TRACE ("ACE_SOCK_IO::recv"); + + va_list argp; + size_t total_tuples = n / 2; + iovec *iovp; +#if defined (ACE_HAS_ALLOCA) + iovp = (iovec *) alloca (total_tuples * sizeof (iovec)); +#else + ACE_NEW_RETURN (iovp, iovec[total_tuples], -1); +#endif /* !defined (ACE_HAS_ALLOCA) */ + + va_start (argp, n); + + for (size_t i = 0; i < total_tuples; i++) + { + iovp[i].iov_base = va_arg (argp, char *); + iovp[i].iov_len = va_arg (argp, int); + } + + ssize_t result = ACE_OS::readv (handle, iovp, total_tuples); +#if !defined (ACE_HAS_ALLOCA) + delete [] iovp; +#endif /* !defined (ACE_HAS_ALLOCA) */ + va_end (argp); + return result; +} + // Miscellaneous static methods used throughout ACE. ssize_t diff --git a/ace/ACE.h b/ace/ACE.h index 83227c217c7..fa207ba6d14 100644 --- a/ace/ACE.h +++ b/ace/ACE.h @@ -264,6 +264,12 @@ public: // returned with <errno == ETIME>. If it succeeds the number of // bytes receieved is returned. + static ssize_t send (ACE_HANDLE handle, size_t n, ...); + // Send varargs messages to the <handle> using <writev>. + + static ssize_t recv (ACE_HANDLE handle, size_t n, ...); + // Recv varargs messages to the <handle> using <readv>. + // = File system I/O functions. // These encapsulate differences between UNIX and Win32 and also diff --git a/ace/Log_Msg.cpp b/ace/Log_Msg.cpp index dbe7dbb86d1..441f9fafc8b 100644 --- a/ace/Log_Msg.cpp +++ b/ace/Log_Msg.cpp @@ -38,15 +38,19 @@ // IPC conduit between sender and client daemon. This should be // included in the <ACE_Log_Msg> class, but due to "order of include" // problems it can't be... -#if defined (ACE_LACKS_FIFO) -# include "ace/SOCK_Connector.h" -typedef ACE_SOCK_Stream ACE_LOG_MSG_IPC; +#if defined (ACE_HAS_STREAM_PIPES) +# include "ace/SPIPE_Connector.h" +typedef ACE_SPIPE_Stream ACE_LOG_MSG_IPC_STREAM; +typedef ACE_SPIPE_Connector ACE_LOG_MSG_IPC_CONNECTOR; +typedef ACE_SPIPE_Addr ACE_LOG_MSG_IPC_ADDR; #else -# include "ace/FIFO_Send_Msg.h" -typedef ACE_FIFO_Send_Msg ACE_LOG_MSG_IPC; -#endif /* ACE_LACKS_FIFO */ +# include "ace/SOCK_Connector.h" +typedef ACE_SOCK_Stream ACE_LOG_MSG_IPC_STREAM; +typedef ACE_SOCK_Connector ACE_LOG_MSG_IPC_CONNECTOR; +typedef ACE_INET_Addr ACE_LOG_MSG_IPC_ADDR; +#endif /* ACE_HAS_STREAM_PIPES */ -static ACE_LOG_MSG_IPC *ACE_Log_Msg_message_queue = 0; +static ACE_LOG_MSG_IPC_STREAM *ACE_Log_Msg_message_queue = 0; #if defined (ACE_HAS_MINIMUM_IOSTREAMH_INCLUSION) # include /**/ <iostream.h> @@ -104,7 +108,7 @@ ACE_Log_Msg_Manager::get_lock (void) ACE_NEW_RETURN_I (ACE_Log_Msg_Manager::lock_, ACE_Thread_Mutex, 0); // Allocated the ACE_Log_Msg IPC instance. - ACE_NEW_RETURN (ACE_Log_Msg_message_queue, ACE_LOG_MSG_IPC, 0); + ACE_NEW_RETURN (ACE_Log_Msg_message_queue, ACE_LOG_MSG_IPC_STREAM, 0); } return ACE_Log_Msg_Manager::lock_; @@ -459,19 +463,14 @@ ACE_Log_Msg::open (const char *prog_name, if (logger_key == 0) status = -1; else -#if defined (ACE_LACKS_FIFO) { if (ACE_Log_Msg_message_queue->get_handle () != ACE_INVALID_HANDLE) ACE_Log_Msg_message_queue->close (); - ACE_SOCK_Connector con; + + ACE_LOG_MSG_IPC_CONNECTOR con; status = con.connect (*ACE_Log_Msg_message_queue, - ACE_INET_Addr (ACE_MULTIBYTE_STRING (logger_key))); + ACE_LOG_MSG_IPC_ADDR (ACE_MULTIBYTE_STRING (logger_key))); } -#else - if (ACE_Log_Msg_message_queue->get_handle () != ACE_INVALID_HANDLE) - ACE_Log_Msg_message_queue->close (); - status = ACE_Log_Msg_message_queue->open (logger_key); -#endif /* ACE_LACKS_FIFO */ if (status == -1) ACE_SET_BITS (ACE_Log_Msg::flags_, ACE_Log_Msg::STDERR); @@ -871,25 +870,22 @@ ACE_Log_Msg::log (const char *format_str, stderr); if (ACE_BIT_ENABLED (ACE_Log_Msg::flags_, ACE_Log_Msg::LOGGER)) { -#if defined (ACE_LACKS_FIFO) - // We're running over sockets, so we'll need to indicate the - // number of bytes to send. - result = ACE_Log_Msg_message_queue->send ((void *) &log_record, - log_record.length ()); -#else +#if defined (ACE_HAS_STREAM_PIPES) ACE_Str_Buf log_msg ((void *) &log_record, int (log_record.length ())); -#if defined (ACE_HAS_STREAM_PIPES) // Try to use the <putpmsg> API if possible in order to // ensure correct message queueing according to priority. - result = ACE_Log_Msg_message_queue->send (int (log_record.priority ()), - &log_msg); + result = ACE_Log_Msg_message_queue->send ((const ACE_Str_Buf *) 0, + &log_msg, + int (log_record.priority ()), + MSG_BAND); #else - // Use the FIFO API that uses the ol' 2-write trick. - result = ACE_Log_Msg_message_queue->send (log_msg); + // We're running over sockets, so we'll need to indicate the + // number of bytes to send. + result = ACE_Log_Msg_message_queue->send ((void *) &log_record, + log_record.length ()); #endif /* ACE_HAS_STREAM_PIPES */ -#endif /* ACE_LACKS_FIFO */ } // Format the message and print it to stderr and/or ship it off // to the log_client daemon, and/or print it to the ostream. @@ -161,10 +161,10 @@ // Used by the FIFO tests and the Client_Logging_Handler netsvc. #if !defined (ACE_DEFAULT_RENDEZVOUS) -#if defined (ACE_LACKS_FIFO) -#define ACE_DEFAULT_RENDEZVOUS "localhost:10012" -#else +#if defined (ACE_HAS_STREAM_PIPES) #define ACE_DEFAULT_RENDEZVOUS "/tmp/fifo.ace" +#else +#define ACE_DEFAULT_RENDEZVOUS "localhost:10012" #endif /* ACE_LACKS_FIFO */ #endif /* ACE_DEFAULT_RENDEZVOUS */ diff --git a/examples/IPC_SAP/SPIPE_SAP/producer_msg.cpp b/examples/IPC_SAP/SPIPE_SAP/producer_msg.cpp index bd0112dc2f1..29954517bff 100644 --- a/examples/IPC_SAP/SPIPE_SAP/producer_msg.cpp +++ b/examples/IPC_SAP/SPIPE_SAP/producer_msg.cpp @@ -14,9 +14,11 @@ const int DEFAULT_COUNT = 100; int main (int argc, char *argv[]) { - int size = argc > 1 ? atoi (argv[1]) : DEFAULT_SIZE; - int iterations = argc > 2 ? atoi (argv[2]) : DEFAULT_COUNT; - char *buf = new char[size]; + int size = argc > 1 ? atoi (argv[1]) : DEFAULT_SIZE; + int iterations = argc > 2 ? atoi (argv[2]) : DEFAULT_COUNT; + char *buf; + + ACE_NEW_RETURN (buf, char[size], -1); if (argc > 3) rendezvous = argv[3]; @@ -34,7 +36,10 @@ main (int argc, char *argv[]) ACE_Str_Buf buffer (buf, size); for (i = 0; i < iterations; i++) - if (cli_stream.send ((ACE_Str_Buf *) 0, &buffer) == -1) + if (cli_stream.send ((ACE_Str_Buf *) 0, + &buffer, + 1, + MSG_BAND) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "send"), 1); if (cli_stream.close () == -1) diff --git a/netsvcs/lib/Client_Logging_Handler.cpp b/netsvcs/lib/Client_Logging_Handler.cpp index e180fd4b165..768792cd92d 100644 --- a/netsvcs/lib/Client_Logging_Handler.cpp +++ b/netsvcs/lib/Client_Logging_Handler.cpp @@ -4,51 +4,22 @@ #define ACE_BUILD_SVC_DLL #include "ace/Get_Opt.h" +#include "ace/Acceptor.h" +#include "ace/SOCK_Connector.h" +#include "ace/SOCK_Acceptor.h" +#include "ace/SPIPE_Acceptor.h" #include "Client_Logging_Handler.h" -#if defined (ACE_LACKS_FIFO) -#define DEFAULT_RENDEZVOUS "10012" -#else -#define DEFAULT_RENDEZVOUS ACE_DEFAULT_RENDEZVOUS -#endif /* ACE_LACKS_FIFO */ - -ACE_Client_Logging_Handler::ACE_Client_Logging_Handler (const char rendezvous[]) - : logging_output_ (ACE_STDOUT) +ACE_Client_Logging_Handler::ACE_Client_Logging_Handler (ACE_HANDLE output_handle) + : logging_output_ (output_handle) { -#if defined (ACE_LACKS_FIFO) - if (this->acceptor_.open (ACE_INET_Addr (DEFAULT_RENDEZVOUS)) == -1) - ACE_ERROR ((LM_ERROR, "%p\n", "open")); - // Register passive-mode socket to receive connections from clients. - else if (ACE_Reactor::instance ()->register_handler - (this->acceptor_.get_handle (), - this, - ACE_Event_Handler::ACCEPT_MASK) == -1) - ACE_ERROR ((LM_ERROR, "%n: %p\n", "register_handler")); - ACE_DEBUG ((LM_DEBUG, - "opened acceptor socket at %s on handle %d\n", - rendezvous, - this->acceptor_.get_handle ())); -#else - if (ACE_OS::unlink (rendezvous) == -1 && errno == EACCES) - ACE_ERROR ((LM_ERROR, "%p\n", "unlink")); - - else if (this->msg_queue_.open (rendezvous) == -1) - ACE_ERROR ((LM_ERROR, "%p\n", "open")); - - // Register message FIFO to receive input from clients. Note that - // we need to put the EXCEPT_MASK here to deal with SVR4 MSG_BAND - // data correctly... - else if (ACE_Reactor::instance ()->register_handler - (this->msg_queue_.get_handle (), - this, - ACE_Event_Handler::READ_MASK | ACE_Event_Handler::EXCEPT_MASK) == -1) + // Register ourselves to receive SIGPIPE so we can attempt + // reconnections. +#if !defined (ACE_LACKS_UNIX_SIGNALS) + if (ACE_Reactor::instance ()->register_handler (SIGPIPE, this) == -1) ACE_ERROR ((LM_ERROR, "%n: %p\n", - "register_handler")); - ACE_DEBUG ((LM_DEBUG, - "opened fifo at %s on handle %d\n", - rendezvous, - this->msg_queue_.get_handle ())); -#endif /* ACE_LACKS_FIFO */ + "register_handler (SIGPIPE)")); +#endif /* !ACE_LACKS_UNIX_SIGNALS */ } // This is called when a <send> to the logging server fails... @@ -56,34 +27,36 @@ ACE_Client_Logging_Handler::ACE_Client_Logging_Handler (const char rendezvous[]) int ACE_Client_Logging_Handler::handle_signal (int, siginfo_t *, ucontext_t *) { - ACE_TRACE ("ACE_Client_Logging_Connector::handle_signal"); + ACE_TRACE ("ACE_Client_Logging_Acceptor::handle_signal"); return -1; } +// This function is called every time a client connects to us. + int ACE_Client_Logging_Handler::open (void *) { - ACE_INET_Addr server_addr; - - this->logging_output_ = this->peer ().get_handle (); - - // Register ourselves to receive SIGPIPE so we can attempt - // reconnections. -#if !defined (ACE_LACKS_FIFO) - if (ACE_Reactor::instance ()->register_handler (SIGPIPE, this) == -1) + LOGGING_ADDR server_addr; + + // Register ourselves to receive <handle_input> callbacks when + // clients send us logging records. Note that since we're really a + // Singleton, this->peer() will change after each connect, so we + // need to grab the value now. + if (ACE_Reactor::instance ()->register_handler + (this->peer ().get_handle (), + this, + ACE_Event_Handler::READ_MASK + | ACE_Event_Handler::EXCEPT_MASK) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%n: %p\n", - "register_handler (SIGPIPE)"), -1); -#endif /* !ACE_LACKS_FIFO */ - + "register_handler)"), -1); + // Figure out what remote port we're really bound to. if (this->peer ().get_remote_addr (server_addr) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "get_remote_addr"), -1); ACE_DEBUG ((LM_DEBUG, - "starting up Client Logging Daemon, " - "connected to port %d on handle %d\n", - server_addr.get_port_number (), - this->peer ().get_handle ())); + "connected to client on handle %u\n", + this->peer ().get_handle ())); return 0; } @@ -91,13 +64,9 @@ ACE_Client_Logging_Handler::open (void *) ACE_Client_Logging_Handler::get_handle (void) const { ACE_TRACE ("ACE_Client_Logging_Handler::get_handle"); -#if defined (ACE_LACKS_FIFO) ACE_ERROR_RETURN ((LM_ERROR, "get_handle() shouldn't be called\n"), ACE_INVALID_HANDLE); -#else - return this->msg_queue_.get_handle (); -#endif /* ACE_LACKS_FIFO */ } // Receive a logging record from an application. @@ -107,36 +76,39 @@ ACE_Client_Logging_Handler::handle_input (ACE_HANDLE handle) { ACE_DEBUG ((LM_DEBUG, "in handle_input, handle = %u\n", handle)); - if (handle == this->peer ().get_handle ()) + if (handle == this->logging_output_) // We're getting a message from the logging server! ACE_ERROR_RETURN ((LM_ERROR, "received data from server!\n"), -1); -#if defined (ACE_LACKS_FIFO) - else if (handle == this->acceptor_.get_handle ()) - { - ACE_SOCK_Stream client_stream; - - if (this->acceptor_.accept (client_stream) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "accept"), -1); - - // Register message socket to receive input from clients. - else if (ACE_Reactor::instance ()->register_handler - (client_stream.get_handle (), - this, - ACE_Event_Handler::READ_MASK) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%n: %p\n", - "register_handler"), -1); - return 0; - } -#endif /* ACE_LACKS_FIFO */ + ACE_Log_Record log_record; +#if defined (ACE_HAS_STREAM_PIPES) // We're getting a logging message from a local application. - ACE_Log_Record log_record; ACE_Str_Buf msg ((void *) &log_record, 0, sizeof log_record); -#if defined (ACE_LACKS_FIFO) + ACE_SPIPE_Stream spipe; + spipe.set_handle (handle); + int flags = 0; + + int result = spipe.recv ((ACE_Str_Buf *) 0, &msg, &flags); + + // We've got a framed IPC mechanism, so we can just to a recv(). + if (result < 0 || msg.len == 0) + { + if (ACE_Reactor::instance ()->remove_handler + (handle, + ACE_Event_Handler::READ_MASK + | ACE_Event_Handler::EXCEPT_MASK + | ACE_Event_Handler::DONT_CALL) == -1) + ACE_ERROR_RETURN ((LM_ERROR, "%n: %p\n", + "remove_handler"), -1); + spipe.close (); + ACE_DEBUG ((LM_DEBUG, "client closing down\n")); + return 0; + } +#else long length; // We need to use the ol' two-read trick here since TCP sockets @@ -154,9 +126,10 @@ ACE_Client_Logging_Handler::handle_input (ACE_HANDLE handle) if (ACE_Reactor::instance ()->remove_handler (handle, ACE_Event_Handler::READ_MASK + | ACE_Event_Handler::EXCEPT_MASK | ACE_Event_Handler::DONT_CALL) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%n: %p\n", - "remove_handler"), -1); + "remove_handler"), 0); ACE_OS::closesocket (handle); ACE_DEBUG ((LM_DEBUG, "client closing down\n")); return 0; @@ -167,16 +140,9 @@ ACE_Client_Logging_Handler::handle_input (ACE_HANDLE handle) if (ACE_OS::recv (handle, (char *) &log_record, (int) length) != length) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "recv"), -1); + ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "recv"), 0); } -#else - // We've got a framed IPC mechanism, so we can just to a recv(). - if (this->msg_queue_.recv (msg) == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "%p\n", - "ACE_FIFO_Recv_Msg::recv"), - 0); -#endif /* ACE_LACKS_FIFO */ +#endif /* ACE_HAS_STREAM_PIPES */ // Forward the logging record to the server. if (this->send (log_record) == -1) @@ -202,24 +168,6 @@ ACE_Client_Logging_Handler::close (u_long) { ACE_DEBUG ((LM_DEBUG, "shutting down!!!\n")); -#if defined (ACE_LACKS_FIFO) - if (ACE_Reactor::instance ()->remove_handler - (this->acceptor_.get_handle (), - ACE_Event_Handler::ACCEPT_MASK - | ACE_Event_Handler::DONT_CALL) == -1) - ACE_ERROR ((LM_ERROR, "%n: %p\n", - "remove_handler")); -#else - if (ACE_Reactor::instance ()->remove_handler - (this->msg_queue_.get_handle (), - ACE_Event_Handler::READ_MASK - | ACE_Event_Handler::EXCEPT_MASK - | ACE_Event_Handler::DONT_CALL) == -1) - ACE_ERROR ((LM_ERROR, "%n: %p\n", - "remove_handler")); -#endif /* ACE_LACKS_FIFO */ - - this->msg_queue_.close (); this->destroy (); return 0; } @@ -237,7 +185,7 @@ int ACE_Client_Logging_Handler::send (ACE_Log_Record &log_record) { if (this->logging_output_ == ACE_STDOUT) - log_record.print ("<localhost>", 0, stderr); + log_record.print ("<localhost>", 0, stderr); else { long len = log_record.length (); @@ -245,10 +193,14 @@ ACE_Client_Logging_Handler::send (ACE_Log_Record &log_record) log_record.encode (); - if (this->peer ().send (4, &encoded_len, sizeof encoded_len, - (char *) &log_record, len) == -1) - // Switch over to logging to stdout for now. In the long run, - // we'll need to queue up the message, try to reestablish a + if (ACE::send (this->logging_output_, + 4, + &encoded_len, + sizeof encoded_len, + (char *) &log_record, + len) == -1) + // Switch over to logging to stdout for now. Eventually, + // we'll try to queue up the message, try to reestablish a // connection, and then send the queued data once we've // reconnect to the logging server. this->logging_output_ = ACE_STDOUT; @@ -257,15 +209,20 @@ ACE_Client_Logging_Handler::send (ACE_Log_Record &log_record) return 0; } -class ACE_Client_Logging_Connector : public ACE_Connector<ACE_Client_Logging_Handler, ACE_SOCK_CONNECTOR> +class ACE_Client_Logging_Acceptor : public ACE_Acceptor<ACE_Client_Logging_Handler, LOGGING_ACCEPTOR> // = TITLE // This factory creates connections with the // <Server_Logging_Acceptor>. // // = DESCRIPTION // This class contains the service-specific methods that can't - // easily be factored into the <ACE_Connector>. + // easily be factored into the <ACE_Acceptor>. { +public: + // = Initialization method. + ACE_Client_Logging_Acceptor (void); + // Default constructor. + protected: // = Dynamic linking hooks. virtual int init (int argc, char *argv[]); @@ -277,6 +234,9 @@ protected: virtual int info (char **strp, size_t length) const; // Called to determine info about the service. + virtual int make_svc_handler (ACE_Client_Logging_Handler *&sh); + // Factory that always returns the <handler_>. + // = Scheduling hooks. virtual int suspend (void); virtual int resume (void); @@ -297,22 +257,30 @@ private: const char *rendezvous_key_; // Communication endpoint where the client logging daemon will - // listen for application logging records. + // listen for connections from clients. ACE_Client_Logging_Handler *handler_; // Pointer to the handler that does the work. }; int -ACE_Client_Logging_Connector::fini (void) +ACE_Client_Logging_Acceptor::fini (void) { if (this->handler_ != 0) this->handler_->close (0); return 0; } +int +ACE_Client_Logging_Acceptor::make_svc_handler (ACE_Client_Logging_Handler *&sh) +{ + // Always return a pointer to the Singleton handler. + sh = this->handler_; + return 0; +} + int -ACE_Client_Logging_Connector::info (char **strp, size_t length) const +ACE_Client_Logging_Acceptor::info (char **strp, size_t length) const { char buf[BUFSIZ]; @@ -327,38 +295,65 @@ ACE_Client_Logging_Connector::info (char **strp, size_t length) const return ACE_OS::strlen (buf); } +ACE_Client_Logging_Acceptor::ACE_Client_Logging_Acceptor (void) + : server_host_ (ACE_DEFAULT_SERVER_HOST), + server_port_ (ACE_DEFAULT_LOGGING_SERVER_PORT), + rendezvous_key_ (DEFAULT_RENDEZVOUS), + handler_ (0) +{ +} + int -ACE_Client_Logging_Connector::init (int argc, char *argv[]) +ACE_Client_Logging_Acceptor::init (int argc, char *argv[]) { + // We'll log *our* error and debug messages to stderr! ACE_LOG_MSG->open ("Client Logging Service"); // Use the options hook to parse the command line arguments and set // options. this->parse_args (argc, argv); - ACE_NEW_RETURN (this->handler_, - ACE_Client_Logging_Handler (this->rendezvous_key_), - -1); + // Initialize the acceptor endpoint. + if (this->open (LOGGING_ADDR (this->rendezvous_key_)) == -1) + ACE_ERROR_RETURN ((LM_ERROR, "%p\n", this->rendezvous_key_), -1); // Establish connection with the server. - if (this->connect (this->handler_, - this->server_addr_, - ACE_Synch_Options::synch) == -1) + ACE_SOCK_Connector con; + ACE_SOCK_Stream stream; + + if (con.connect (stream, this->server_addr_) == -1) { ACE_ERROR ((LM_ERROR, "%p, using stdout\n", "can't connect to logging server")); - this->handler_ = 0; + // If we can't connect to the server then we'll send the logging + // messages to stdout. + stream.set_handle (ACE_STDOUT); + } + else + { + ACE_INET_Addr server_addr; + + // Figure out what remote port we're really bound to. + if (stream.get_remote_addr (server_addr) == -1) + ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "get_remote_addr"), -1); + + ACE_DEBUG ((LM_DEBUG, + "starting up Client Logging Daemon, " + "connected to port %d on handle %u\n", + server_addr.get_port_number (), + stream.get_handle ())); } + + // Create the Singleton <Client_Logging_Handler>. + ACE_NEW_RETURN (this->handler_, + ACE_Client_Logging_Handler (stream.get_handle ()), + -1); return 0; } int -ACE_Client_Logging_Connector::parse_args (int argc, char *argv[]) +ACE_Client_Logging_Acceptor::parse_args (int argc, char *argv[]) { - this->rendezvous_key_ = DEFAULT_RENDEZVOUS; - this->server_port_ = ACE_DEFAULT_LOGGING_SERVER_PORT; - this->server_host_ = ACE_DEFAULT_SERVER_HOST; - ACE_Get_Opt get_opt (argc, argv, "h:k:p:", 0); for (int c; (c = get_opt ()) != -1; ) @@ -389,14 +384,14 @@ ACE_Client_Logging_Connector::parse_args (int argc, char *argv[]) } int -ACE_Client_Logging_Connector::suspend (void) +ACE_Client_Logging_Acceptor::suspend (void) { // To be done... return 0; } int -ACE_Client_Logging_Connector::resume (void) +ACE_Client_Logging_Acceptor::resume (void) { // To be done... return 0; @@ -406,19 +401,11 @@ ACE_Client_Logging_Connector::resume (void) // svc.conf file to dynamically initialize the state of the // single-threaded logging server. -ACE_SVC_FACTORY_DEFINE (ACE_Client_Logging_Connector) +ACE_SVC_FACTORY_DEFINE (ACE_Client_Logging_Acceptor) #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) -template class ACE_Connector<ACE_Client_Logging_Handler, ACE_SOCK_CONNECTOR>; -template class ACE_Svc_Tuple<ACE_Client_Logging_Handler>; -template class ACE_Map_Entry<ACE_HANDLE, ACE_Svc_Tuple<ACE_Client_Logging_Handler> *>; -template class ACE_Map_Iterator<ACE_HANDLE, ACE_Svc_Tuple<ACE_Client_Logging_Handler> *, ACE_SYNCH_RW_MUTEX>; -template class ACE_Map_Manager<ACE_HANDLE, ACE_Svc_Tuple<ACE_Client_Logging_Handler> *, ACE_SYNCH_RW_MUTEX>; +template class ACE_Acceptor<ACE_Client_Logging_Handler, LOGGING_ACCEPTOR>; #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -#pragma instantiate ACE_Connector<ACE_Client_Logging_Handler, ACE_SOCK_CONNECTOR> -#pragma instantiate ACE_Svc_Tuple<ACE_Client_Logging_Handler> -#pragma instantiate ACE_Map_Entry<ACE_HANDLE, ACE_Svc_Tuple<ACE_Client_Logging_Handler> *> -#pragma instantiate ACE_Map_Iterator<ACE_HANDLE, ACE_Svc_Tuple<ACE_Client_Logging_Handler> *, ACE_SYNCH_RW_MUTEX> -#pragma instantiate ACE_Map_Manager<ACE_HANDLE, ACE_Svc_Tuple<ACE_Client_Logging_Handler> *, ACE_SYNCH_RW_MUTEX> +#pragma instantiate ACE_Acceptor<ACE_Client_Logging_Handler, LOGGING_ACCEPTOR> #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/netsvcs/lib/Client_Logging_Handler.h b/netsvcs/lib/Client_Logging_Handler.h index 7de14e72783..443f389bdc3 100644 --- a/netsvcs/lib/Client_Logging_Handler.h +++ b/netsvcs/lib/Client_Logging_Handler.h @@ -17,52 +17,66 @@ #if !defined (ACE_CLIENT_LOGGER_H) #define ACE_CLIENT_LOGGER_H -#include "ace/Connector.h" -#include "ace/SOCK_Acceptor.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> +#include "ace/SPIPE_Stream.h" +#include "ace/SOCK_Stream.h" +#include "ace/Svc_Handler.h" +#include "ace/Synch.h" + +#if defined (ACE_HAS_STREAM_PIPES) +#define DEFAULT_RENDEZVOUS ACE_DEFAULT_RENDEZVOUS +#define LOGGING_STREAM ACE_SPIPE_STREAM +#define LOGGING_ACCEPTOR ACE_SPIPE_ACCEPTOR +#define LOGGING_ADDR ACE_SPIPE_Addr +#else +#define DEFAULT_RENDEZVOUS "10012" +#define LOGGING_STREAM ACE_SOCK_STREAM +#define LOGGING_ACCEPTOR ACE_SOCK_ACCEPTOR +#define LOGGING_ADDR ACE_INET_Addr +#endif /* ACE_HAS_STREAM_PIPES */ + +class ACE_Svc_Export ACE_Client_Logging_Handler : public ACE_Svc_Handler<LOGGING_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. // // = DESCRIPTION - // The default implementation uses an <ACE_FIFO_Recv_Msg> data - // member to receive the logging message from the application - // and an <ACE_SOCK_Stream> to forward the logging message to - // the server. However, on platforms that don't support FIFOs - // (e.g., Win32) we use sockets instead of FIFOs. + // The default implementation uses an <ACE_SPIPE_Stream> to + // receive the logging message from the application and an + // <ACE_SOCK_Stream> to forward the logging message to the + // server. However, on platforms that don't support + // <ACE_SPIPEs> (e.g., Win32) we use sockets instead. { -friend class ACE_Client_Logging_Connector; public: // = Initialization and termination. - ACE_Client_Logging_Handler (const char rendezvous[] = 0); - // Default constructor, which initializes the server endpoint. + ACE_Client_Logging_Handler (ACE_HANDLE handle = ACE_STDOUT); + // Default constructor. <handle> is where the output is sent. virtual int open (void * = 0); // Activate this instance of the <ACE_Client_Logging_Handler> - // (called by the <ACE_Client_Logging_Connector>). + // (called by the <ACE_Client_Logging_Acceptor>). virtual ACE_HANDLE get_handle (void) const; - // Return the handle of the message_fifo_; + // Return the handle of the <ACE_SPIPE_Stream>; virtual int close (u_long); - // Called when object is removed from the ACE_Reactor. + // Called when object is removed from the <ACE_Reactor>. -protected: - virtual int handle_signal (int signum, siginfo_t *, ucontext_t *); +private: + 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>. + // 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. @@ -70,19 +84,11 @@ protected: int send (ACE_Log_Record &log_record); // Send the <log_record> to the logging server. - ACE_FIFO_Recv_Msg msg_queue_; - // 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. - -#if defined (ACE_LACKS_FIFO) - ACE_SOCK_Acceptor acceptor_; - // Acceptor used for platforms that don't support FIFOs -#endif /* ACE_LACKS_FIFO */ }; -ACE_SVC_FACTORY_DECLARE (ACE_Client_Logging_Connector) +ACE_SVC_FACTORY_DECLARE (ACE_Client_Logging_Acceptor) #endif /* ACE_CLIENT_LOGGER_H */ diff --git a/netsvcs/servers/main.cpp b/netsvcs/servers/main.cpp index 4c5c4d5de72..3d6d3bb977e 100644 --- a/netsvcs/servers/main.cpp +++ b/netsvcs/servers/main.cpp @@ -87,7 +87,7 @@ main (int argc, char *argv[]) #endif l_argv[0] = "-p " ACE_DEFAULT_LOGGING_SERVER_PORT_STR; l_argv[1] = "-hflamenco.cs.wustl.edu"; - ACE_Service_Object_Ptr sp_6 = ACE_SVC_INVOKE (ACE_Client_Logging_Connector); + ACE_Service_Object_Ptr sp_6 = ACE_SVC_INVOKE (ACE_Client_Logging_Acceptor); if (sp_6->init (2, l_argv) == -1) ACE_ERROR ((LM_ERROR, "%p\n%a", "Logging Client", 1)); diff --git a/netsvcs/servers/svc.conf b/netsvcs/servers/svc.conf index e85cadf3138..78b59eab3a9 100644 --- a/netsvcs/servers/svc.conf +++ b/netsvcs/servers/svc.conf @@ -13,5 +13,5 @@ dynamic Name_Server Service_Object * ../lib/netsvcs:_make_ACE_Name_Acceptor() "- dynamic Token_Service Service_Object * ../lib/netsvcs:_make_ACE_Token_Acceptor() "-p 20202" dynamic Server_Logging_Service Service_Object * ../lib/netsvcs:_make_ACE_Server_Logging_Acceptor() active "-p 20009" dynamic Thr_Server_Logging_Service Service_Object * ../lib/netsvcs:_make_ACE_Thr_Server_Logging_Acceptor() active "-p 20020" -dynamic Client_Logging_Service Service_Object * ../lib/netsvcs:_make_ACE_Client_Logging_Connector() active "-p 20009" +dynamic Client_Logging_Service Service_Object * ../lib/netsvcs:_make_ACE_Client_Logging_Acceptor() active "-p 20009" |