channel::~channel()
{
_D("Destroyed[%llu]", m_event_id);
- disconnect();
+ if (is_connected()) {
+ disconnect();
+ }
}
uint64_t channel::bind(void)
void channel::disconnect(void)
{
+ AUTOLOCK(m_cmutex);
if (!is_connected()) {
_D("Channel is not connected");
return;
bool channel::send_sync(message &msg)
{
+ AUTOLOCK(m_cmutex);
+ if (!is_connected()) {
+ _D("Channel is not connected");
+ return false;
+ }
+
retvm_if(msg.size() >= MAX_MSG_CAPACITY, true, "Invaild message size[%u]", msg.size());
ssize_t size = 0;
bool channel::read_sync(message &msg, bool select)
{
+ AUTOLOCK(m_cmutex);
+ if (!is_connected()) {
+ _D("Channel is not connected");
+ return false;
+ }
+
message_header header;
ssize_t size = 0;
char buf[MAX_MSG_CAPACITY];
#include "message.h"
#include "event_loop.h"
#include "channel_handler.h"
+#include "cmutex.h"
namespace ipc {
std::vector<uint64_t> m_pending_event_id;
std::atomic<bool> m_connected;
+ cmutex m_cmutex;
};
}