Skip to content

Commit

Permalink
fix bug: MsgSender::type return value incorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
张晨 authored and 张晨 committed May 23, 2019
1 parent 899ec8b commit ec8651c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
12 changes: 3 additions & 9 deletions src/cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -765,15 +765,9 @@ const char* MsgSender::name() {

void MsgSender::to_string(string& str) {
str = "[";
if (MsgSender::connection_type() == 0) {
char buf[16];
snprintf(buf, sizeof(buf), "%d", MsgSender::pid());
str += buf;
} else {
string tmp;
flora::internal::TagHelper::to_addr_string(flora::internal::Client::tag, tmp);
str += tmp;
}
string tmp;
flora::internal::TagHelper::to_string(flora::internal::Client::tag, tmp);
str += tmp;
str += "]";
str += MsgSender::name();
}
Expand Down
2 changes: 1 addition & 1 deletion src/disp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ void Dispatcher::do_erase_adapter(shared_ptr<Adapter> &sender) {
monitors.erase(reinterpret_cast<intptr_t>(sender.get()));
else {
string str;
TagHelper::to_addr_string(sender->tag, str);
TagHelper::to_string(sender->tag, str);
KLOGI(TAG, "erase adapter <%s>:%s", str.c_str(),
sender->info->name.c_str());
write_monitor_list_remove(sender->info->id);
Expand Down
17 changes: 11 additions & 6 deletions src/ser-helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class TagHelper {
// return: 0 unix
// 1 tcp
static uint32_t type(uint64_t tag) {
return (tag >> 32) & 0x80000000;
return ((tag >> 32) & 0x80000000) ? 1 : 0;
}

static pid_t pid(uint64_t tag) {
Expand All @@ -217,12 +217,17 @@ class TagHelper {
return (tag >> 32) & 0xffff;
}

static void to_addr_string(uint64_t tag, std::string& str) {
str = ipaddr(tag);
str += ':';
static void to_string(uint64_t tag, std::string& str) {
char buf[16];
snprintf(buf, sizeof(buf), "%d", port(tag));
str += buf;
if (type(tag) == 0) {
snprintf(buf, sizeof(buf), "%d", pid(tag));
str = buf;
} else {
str = ipaddr(tag);
str += ':';
snprintf(buf, sizeof(buf), "%d", port(tag));
str += buf;
}
}
};

Expand Down

0 comments on commit ec8651c

Please sign in to comment.