1 #include "ace/Log_Msg_IPC.h"
2 #include "ace/Log_Record.h"
3 #include "ace/CDR_Stream.h"
4 #include "ace/Truncate.h"
6 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
8 ACE_Log_Msg_IPC::~ACE_Log_Msg_IPC ()
10 (void) this->close ();
13 ACE_ALLOC_HOOK_DEFINE(ACE_Log_Msg_IPC
)
16 ACE_Log_Msg_IPC::open (const ACE_TCHAR
*logger_key
)
18 ACE_LOG_MSG_IPC_CONNECTOR con
;
19 return con
.connect (this->message_queue_
,
20 ACE_LOG_MSG_IPC_ADDR (logger_key
));
24 ACE_Log_Msg_IPC::reset ()
26 if (this->message_queue_
.get_handle () != ACE_INVALID_HANDLE
)
28 // If we don't do this, handles aren't reused on Win32 and the
29 // server eventually crashes!
30 return this->close ();
36 ACE_Log_Msg_IPC::close ()
38 return this->message_queue_
.close ();
42 ACE_Log_Msg_IPC::log (ACE_Log_Record
&log_record
)
44 // Serialize the log record using a CDR stream, allocate enough
45 // space for the complete <ACE_Log_Record>.
46 size_t const max_payload_size
=
52 #if defined (ACE_USES_WCHAR)
53 + (log_record
.msg_data_len () * ACE_OutputCDR::wchar_maxbytes()) // message
55 + log_record
.msg_data_len () // message
57 + ACE_CDR::MAX_ALIGNMENT
; // padding;
59 // Insert contents of <log_record> into payload stream.
60 ACE_OutputCDR
payload (max_payload_size
);
61 if (!(payload
<< log_record
))
64 // Get the number of bytes used by the CDR stream. If it becomes desireable
65 // to support payloads more than 4GB, this field will need to be changed
67 ACE_CDR::ULong
const length
=
68 ACE_Utils::truncate_cast
<ACE_CDR::ULong
> (payload
.total_length ());
70 // Send a header so the receiver can determine the byte order and
71 // size of the incoming CDR stream.
72 ACE_OutputCDR
header (ACE_CDR::MAX_ALIGNMENT
+ 8);
73 if (!(header
<< ACE_OutputCDR::from_boolean (ACE_CDR_BYTE_ORDER
)))
76 // Store the size of the payload that follows
77 if (!(header
<< ACE_CDR::ULong (length
)))
80 // Use an iovec to send both buffer and payload simultaneously.
82 iov
[0].iov_base
= header
.begin ()->rd_ptr ();
84 iov
[1].iov_base
= payload
.begin ()->rd_ptr ();
85 iov
[1].iov_len
= length
;
87 #if (ACE_HAS_STREAM_LOG_MSG_IPC == 1)
88 // Use the <putpmsg> API if supported to ensure correct message
89 // queueing according to priority.
91 ACE_Str_Buf
header_msg (static_cast<void *> (header
.begin ()->rd_ptr ()),
92 static_cast<int> (8));
94 ACE_Str_Buf
payload_msg (static_cast<void *> (payload
.begin ()->rd_ptr ()),
95 static_cast<int> (length
));
97 return this->message_queue_
.send (&header_msg
,
99 static_cast<int> (log_record
.priority ()),
102 // We're running over sockets, so send header and payload
103 // efficiently using "gather-write".
104 return this->message_queue_
.sendv_n (iov
, 2);
105 #endif /* ACE_HAS_STREAM_LOG_MSG_IPC */
108 ACE_END_VERSIONED_NAMESPACE_DECL