add PackageWrapper for MySQL Binlog

This commit is contained in:
XieHan
2022-04-12 21:13:51 +08:00
parent 75c28269b6
commit e02826ca10
6 changed files with 119 additions and 1 deletions

1
BUILD
View File

@@ -55,6 +55,7 @@ cc_library(
'src/protocol/DnsMessage.cc',
'src/protocol/DnsUtil.cc',
'src/protocol/SSLWrapper.cc',
'src/protocol/PackageWrapper.cc',
'src/protocol/dns_parser.c',
'src/server/WFServer.cc',
'src/kernel/CommRequest.cc',

View File

@@ -50,6 +50,7 @@ set(INCLUDE_HEADERS
src/protocol/mysql_parser.h
src/protocol/mysql_types.h
src/protocol/mysql_byteorder.h
src/protocol/PackageWrapper.h
src/protocol/SSLWrapper.h
src/protocol/dns_parser.h
src/protocol/DnsMessage.h

View File

@@ -0,0 +1 @@
../../protocol/PackageWrapper.h

View File

@@ -2,10 +2,11 @@ cmake_minimum_required(VERSION 3.6)
project(protocol)
set(SRC
PackageWrapper.cc
SSLWrapper.cc
dns_parser.c
DnsMessage.cc
DnsUtil.cc
SSLWrapper.cc
http_parser.c
HttpMessage.cc
HttpUtil.cc

View File

@@ -0,0 +1,66 @@
/*
Copyright (c) 2022 Sogou, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Author: Xie Han (xiehan@sogou-inc.com)
*/
#include <errno.h>
#include "PackageWrapper.h"
namespace protocol
{
int PackageWrapper::encode(struct iovec vectors[], int max)
{
int cnt = 0;
int ret;
while (max >= 8)
{
ret = this->ProtocolWrapper::encode(vectors, max);
if ((unsigned int)ret > (unsigned int)max)
{
if (ret < 0)
return ret;
break;
}
cnt += ret;
this->msg = this->next(this->msg);
if (!this->msg)
return cnt;
vectors += ret;
max -= ret;
}
errno = EOVERFLOW;
return -1;
}
int PackageWrapper::append(const void *buf, size_t *size)
{
int ret = this->ProtocolWrapper::append(buf, size);
if (ret <= 0)
return ret;
this->msg = this->next(this->msg);
return !this->msg;
}
}

View File

@@ -0,0 +1,48 @@
/*
Copyright (c) 2022 Sogou, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Author: Xie Han (xiehan@sogou-inc.com)
*/
#ifndef _PACKAGEWRAPPER_H_
#define _PACKAGEWRAPPER_H_
#include "ProtocolMessage.h"
namespace protocol
{
class PackageWrapper : public ProtocolWrapper
{
private:
virtual ProtocolMessage *next(ProtocolMessage *msg)
{
return NULL;
}
protected:
virtual int encode(struct iovec vectors[], int max);
virtual int append(const void *buf, size_t *size);
public:
PackageWrapper(ProtocolMessage *msg) : ProtocolWrapper(msg)
{
}
};
}
#endif