diff --git a/include/boost/log/sinks/text_ipc_message_queue_backend.hpp b/include/boost/log/sinks/text_ipc_message_queue_backend.hpp index 3095714..5539d14 100644 --- a/include/boost/log/sinks/text_ipc_message_queue_backend.hpp +++ b/include/boost/log/sinks/text_ipc_message_queue_backend.hpp @@ -71,13 +71,13 @@ public: /*! * \brief An implementation of a supporting interprocess message queue used * by \c basic_text_ipc_message_queue_backend. Methods of this class - * are not thread-safe, unless otherwise specified. + * are not thread-safe, unless otherwise specified. */ class message_queue_type { private: //! \cond - + BOOST_MOVABLE_BUT_NOT_COPYABLE(message_queue_type) struct implementation; @@ -99,7 +99,7 @@ public: /*! * \brief Access permission type for \c message_queue_type. - * + * * On Windows platforms, it represents a \c SECURITY_ATTRIBUTES pointer. * On POSIX platforms, it represents a \c mode_t value. */ @@ -107,14 +107,15 @@ public: { //! \cond - BOOST_COPYABLE_AND_MOVABLE(permission) + BOOST_COPYABLE_AND_MOVABLE(permission) friend class message_queue_type; friend struct message_queue_type::implementation; #ifdef BOOST_TEST_MODULE public: -#endif +#endif + struct implementation; implementation* m_pImpl; @@ -160,7 +161,7 @@ public: * \param other The object to be copied. */ BOOST_LOG_API permission(permission const& other); - + /*! * Move constructor. The method move-constructs an object from \c other. * After the call, the constructed object becomes \c other, while \c other @@ -169,7 +170,7 @@ public: * \param other The object to be moved. */ BOOST_LOG_API permission(BOOST_RV_REF(permission) other); - + /*! * Copy assignment operator. The method copy-assigns the object from * \c other. After the call, the object is a copy of \c other. @@ -345,7 +346,7 @@ public: * \return Maximum number of messages the associated message queue can hold. */ BOOST_LOG_API unsigned int max_queue_size() const; - + /*! * The method returns the maximum size in bytes of each message allowed by the * associated message queue. Note that the returned value may be different from the @@ -484,7 +485,7 @@ public: BOOST_LOG_API static open_mode const open_or_create = message_queue_type::open_or_create; //! Convenient typedef for message_queue_type::permission. typedef typename message_queue_type::permission permission; - + //! Queue policy type enum queue_policy_type { @@ -505,7 +506,7 @@ public: //! Truncate the message when it is too long for the queue truncate_when_too_long }; - + private: //! \cond @@ -679,7 +680,7 @@ public: * should be using this object before calling this method. The stop() method * could be used to have any threads currently blocking on consume() return, * and prevent further calls to consume() from blocking. The associated message - * queue is destroyed, if the object represents the last outstanding reference to it. + * queue is destroyed, if the object represents the last outstanding reference to it. */ BOOST_LOG_API void close(); diff --git a/src/ipc_message_queue_posix.hpp b/src/ipc_message_queue_posix.hpp index 3745ad1..b602175 100644 --- a/src/ipc_message_queue_posix.hpp +++ b/src/ipc_message_queue_posix.hpp @@ -264,7 +264,7 @@ struct basic_text_ipc_message_queue_backend< CharT >::message_queue_type::implem { if (is_open()) { - unsigned int memory_size = sizeof(header) + + unsigned int memory_size = sizeof(header) + (sizeof(unsigned int) + m_pHeader->m_MaxMessageSize) * m_pHeader->m_MaxQueueSize; bool locked = false; @@ -298,7 +298,7 @@ struct basic_text_ipc_message_queue_backend< CharT >::message_queue_type::implem unsigned int max_queue_size, unsigned int max_message_size, permission const& permission_value) { - unsigned int memory_size = sizeof(header) + + unsigned int memory_size = sizeof(header) + (sizeof(unsigned int) + max_message_size) * max_queue_size; bool mutex_inited = false; bool non_empty_queue_inited = false; @@ -371,7 +371,7 @@ struct basic_text_ipc_message_queue_backend< CharT >::message_queue_type::implem int err = aux::pthread_mutex_lock(&m_pHeader->m_Mutex); locked = true; if (err == EOWNERDEAD) - { + { clear_queue(); aux::pthread_mutex_consistent(&m_pHeader->m_Mutex); } @@ -394,7 +394,7 @@ struct basic_text_ipc_message_queue_backend< CharT >::message_queue_type::implem { close(); errno = 0; - + if (*name) { m_Name = m_Name + "/" + name; @@ -508,7 +508,7 @@ struct basic_text_ipc_message_queue_backend< CharT >::message_queue_type::implem if (message_size > m_pHeader->m_MaxMessageSize) throw std::logic_error("Message is too long"); errno = 0; bool locked = false; - + try { int err = aux::pthread_mutex_lock(&m_pHeader->m_Mutex); @@ -543,7 +543,7 @@ struct basic_text_ipc_message_queue_backend< CharT >::message_queue_type::implem throw; } } - + bool try_send(void const* message_data, unsigned int message_size) { if (!is_open()) throw std::logic_error("IPC message queue not opened"); @@ -580,7 +580,7 @@ struct basic_text_ipc_message_queue_backend< CharT >::message_queue_type::implem if (buffer_size < m_pHeader->m_MaxMessageSize) throw std::logic_error("Insufficient buffer"); errno = 0; bool locked = false; - + try { int err = aux::pthread_mutex_lock(&m_pHeader->m_Mutex); diff --git a/src/ipc_message_queue_win.hpp b/src/ipc_message_queue_win.hpp index 26576cb..52bffb5 100644 --- a/src/ipc_message_queue_win.hpp +++ b/src/ipc_message_queue_win.hpp @@ -243,7 +243,7 @@ struct basic_text_ipc_message_queue_backend< CharT >::message_queue_type::implem m_Name = name; if (*name) { - unsigned int memory_size = sizeof(header) + + unsigned int memory_size = sizeof(header) + (sizeof(unsigned int) + max_message_size) * max_queue_size; static char const uuid[] = "37394D1EBAC14602BC9492CB1971F756"; @@ -259,7 +259,7 @@ struct basic_text_ipc_message_queue_backend< CharT >::message_queue_type::implem m_hMutex = aux::create_mutex(get_psa(permission_value), FALSE, mutex_name.c_str()); mode = GetLastError() == ERROR_ALREADY_EXISTS ? open_only : create_only; } - + if (mode == create_only) { if (!m_hMutex) @@ -399,7 +399,7 @@ struct basic_text_ipc_message_queue_backend< CharT >::message_queue_type::implem if (message_size > m_pHeader->m_MaxMessageSize) throw std::logic_error("Message is too long"); errno = 0; mutex_type locker(m_hMutex); - + while (true) { if (locker.lock() == WAIT_ABANDONED) clear_queue(); @@ -407,7 +407,7 @@ struct basic_text_ipc_message_queue_backend< CharT >::message_queue_type::implem { aux::reset_event(m_hNonFullQueueEvent); locker.unlock(); - + HANDLE handles[2] = { m_hStopEvent, m_hNonFullQueueEvent }; DWORD wait_result = aux::wait_for_multiple_objects(2, handles, FALSE, INFINITE); if (wait_result == WAIT_OBJECT_0) @@ -441,7 +441,7 @@ struct basic_text_ipc_message_queue_backend< CharT >::message_queue_type::implem if (buffer_size < m_pHeader->m_MaxMessageSize) throw std::logic_error("Insufficient buffer"); errno = 0; mutex_type locker(m_hMutex); - + while (true) { if (locker.lock() == WAIT_ABANDONED) clear_queue(); @@ -449,7 +449,7 @@ struct basic_text_ipc_message_queue_backend< CharT >::message_queue_type::implem { aux::reset_event(m_hNonEmptyQueueEvent); locker.unlock(); - + HANDLE handles[2] = { m_hStopEvent, m_hNonEmptyQueueEvent }; DWORD wait_result = aux::wait_for_multiple_objects(2, handles, FALSE, INFINITE); if (wait_result == WAIT_OBJECT_0) diff --git a/src/text_ipc_message_queue_backend.cpp b/src/text_ipc_message_queue_backend.cpp index 6b8ff43..c0ce368 100644 --- a/src/text_ipc_message_queue_backend.cpp +++ b/src/text_ipc_message_queue_backend.cpp @@ -47,7 +47,7 @@ struct basic_text_ipc_message_queue_backend< CharT >::implementation }; template < typename CharT > -BOOST_LOG_API typename basic_text_ipc_message_queue_backend< CharT >::open_mode const +BOOST_LOG_API typename basic_text_ipc_message_queue_backend< CharT >::open_mode const basic_text_ipc_message_queue_backend< CharT >::create_only; template < typename CharT > @@ -75,7 +75,7 @@ BOOST_LOG_API void basic_text_ipc_message_queue_backend< CharT >::construct( permission const& permission_value) { m_pImpl = new implementation(); - m_pImpl->m_MessageQueue.open(message_queue_name, mode, max_queue_size, + m_pImpl->m_MessageQueue.open(message_queue_name, mode, max_queue_size, max_message_size, permission_value); m_pImpl->m_QueuePolicy = queue_policy_val; m_pImpl->m_MessagePolicy = message_policy_val; @@ -185,7 +185,7 @@ BOOST_LOG_API void basic_text_ipc_message_queue_backend< CharT >::consume( if (!is_open()) return; unsigned int message_size = static_cast< unsigned int >(message.size() * sizeof(char_type)); - + // Deal with messages that are too long. if (message_size > max_message_size()) { diff --git a/src/win_wrapper.hpp b/src/win_wrapper.hpp index 89c239e..ec9fb2d 100644 --- a/src/win_wrapper.hpp +++ b/src/win_wrapper.hpp @@ -130,9 +130,9 @@ inline HANDLE open_file_mapping(DWORD access, BOOL inheritable, char const* name } inline void* map_view_of_file( - HANDLE hfilemapping, - DWORD access, - DWORD offset_high, + HANDLE hfilemapping, + DWORD access, + DWORD offset_high, DWORD offset_low, SIZE_T size) { diff --git a/test/run/sink_ipc_backend.cpp b/test/run/sink_ipc_backend.cpp index 7a2b84a..c51a5ba 100644 --- a/test/run/sink_ipc_backend.cpp +++ b/test/run/sink_ipc_backend.cpp @@ -410,7 +410,7 @@ BOOST_AUTO_TEST_CASE(ipc_backend) // stop() and reset(). { backend_t queue( - message_queue_name = "queue", + message_queue_name = "queue", open_mode = queue_t::open_or_create, max_queue_size = 1, queue_policy = backend_t::block_when_full);