Update ProtocolWrapper. (#1597)

This commit is contained in:
xiehan
2024-08-02 19:14:03 +08:00
committed by GitHub
parent 3e8f57160a
commit 6a919fb994
5 changed files with 46 additions and 35 deletions

View File

@@ -100,8 +100,8 @@ private:
MySSLWrapper(ProtocolMessage *msg, SSL *ssl) :
SSLWrapper(msg, ssl)
{ }
ProtocolMessage *get_msg() const { return this->msg; }
virtual ~MySSLWrapper() { delete this->msg; }
ProtocolMessage *get_msg() const { return this->message; }
virtual ~MySSLWrapper() { delete this->message; }
};
private:

View File

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

View File

@@ -27,7 +27,17 @@ namespace protocol
class PackageWrapper : public ProtocolWrapper
{
private:
virtual ProtocolMessage *next(ProtocolMessage *msg)
virtual ProtocolMessage *next_in(ProtocolMessage *message)
{
return this->next(message);
}
virtual ProtocolMessage *next_out(ProtocolMessage *message)
{
return this->next(message);
}
virtual ProtocolMessage *next(ProtocolMessage *message)
{
return NULL;
}
@@ -37,7 +47,7 @@ protected:
virtual int append(const void *buf, size_t *size);
public:
PackageWrapper(ProtocolMessage *msg) : ProtocolWrapper(msg)
PackageWrapper(ProtocolMessage *message) : ProtocolWrapper(message)
{
}

View File

@@ -109,23 +109,23 @@ public:
virtual ~ProtocolMessage() { delete this->attachment; }
public:
ProtocolMessage(ProtocolMessage&& msg)
ProtocolMessage(ProtocolMessage&& message)
{
this->size_limit = msg.size_limit;
msg.size_limit = (size_t)-1;
this->attachment = msg.attachment;
msg.attachment = NULL;
this->size_limit = message.size_limit;
message.size_limit = (size_t)-1;
this->attachment = message.attachment;
message.attachment = NULL;
}
ProtocolMessage& operator = (ProtocolMessage&& msg)
ProtocolMessage& operator = (ProtocolMessage&& message)
{
if (&msg != this)
if (&message != this)
{
this->size_limit = msg.size_limit;
msg.size_limit = (size_t)-1;
this->size_limit = message.size_limit;
message.size_limit = (size_t)-1;
delete this->attachment;
this->attachment = msg.attachment;
msg.attachment = NULL;
this->attachment = message.attachment;
message.attachment = NULL;
}
return *this;
@@ -139,37 +139,37 @@ class ProtocolWrapper : public ProtocolMessage
protected:
virtual int encode(struct iovec vectors[], int max)
{
return this->msg->encode(vectors, max);
return this->message->encode(vectors, max);
}
virtual int append(const void *buf, size_t *size)
{
return this->msg->append(buf, size);
return this->message->append(buf, size);
}
protected:
virtual ProtocolMessage *inner()
{
return this->msg->inner();
return this->message->inner();
}
protected:
ProtocolMessage *msg;
ProtocolMessage *message;
public:
ProtocolWrapper(ProtocolMessage *msg)
ProtocolWrapper(ProtocolMessage *message)
{
msg->wrapper = this;
this->msg = msg;
message->wrapper = this;
this->message = message;
}
public:
ProtocolWrapper(ProtocolWrapper&& wrapper) :
ProtocolMessage(std::move(wrapper))
{
wrapper.msg->wrapper = this;
this->msg = wrapper.msg;
wrapper.msg = NULL;
wrapper.message->wrapper = this;
this->message = wrapper.message;
wrapper.message = NULL;
}
ProtocolWrapper& operator = (ProtocolWrapper&& wrapper)
@@ -177,9 +177,9 @@ public:
if (&wrapper != this)
{
*(ProtocolMessage *)this = std::move(wrapper);
wrapper.msg->wrapper = this;
this->msg = wrapper.msg;
wrapper.msg = NULL;
wrapper.message->wrapper = this;
this->message = wrapper.message;
wrapper.message = NULL;
}
return *this;

View File

@@ -61,8 +61,8 @@ protected:
SSL *ssl;
public:
SSLWrapper(ProtocolMessage *msg, SSL *ssl) :
ProtocolWrapper(msg)
SSLWrapper(ProtocolMessage *message, SSL *ssl) :
ProtocolWrapper(message)
{
this->ssl = ssl;
}
@@ -78,7 +78,8 @@ protected:
virtual int append(const void *buf, size_t *size);
public:
ServerSSLWrapper(ProtocolMessage *msg, SSL *ssl) : SSLWrapper(msg, ssl)
ServerSSLWrapper(ProtocolMessage *message, SSL *ssl) :
SSLWrapper(message, ssl)
{
}