adjust code

This commit is contained in:
mutouyun 2018-12-15 21:47:58 +08:00
parent 44ab812925
commit ee2a4e1106

View File

@ -106,7 +106,7 @@ bool send(handle_t h, void* data, int size) {
return false; return false;
} }
static unsigned msg_id = 0; static unsigned msg_id = 0;
++msg_id; // calc a new message id ++msg_id; // calc a new message id, atomic is unnecessary
int offset = 0; int offset = 0;
for (int i = 0; i < (size / static_cast<int>(data_length)); ++i, offset += data_length) { for (int i = 0; i < (size / static_cast<int>(data_length)); ++i, offset += data_length) {
msg_t msg { msg_t msg {
@ -138,7 +138,7 @@ std::vector<byte_t> recv(handle_t h) {
queue->connect(); queue->connect();
} }
auto rcs = recv_caches__.create(); auto rcs = recv_caches__.create();
do { while(1) {
// pop a new message // pop a new message
auto msg = queue->pop(); auto msg = queue->pop();
// remain_ may minus & abs(remain_) < data_length // remain_ may minus & abs(remain_) < data_length
@ -165,7 +165,7 @@ std::vector<byte_t> recv(handle_t h) {
// there are remain datas after this message // there are remain datas after this message
cache.resize(last_size + data_length); cache.resize(last_size + data_length);
std::memcpy(cache.data() + last_size, msg.data_, data_length); std::memcpy(cache.data() + last_size, msg.data_, data_length);
} while(1); }
} }
class channel::channel_ : public pimpl<channel_> { class channel::channel_ : public pimpl<channel_> {
@ -214,6 +214,7 @@ channel channel::clone(void) const {
} }
bool channel::connect(char const * name) { bool channel::connect(char const * name) {
if (name == nullptr || name[0] == '\0') return false;
this->disconnect(); this->disconnect();
impl(p_)->h_ = ipc::connect((impl(p_)->n_ = name).c_str()); impl(p_)->h_ = ipc::connect((impl(p_)->n_ = name).c_str());
return valid(); return valid();