mirror of
https://github.com/sogou/workflow.git
synced 2026-10-22 07:06:30 +08:00
Merge pull request #223 from Barenboim/master
add ProtocolMessage::Attachment
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <utility>
|
||||
#include "HttpMessage.h"
|
||||
|
||||
namespace protocol
|
||||
@@ -222,11 +223,9 @@ inline int HttpMessage::append(const void *buf, size_t *size)
|
||||
return ret;
|
||||
}
|
||||
|
||||
HttpMessage::HttpMessage(HttpMessage&& msg)
|
||||
HttpMessage::HttpMessage(HttpMessage&& msg) :
|
||||
ProtocolMessage(std::move(msg))
|
||||
{
|
||||
this->size_limit = msg.size_limit;
|
||||
msg.size_limit = (size_t)-1;
|
||||
|
||||
this->parser = msg.parser;
|
||||
msg.parser = NULL;
|
||||
|
||||
@@ -243,8 +242,7 @@ HttpMessage& HttpMessage::operator = (HttpMessage&& msg)
|
||||
{
|
||||
if (&msg != this)
|
||||
{
|
||||
this->size_limit = msg.size_limit;
|
||||
msg.size_limit = (size_t)-1;
|
||||
*(ProtocolMessage *)this = std::move(msg);
|
||||
|
||||
http_parser_deinit(this->parser);
|
||||
delete this->parser;
|
||||
|
||||
@@ -278,12 +278,8 @@ public:
|
||||
|
||||
/* for std::move() */
|
||||
public:
|
||||
HttpRequest(HttpRequest&& req) : HttpMessage(std::move(req)) { }
|
||||
HttpRequest& operator = (HttpRequest&& req)
|
||||
{
|
||||
*(HttpMessage *)this = std::move(req);
|
||||
return *this;
|
||||
}
|
||||
HttpRequest(HttpRequest&& req) = default;
|
||||
HttpRequest& operator = (HttpRequest&& req) = default;
|
||||
};
|
||||
|
||||
class HttpResponse : public HttpMessage
|
||||
@@ -361,12 +357,8 @@ public:
|
||||
|
||||
/* for std::move() */
|
||||
public:
|
||||
HttpResponse(HttpResponse&& resp) : HttpMessage(std::move(resp)) { }
|
||||
HttpResponse& operator = (HttpResponse&& resp)
|
||||
{
|
||||
*(HttpMessage *)this = std::move(resp);
|
||||
return *this;
|
||||
}
|
||||
HttpResponse(HttpResponse&& resp) = default;
|
||||
HttpResponse& operator = (HttpResponse&& resp) = default;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1620,11 +1620,9 @@ KafkaMessage::~KafkaMessage()
|
||||
}
|
||||
}
|
||||
|
||||
KafkaMessage::KafkaMessage(KafkaMessage&& msg)
|
||||
KafkaMessage::KafkaMessage(KafkaMessage&& msg) :
|
||||
ProtocolMessage(std::move(msg))
|
||||
{
|
||||
this->size_limit = msg.size_limit;
|
||||
msg.size_limit = (size_t)-1;
|
||||
|
||||
this->parser = msg.parser;
|
||||
this->stream = msg.stream;
|
||||
msg.parser = NULL;
|
||||
@@ -1651,8 +1649,7 @@ KafkaMessage& KafkaMessage::operator= (KafkaMessage &&msg)
|
||||
{
|
||||
if (this != &msg)
|
||||
{
|
||||
this->size_limit = msg.size_limit;
|
||||
msg.size_limit = (size_t)-1;
|
||||
*(ProtocolMessage *)this = std::move(msg);
|
||||
|
||||
kafka_parser_deinit(this->parser);
|
||||
delete this->parser;
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <errno.h>
|
||||
#include <string>
|
||||
#include <openssl/sha.h>
|
||||
#include <utility>
|
||||
#include "MySQLMessage.h"
|
||||
#include "mysql_types.h"
|
||||
|
||||
@@ -41,11 +42,9 @@ MySQLMessage::~MySQLMessage()
|
||||
}
|
||||
}
|
||||
|
||||
MySQLMessage::MySQLMessage(MySQLMessage&& move)
|
||||
MySQLMessage::MySQLMessage(MySQLMessage&& move) :
|
||||
ProtocolMessage(std::move(move))
|
||||
{
|
||||
this->size_limit = move.size_limit;
|
||||
move.size_limit = (size_t)-1;
|
||||
|
||||
parser_ = move.parser_;
|
||||
stream_ = move.stream_;
|
||||
seqid_ = move.seqid_;
|
||||
@@ -61,8 +60,7 @@ MySQLMessage& MySQLMessage::operator= (MySQLMessage&& move)
|
||||
{
|
||||
if (this != &move)
|
||||
{
|
||||
this->size_limit = move.size_limit;
|
||||
move.size_limit = (size_t)-1;
|
||||
*(ProtocolMessage *)this = std::move(move);
|
||||
|
||||
mysql_parser_deinit(parser_);
|
||||
mysql_stream_deinit(stream_);
|
||||
|
||||
@@ -61,11 +61,52 @@ public:
|
||||
void set_size_limit(size_t limit) { this->size_limit = limit; }
|
||||
size_t get_size_limit() const { return this->size_limit; }
|
||||
|
||||
public:
|
||||
class Attachment
|
||||
{
|
||||
public:
|
||||
virtual ~Attachment() { }
|
||||
};
|
||||
|
||||
void set_attachment(Attachment *att) { this->attachment = att; }
|
||||
Attachment *get_attachment() const { return this->attachment; }
|
||||
|
||||
protected:
|
||||
size_t size_limit;
|
||||
|
||||
private:
|
||||
Attachment *attachment;
|
||||
|
||||
public:
|
||||
ProtocolMessage() { this->size_limit = (size_t)-1; }
|
||||
ProtocolMessage()
|
||||
{
|
||||
this->size_limit = (size_t)-1;
|
||||
this->attachment = NULL;
|
||||
}
|
||||
|
||||
virtual ~ProtocolMessage() { delete this->attachment; }
|
||||
|
||||
public:
|
||||
ProtocolMessage(ProtocolMessage&& msg)
|
||||
{
|
||||
this->size_limit = msg.size_limit;
|
||||
msg.size_limit = (size_t)-1;
|
||||
this->attachment = msg.attachment;
|
||||
msg.attachment = NULL;
|
||||
}
|
||||
|
||||
ProtocolMessage& operator = (ProtocolMessage&& msg)
|
||||
{
|
||||
if (&msg != this)
|
||||
{
|
||||
this->size_limit = msg.size_limit;
|
||||
msg.size_limit = (size_t)-1;
|
||||
this->attachment = msg.attachment;
|
||||
msg.attachment = NULL;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -485,11 +485,9 @@ std::string RedisValue::debug_string() const
|
||||
return ret;
|
||||
}
|
||||
|
||||
RedisMessage::RedisMessage(RedisMessage&& move)
|
||||
RedisMessage::RedisMessage(RedisMessage&& move) :
|
||||
ProtocolMessage(std::move(move))
|
||||
{
|
||||
this->size_limit = move.size_limit;
|
||||
move.size_limit = (size_t)-1;
|
||||
|
||||
parser_ = move.parser_;
|
||||
stream_ = move.stream_;
|
||||
cur_size_ = move.cur_size_;
|
||||
@@ -503,8 +501,7 @@ RedisMessage& RedisMessage::operator= (RedisMessage &&move)
|
||||
{
|
||||
if (this != &move)
|
||||
{
|
||||
this->size_limit = move.size_limit;
|
||||
move.size_limit = (size_t)-1;
|
||||
*(ProtocolMessage *)this = std::move(move);
|
||||
|
||||
redis_parser_deinit(parser_);
|
||||
delete parser_;
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <utility>
|
||||
#include "message.h"
|
||||
|
||||
namespace protocol
|
||||
@@ -106,11 +107,9 @@ int TutorialMessage::set_message_body(const void *body, size_t size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
TutorialMessage::TutorialMessage(TutorialMessage&& msg)
|
||||
TutorialMessage::TutorialMessage(TutorialMessage&& msg) :
|
||||
ProtocolMessage(std::move(msg))
|
||||
{
|
||||
this->size_limit = msg.size_limit;
|
||||
msg.size_limit = (size_t)-1;
|
||||
|
||||
memcpy(this->head, msg.head, 4);
|
||||
this->head_received = msg.head_received;
|
||||
this->body = msg.body;
|
||||
@@ -126,8 +125,7 @@ TutorialMessage& TutorialMessage::operator = (TutorialMessage&& msg)
|
||||
{
|
||||
if (&msg != this)
|
||||
{
|
||||
this->size_limit = msg.size_limit;
|
||||
msg.size_limit = (size_t)-1;
|
||||
*(ProtocolMessage *)this = std::move(msg);
|
||||
|
||||
memcpy(this->head, msg.head, 4);
|
||||
this->head_received = msg.head_received;
|
||||
|
||||
Reference in New Issue
Block a user