Update ProtocolMessage and ProtocolWrapper moving. (#1612)

This commit is contained in:
xiehan
2024-08-20 19:52:57 +08:00
committed by GitHub
parent 0c11e8c2e6
commit fcabd2d8c6
2 changed files with 14 additions and 10 deletions

View File

@@ -39,7 +39,7 @@ int PackageWrapper::encode(struct iovec vectors[], int max)
}
cnt += ret;
this->message = this->next_out(this->message);
this->set_message(this->next_out(this->message));
if (!this->message)
return cnt;
@@ -57,7 +57,7 @@ int PackageWrapper::append(const void *buf, size_t *size)
if (ret > 0)
{
this->message = this->next_in(this->message);
this->set_message(this->next_in(this->message));
if (this->message)
{
this->renew();

View File

@@ -114,7 +114,7 @@ public:
this->size_limit = message.size_limit;
this->attachment = message.attachment;
message.attachment = NULL;
this->wrapper = message.wrapper;
this->wrapper = NULL;
}
ProtocolMessage& operator = (ProtocolMessage&& message)
@@ -125,7 +125,6 @@ public:
delete this->attachment;
this->attachment = message.attachment;
message.attachment = NULL;
this->wrapper = message.wrapper;
}
return *this;
@@ -153,22 +152,28 @@ protected:
return this->message->inner();
}
protected:
void set_message(ProtocolMessage *message)
{
this->message = message;
if (message)
message->wrapper = this;
}
protected:
ProtocolMessage *message;
public:
ProtocolWrapper(ProtocolMessage *message)
{
message->wrapper = this;
this->message = message;
this->set_message(message);
}
public:
ProtocolWrapper(ProtocolWrapper&& wrapper) :
ProtocolMessage(std::move(wrapper))
{
wrapper.message->wrapper = this;
this->message = wrapper.message;
this->set_message(wrapper.message);
wrapper.message = NULL;
}
@@ -177,8 +182,7 @@ public:
if (&wrapper != this)
{
*(ProtocolMessage *)this = std::move(wrapper);
wrapper.message->wrapper = this;
this->message = wrapper.message;
this->set_message(wrapper.message);
wrapper.message = NULL;
}