Log_Msg_IPC.cpp

Go to the documentation of this file.
00001 // Log_Msg_IPC.cpp,v 4.9 2006/05/26 21:49:34 schmidt Exp
00002 
00003 #include "ace/Log_Msg_IPC.h"
00004 #include "ace/Log_Record.h"
00005 #include "ace/CDR_Stream.h"
00006 
00007 ACE_RCSID(ace, Log_Msg_IPC, "Log_Msg_IPC.cpp,v 4.9 2006/05/26 21:49:34 schmidt Exp")
00008 
00009 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00010 
00011 ACE_Log_Msg_IPC::ACE_Log_Msg_IPC (void)
00012 {
00013 }
00014 
00015 ACE_Log_Msg_IPC::~ACE_Log_Msg_IPC (void)
00016 {
00017   (void) this->close ();
00018 }
00019 
00020 int
00021 ACE_Log_Msg_IPC::open (const ACE_TCHAR *logger_key)
00022 {
00023   ACE_LOG_MSG_IPC_CONNECTOR con;
00024   return con.connect (this->message_queue_,
00025                       ACE_LOG_MSG_IPC_ADDR (logger_key));
00026 }
00027 
00028 int
00029 ACE_Log_Msg_IPC::reset (void)
00030 {
00031   if (this->message_queue_.get_handle () != ACE_INVALID_HANDLE)
00032     {
00033       // If we don't do this, handles aren't reused on Win32 and the
00034       // server eventually crashes!
00035       return this->close ();
00036     }
00037   return 0;
00038 }
00039 
00040 int
00041 ACE_Log_Msg_IPC::close (void)
00042 {
00043   return this->message_queue_.close ();
00044 }
00045 
00046 int
00047 ACE_Log_Msg_IPC::log (ACE_Log_Record &log_record)
00048 {
00049   // Serialize the log record using a CDR stream, allocate enough
00050   // space for the complete <ACE_Log_Record>.
00051   const size_t max_payload_size =
00052     4 // type()
00053     + 8 // timestamp
00054     + 4 // process id
00055     + 4 // data length
00056     + ACE_Log_Record::MAXLOGMSGLEN // data
00057     + ACE_CDR::MAX_ALIGNMENT; // padding;
00058 
00059   // Insert contents of <log_record> into payload stream.
00060   ACE_OutputCDR payload (max_payload_size);
00061   payload << log_record;
00062 
00063   // Get the number of bytes used by the CDR stream.
00064   ACE_CDR::ULong length = payload.total_length ();
00065 
00066   // Send a header so the receiver can determine the byte order and
00067   // size of the incoming CDR stream.
00068   ACE_OutputCDR header (ACE_CDR::MAX_ALIGNMENT + 8);
00069   header << ACE_OutputCDR::from_boolean (ACE_CDR_BYTE_ORDER);
00070 
00071   // Store the size of the payload that follows
00072   header << ACE_CDR::ULong (length);
00073 
00074   // Use an iovec to send both buffer and payload simultaneously.
00075   iovec iov[2];
00076   iov[0].iov_base = header.begin ()->rd_ptr ();
00077   iov[0].iov_len  = 8;
00078   iov[1].iov_base = payload.begin ()->rd_ptr ();
00079   iov[1].iov_len  = length;
00080 
00081 #if defined (ACE_HAS_STREAM_PIPES)
00082   // Use the <putpmsg> API if supported to ensure correct message
00083   // queueing according to priority.
00084 
00085   ACE_Str_Buf header_msg (static_cast<void *> (header.begin ()->rd_ptr ()),
00086                           static_cast<int> (8));
00087 
00088   ACE_Str_Buf payload_msg (static_cast<void *> (payload.begin ()->rd_ptr ()),
00089                            static_cast<int> (length));
00090 
00091   return this->message_queue_.send (&header_msg,
00092                                     &payload_msg,
00093                                     static_cast<int> (log_record.priority ()),
00094                                     MSG_BAND);
00095 #else
00096   // We're running over sockets, so send header and payload
00097   // efficiently using "gather-write".
00098   return this->message_queue_.sendv_n (iov, 2);
00099 #endif /* ACE_HAS_STREAM_PIPES */
00100 }
00101 
00102 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 09:41:53 2006 for ACE by doxygen 1.3.6