mirror of
https://github.com/sogou/workflow.git
synced 2026-02-08 01:33:17 +08:00
add PackageWrapper for MySQL Binlog
This commit is contained in:
1
BUILD
1
BUILD
@@ -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',
|
||||
|
||||
@@ -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
|
||||
|
||||
1
src/include/workflow/PackageWrapper.h
Symbolic link
1
src/include/workflow/PackageWrapper.h
Symbolic link
@@ -0,0 +1 @@
|
||||
../../protocol/PackageWrapper.h
|
||||
@@ -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
|
||||
|
||||
66
src/protocol/PackageWrapper.cc
Normal file
66
src/protocol/PackageWrapper.cc
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
48
src/protocol/PackageWrapper.h
Normal file
48
src/protocol/PackageWrapper.h
Normal 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
|
||||
|
||||
Reference in New Issue
Block a user