Skip to content

Commit

Permalink
Update ProtocolWrapper.
Browse files Browse the repository at this point in the history
  • Loading branch information
Barenboim committed Aug 2, 2024
1 parent 47eeced commit 8ad625b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/factory/MySQLTaskImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ class ComplexMySQLTask : public WFComplexClientTask<MySQLRequest, MySQLResponse>
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:
Expand Down
62 changes: 39 additions & 23 deletions src/protocol/ProtocolMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ class ProtocolMessage : public CommMessageOut, public CommMessageIn
return this->CommMessageIn::feedback(buf, size);
}

virtual void renew()
{
if (this->wrapper)
return this->wrapper->renew();
else
return this->CommMessageIn::renew();
}

virtual ProtocolMessage *inner() { return this; }

protected:
size_t size_limit;

Expand All @@ -99,23 +109,23 @@ class ProtocolMessage : public CommMessageOut, public CommMessageIn
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;
Expand All @@ -129,41 +139,47 @@ 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->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)
{
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;
Expand Down
7 changes: 4 additions & 3 deletions src/protocol/SSLWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class SSLWrapper : public ProtocolWrapper
SSL *ssl;

public:
SSLWrapper(ProtocolMessage *msg, SSL *ssl) :
ProtocolWrapper(msg)
SSLWrapper(ProtocolMessage *message, SSL *ssl) :
ProtocolWrapper(message)
{
this->ssl = ssl;
}
Expand All @@ -78,7 +78,8 @@ class ServerSSLWrapper : public SSLWrapper
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)
{
}

Expand Down

0 comments on commit 8ad625b

Please sign in to comment.