Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / Log_Msg_IPC.cpp
blobf3454de500629f100f8b985cafdda75fef9dff41
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)
15 int
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));
23 int
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 ();
32 return 0;
35 int
36 ACE_Log_Msg_IPC::close ()
38 return this->message_queue_.close ();
41 ssize_t
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 =
47 4 // type
48 + 4 // pid
49 + 12 // timestamp
50 + 4 // process id
51 + 4 // data length
52 #if defined (ACE_USES_WCHAR)
53 + (log_record.msg_data_len () * ACE_OutputCDR::wchar_maxbytes()) // message
54 #else
55 + log_record.msg_data_len () // message
56 #endif
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))
62 return -1;
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
66 // to a 64-bit value.
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)))
74 return -1;
76 // Store the size of the payload that follows
77 if (!(header << ACE_CDR::ULong (length)))
78 return -1;
80 // Use an iovec to send both buffer and payload simultaneously.
81 iovec iov[2];
82 iov[0].iov_base = header.begin ()->rd_ptr ();
83 iov[0].iov_len = 8;
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,
98 &payload_msg,
99 static_cast<int> (log_record.priority ()),
100 MSG_BAND);
101 #else
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