1 #include "ace/Log_Msg_IPC.h"
2 #include "ace/Log_Record.h"
3 #include "ace/CDR_Stream.h"
4 #include "ace/Truncate.h"
8 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
10 ACE_Log_Msg_IPC::ACE_Log_Msg_IPC (void)
14 ACE_Log_Msg_IPC::~ACE_Log_Msg_IPC (void)
16 (void) this->close ();
19 ACE_ALLOC_HOOK_DEFINE(ACE_Log_Msg_IPC
)
22 ACE_Log_Msg_IPC::open (const ACE_TCHAR
*logger_key
)
24 ACE_LOG_MSG_IPC_CONNECTOR con
;
25 return con
.connect (this->message_queue_
,
26 ACE_LOG_MSG_IPC_ADDR (logger_key
));
30 ACE_Log_Msg_IPC::reset (void)
32 if (this->message_queue_
.get_handle () != ACE_INVALID_HANDLE
)
34 // If we don't do this, handles aren't reused on Win32 and the
35 // server eventually crashes!
36 return this->close ();
42 ACE_Log_Msg_IPC::close (void)
44 return this->message_queue_
.close ();
48 ACE_Log_Msg_IPC::log (ACE_Log_Record
&log_record
)
50 // Serialize the log record using a CDR stream, allocate enough
51 // space for the complete <ACE_Log_Record>.
52 size_t const max_payload_size
=
58 #if defined (ACE_USES_WCHAR)
59 + (log_record
.msg_data_len () * ACE_OutputCDR::wchar_maxbytes()) // message
61 + log_record
.msg_data_len () // message
63 + ACE_CDR::MAX_ALIGNMENT
; // padding;
65 // Insert contents of <log_record> into payload stream.
66 ACE_OutputCDR
payload (max_payload_size
);
67 if (!(payload
<< log_record
))
70 // Get the number of bytes used by the CDR stream. If it becomes desireable
71 // to support payloads more than 4GB, this field will need to be changed
73 ACE_CDR::ULong
const length
=
74 ACE_Utils::truncate_cast
<ACE_CDR::ULong
> (payload
.total_length ());
76 // Send a header so the receiver can determine the byte order and
77 // size of the incoming CDR stream.
78 ACE_OutputCDR
header (ACE_CDR::MAX_ALIGNMENT
+ 8);
79 if (!(header
<< ACE_OutputCDR::from_boolean (ACE_CDR_BYTE_ORDER
)))
82 // Store the size of the payload that follows
83 if (!(header
<< ACE_CDR::ULong (length
)))
86 // Use an iovec to send both buffer and payload simultaneously.
88 iov
[0].iov_base
= header
.begin ()->rd_ptr ();
90 iov
[1].iov_base
= payload
.begin ()->rd_ptr ();
91 iov
[1].iov_len
= length
;
93 #if (ACE_HAS_STREAM_LOG_MSG_IPC == 1)
94 // Use the <putpmsg> API if supported to ensure correct message
95 // queueing according to priority.
97 ACE_Str_Buf
header_msg (static_cast<void *> (header
.begin ()->rd_ptr ()),
98 static_cast<int> (8));
100 ACE_Str_Buf
payload_msg (static_cast<void *> (payload
.begin ()->rd_ptr ()),
101 static_cast<int> (length
));
103 return this->message_queue_
.send (&header_msg
,
105 static_cast<int> (log_record
.priority ()),
108 // We're running over sockets, so send header and payload
109 // efficiently using "gather-write".
110 return this->message_queue_
.sendv_n (iov
, 2);
111 #endif /* ACE_HAS_STREAM_LOG_MSG_IPC */
114 ACE_END_VERSIONED_NAMESPACE_DECL