1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-06-13 16:01:32 +03:00

Reformat all code to coding standard

This commit is contained in:
Andrew Hutchings
2017-10-26 17:18:17 +01:00
parent 4985f3456e
commit 01446d1e22
1296 changed files with 403852 additions and 353747 deletions

View File

@ -52,279 +52,300 @@ using namespace config;
#include "messagequeue.h"
#undef MESSAGEQUEUE_DLLEXPORT
namespace messageqcpp {
namespace messageqcpp
{
void MessageQueueServer::setup(size_t blocksize, int backlog, bool syncProto)
{
string thisEndPortStr;
string thisEndPortStr;
thisEndPortStr = fConfig->getConfig(fThisEnd, "Port");
uint16_t port;
thisEndPortStr = fConfig->getConfig(fThisEnd, "Port");
uint16_t port;
if (thisEndPortStr.length() == 0 || (port = static_cast<uint16_t>(strtol(thisEndPortStr.c_str(), 0, 0))) == 0)
{
string msg = "MessageQueueServer::MessageQueueServer: config error: Invalid/Missing Port "
"attribute for " + fThisEnd;
throw runtime_error(msg);
}
if (thisEndPortStr.length() == 0 || (port = static_cast<uint16_t>(strtol(thisEndPortStr.c_str(), 0, 0))) == 0)
{
string msg = "MessageQueueServer::MessageQueueServer: config error: Invalid/Missing Port "
"attribute for " + fThisEnd;
throw runtime_error(msg);
}
in_addr listenAddr;
listenAddr.s_addr = INADDR_ANY;
string listenAddrStr = fConfig->getConfig(fThisEnd, "ListenAddr");
if (listenAddrStr.length() > 0)
{
struct in_addr la;
if (inet_aton(listenAddrStr.c_str(), &la) != 0)
listenAddr = la;
}
in_addr listenAddr;
listenAddr.s_addr = INADDR_ANY;
string listenAddrStr = fConfig->getConfig(fThisEnd, "ListenAddr");
memset(&fServ_addr, 0, sizeof(fServ_addr));
sockaddr_in* sinp = reinterpret_cast<sockaddr_in*>(&fServ_addr);
sinp->sin_family = AF_INET;
sinp->sin_addr.s_addr = listenAddr.s_addr;
sinp->sin_port = htons(port);
if (listenAddrStr.length() > 0)
{
struct in_addr la;
if (inet_aton(listenAddrStr.c_str(), &la) != 0)
listenAddr = la;
}
memset(&fServ_addr, 0, sizeof(fServ_addr));
sockaddr_in* sinp = reinterpret_cast<sockaddr_in*>(&fServ_addr);
sinp->sin_family = AF_INET;
sinp->sin_addr.s_addr = listenAddr.s_addr;
sinp->sin_port = htons(port);
#ifdef SKIP_IDB_COMPRESSION
fListenSock.setSocketImpl(new InetStreamSocket(blocksize));
fListenSock.setSocketImpl(new InetStreamSocket(blocksize));
#else
fListenSock.setSocketImpl(new CompressedInetStreamSocket());
fListenSock.setSocketImpl(new CompressedInetStreamSocket());
#endif
fListenSock.syncProto(syncProto);
fListenSock.open();
fListenSock.bind(&fServ_addr);
fListenSock.listen(backlog);
fListenSock.syncProto(syncProto);
fListenSock.open();
fListenSock.bind(&fServ_addr);
fListenSock.listen(backlog);
#ifdef SKIP_IDB_COMPRESSION
fClientSock.setSocketImpl(new InetStreamSocket(blocksize));
fClientSock.setSocketImpl(new InetStreamSocket(blocksize));
#else
fClientSock.setSocketImpl(new CompressedInetStreamSocket());
fClientSock.setSocketImpl(new CompressedInetStreamSocket());
#endif
fClientSock.syncProto(syncProto);
fClientSock.syncProto(syncProto);
}
MessageQueueServer::MessageQueueServer(const string& thisEnd, const string& config,
size_t blocksize, int backlog, bool syncProto) :
fThisEnd(thisEnd),
fConfig(Config::makeConfig(config)),
fLogger(31)
size_t blocksize, int backlog, bool syncProto) :
fThisEnd(thisEnd),
fConfig(Config::makeConfig(config)),
fLogger(31)
{
setup(blocksize, backlog, syncProto);
setup(blocksize, backlog, syncProto);
}
MessageQueueServer::MessageQueueServer(const string& thisEnd, Config* config,
size_t blocksize, int backlog, bool syncProto) :
fThisEnd(thisEnd),
fConfig(config),
fLogger(31)
size_t blocksize, int backlog, bool syncProto) :
fThisEnd(thisEnd),
fConfig(config),
fLogger(31)
{
if (fConfig == 0)
fConfig = Config::makeConfig();
if (fConfig == 0)
fConfig = Config::makeConfig();
setup(blocksize, backlog, syncProto);
setup(blocksize, backlog, syncProto);
}
MessageQueueServer::~MessageQueueServer()
{
fClientSock.close();
fListenSock.close();
fClientSock.close();
fListenSock.close();
}
const IOSocket MessageQueueServer::accept(const struct timespec* timeout) const
{
return fListenSock.accept(timeout);
return fListenSock.accept(timeout);
}
void MessageQueueServer::syncProto(bool use)
{
fListenSock.syncProto(use);
fClientSock.syncProto(use);
fListenSock.syncProto(use);
fClientSock.syncProto(use);
}
MessageQueueClient::~MessageQueueClient()
{
fClientSock.close();
fClientSock.close();
}
void MessageQueueClient::shutdown()
{
fClientSock.close();
fClientSock.close();
}
void MessageQueueClient::setup(bool syncProto)
{
string otherEndIPStr;
string otherEndPortStr;
uint16_t port;
string otherEndIPStr;
string otherEndPortStr;
uint16_t port;
otherEndIPStr = fConfig->getConfig(fOtherEnd, "IPAddr");
otherEndPortStr = fConfig->getConfig(fOtherEnd, "Port");
otherEndIPStr = fConfig->getConfig(fOtherEnd, "IPAddr");
otherEndPortStr = fConfig->getConfig(fOtherEnd, "Port");
if (otherEndIPStr.length() == 0) otherEndIPStr = "127.0.0.1";
if (otherEndIPStr.length() == 0) otherEndIPStr = "127.0.0.1";
if (otherEndPortStr.length() == 0 || (port = static_cast<uint16_t>(strtol(otherEndPortStr.c_str(), 0, 0))) == 0)
{
string msg = "MessageQueueClient::MessageQueueClient: config error: Invalid/Missing Port attribute";
throw runtime_error(msg);
}
if (otherEndPortStr.length() == 0 || (port = static_cast<uint16_t>(strtol(otherEndPortStr.c_str(), 0, 0))) == 0)
{
string msg = "MessageQueueClient::MessageQueueClient: config error: Invalid/Missing Port attribute";
throw runtime_error(msg);
}
memset(&fServ_addr, 0, sizeof(fServ_addr));
sockaddr_in* sinp = reinterpret_cast<sockaddr_in*>(&fServ_addr);
sinp->sin_family = AF_INET;
sinp->sin_port = htons(port);
sinp->sin_addr.s_addr = inet_addr(otherEndIPStr.c_str());
memset(&fServ_addr, 0, sizeof(fServ_addr));
sockaddr_in* sinp = reinterpret_cast<sockaddr_in*>(&fServ_addr);
sinp->sin_family = AF_INET;
sinp->sin_port = htons(port);
sinp->sin_addr.s_addr = inet_addr(otherEndIPStr.c_str());
#ifdef SKIP_IDB_COMPRESSION
fClientSock.setSocketImpl(new InetStreamSocket());
fClientSock.setSocketImpl(new InetStreamSocket());
#else
fClientSock.setSocketImpl(new CompressedInetStreamSocket());
fClientSock.setSocketImpl(new CompressedInetStreamSocket());
#endif
fClientSock.syncProto(syncProto);
fClientSock.sa(&fServ_addr);
fClientSock.syncProto(syncProto);
fClientSock.sa(&fServ_addr);
}
MessageQueueClient::MessageQueueClient(const string& otherEnd, const string& config, bool syncProto) :
fOtherEnd(otherEnd), fConfig(Config::makeConfig(config)), fLogger(31), fIsAvailable(true)
fOtherEnd(otherEnd), fConfig(Config::makeConfig(config)), fLogger(31), fIsAvailable(true)
{
setup(syncProto);
setup(syncProto);
}
MessageQueueClient::MessageQueueClient(const string& otherEnd, Config* config, bool syncProto) :
fOtherEnd(otherEnd), fConfig(config), fLogger(31), fIsAvailable(true)
fOtherEnd(otherEnd), fConfig(config), fLogger(31), fIsAvailable(true)
{
if (fConfig == 0)
fConfig = Config::makeConfig();
if (fConfig == 0)
fConfig = Config::makeConfig();
setup(syncProto);
setup(syncProto);
}
MessageQueueClient::MessageQueueClient(const string& ip, uint16_t port, bool syncProto) :
fLogger(31), fIsAvailable(true)
fLogger(31), fIsAvailable(true)
{
memset(&fServ_addr, 0, sizeof(fServ_addr));
sockaddr_in* sinp = reinterpret_cast<sockaddr_in*>(&fServ_addr);
sinp->sin_family = AF_INET;
sinp->sin_port = htons(port);
sinp->sin_addr.s_addr = inet_addr(ip.c_str());
memset(&fServ_addr, 0, sizeof(fServ_addr));
sockaddr_in* sinp = reinterpret_cast<sockaddr_in*>(&fServ_addr);
sinp->sin_family = AF_INET;
sinp->sin_port = htons(port);
sinp->sin_addr.s_addr = inet_addr(ip.c_str());
#ifdef SKIP_IDB_COMPRESSION
fClientSock.setSocketImpl(new InetStreamSocket());
fClientSock.setSocketImpl(new InetStreamSocket());
#else
fClientSock.setSocketImpl(new CompressedInetStreamSocket());
fClientSock.setSocketImpl(new CompressedInetStreamSocket());
#endif
fClientSock.syncProto(syncProto);
fClientSock.sa(&fServ_addr);
fClientSock.syncProto(syncProto);
fClientSock.sa(&fServ_addr);
}
const SBS MessageQueueClient::read(const struct timespec* timeout, bool* isTimeOut, Stats *stats) const
const SBS MessageQueueClient::read(const struct timespec* timeout, bool* isTimeOut, Stats* stats) const
{
if (!fClientSock.isOpen())
{
fClientSock.open();
try {
fClientSock.connect(&fServ_addr);
}
catch (...) {
fClientSock.close();
throw;
}
}
if (!fClientSock.isOpen())
{
fClientSock.open();
SBS res;
try
{
res = fClientSock.read(timeout, isTimeOut, stats);
}
catch (runtime_error& re)
{
// This is an I/O error from IOSocket::read()
try
{
fClientSock.connect(&fServ_addr);
}
catch (...)
{
fClientSock.close();
throw;
}
}
SBS res;
try
{
res = fClientSock.read(timeout, isTimeOut, stats);
}
catch (runtime_error& re)
{
// This is an I/O error from IOSocket::read()
// cerr << "MessageQueueClient::read: close socket for " << re.what() << endl;
logging::Message::Args args;
logging::LoggingID li(31);
args.add("Client read close socket for");
args.add(re.what());
fLogger.logMessage(logging::LOG_TYPE_WARNING, logging::M0000, args, li);
fClientSock.close();
throw;
}
catch (SocketClosed &e) {
logging::Message::Args args;
logging::LoggingID li(31);
args.add("Client read close socket for");
args.add(re.what());
fLogger.logMessage(logging::LOG_TYPE_WARNING, logging::M0000, args, li);
fClientSock.close();
throw;
}
catch (SocketClosed& e)
{
// cerr << "MessageQueueClient::read: close socket for " << e.what() << endl;
logging::Message::Args args;
logging::LoggingID li(31);
args.add("Client read close socket for");
args.add(e.what());
fLogger.logMessage(logging::LOG_TYPE_WARNING, logging::M0000, args, li);
fClientSock.close();
throw;
}
return res;
logging::Message::Args args;
logging::LoggingID li(31);
args.add("Client read close socket for");
args.add(e.what());
fLogger.logMessage(logging::LOG_TYPE_WARNING, logging::M0000, args, li);
fClientSock.close();
throw;
}
return res;
}
void MessageQueueClient::write(const ByteStream& msg, const struct timespec* timeout, Stats *stats) const
void MessageQueueClient::write(const ByteStream& msg, const struct timespec* timeout, Stats* stats) const
{
if (!fClientSock.isOpen())
{
fClientSock.open();
try {
fClientSock.connectionTimeout(timeout);
fClientSock.connect(&fServ_addr);
}
catch(...) {
fClientSock.close();
throw;
}
}
if (!fClientSock.isOpen())
{
fClientSock.open();
try {
fClientSock.write(msg, stats);
}
catch (runtime_error &e) {
try
{
ostringstream oss;
oss << "MessageQueueClient::write: error writing " << msg.length() << " bytes to "
<< fClientSock << ". Socket error was " << e.what() << endl;
try
{
fClientSock.connectionTimeout(timeout);
fClientSock.connect(&fServ_addr);
}
catch (...)
{
fClientSock.close();
throw;
}
}
try
{
fClientSock.write(msg, stats);
}
catch (runtime_error& e)
{
try
{
ostringstream oss;
oss << "MessageQueueClient::write: error writing " << msg.length() << " bytes to "
<< fClientSock << ". Socket error was " << e.what() << endl;
// cerr << oss.str() << endl;
logging::Message::Args args;
logging::LoggingID li(31);
args.add(oss.str());
fLogger.logMessage(logging::LOG_TYPE_WARNING, logging::M0000, args, li);
}
catch (...)
{
}
fClientSock.close();
throw;
}
logging::Message::Args args;
logging::LoggingID li(31);
args.add(oss.str());
fLogger.logMessage(logging::LOG_TYPE_WARNING, logging::M0000, args, li);
}
catch (...)
{
}
fClientSock.close();
throw;
}
}
bool MessageQueueClient::connect() const
{
if (!fClientSock.isOpen())
{
fClientSock.open();
if (!fClientSock.isOpen())
{
fClientSock.open();
try {
fClientSock.connect(&fServ_addr);
}
catch (runtime_error& re) {
string what = re.what();
if (what.find("Connection refused") != string::npos)
{
try {
fClientSock.close();
}
catch (...) {
}
}
else
throw;
}
catch (...) {
throw;
}
}
try
{
fClientSock.connect(&fServ_addr);
}
catch (runtime_error& re)
{
string what = re.what();
return fClientSock.isOpen();
if (what.find("Connection refused") != string::npos)
{
try
{
fClientSock.close();
}
catch (...)
{
}
}
else
throw;
}
catch (...)
{
throw;
}
}
return fClientSock.isOpen();
}
}//namespace messageqcpp