2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
43#include "database/mariadb/MariaDBConnection.h"
45#include "database/mariadb/MariaDBClient.h"
46#include "database/mariadb/commands/async/MariaDBConnectCommand.h"
48#ifndef DOXYGEN_SHOULD_SKIP_THIS
50#include "core/SNodeC.h"
51#include "log/Logger.h"
52#include "utils/Timeval.h"
64 const std::function<
void(
const MariaDBState&)>& onStateChanged)
73 mysql_options(mysql, MYSQL_OPT_NONBLOCK,
nullptr);
78 if (mysql_errno(mysql) == 0) {
79 const int fd = mysql_get_socket(mysql);
81 if (ReadEventReceiver::enable(fd) && WriteEventReceiver::enable(fd) && ExceptionalConditionEventReceiver::enable(fd)) {
82 ReadEventReceiver::suspend();
83 WriteEventReceiver::suspend();
84 ExceptionalConditionEventReceiver::suspend();
88 if (ReadEventReceiver::isEnabled()) {
89 ReadEventReceiver::disable();
91 if (WriteEventReceiver::isEnabled()) {
92 WriteEventReceiver::disable();
94 if (ExceptionalConditionEventReceiver::isEnabled()) {
95 ExceptionalConditionEventReceiver::disable();
98 LOG(ERROR) <<
this->connectionName <<
" MariaDB: Descriptor not registered in SNode.C eventloop";
103 LOG(DEBUG) <<
this->connectionName <<
" MariaDB connect: success";
105 this->onStateChanged({.connected =
true});
107 [
this](
const std::string& errorString,
unsigned int errorNumber) {
108 LOG(WARNING) <<
this->connectionName <<
" MariaDB connect: error: " << errorString <<
" : " << errorNumber;
110 this->onStateChanged({.error = errorNumber, .errorMessage = errorString});
115 for (MariaDBCommandSequence& mariaDBCommandSequence : commandSequenceQueue) {
116 for (MariaDBCommand* mariaDBCommand : mariaDBCommandSequence.sequence()) {
117 if (core::SNodeC::state() == core::State::RUNNING && connected) {
118 mariaDBCommand->commandError(mysql_error(mysql), mysql_errno(mysql));
121 delete mariaDBCommand;
134 if (currentCommand ==
nullptr && commandSequenceQueue.empty()) {
138 commandSequenceQueue.emplace_back(std::move(commandSequence));
140 return commandSequenceQueue.back();
146 if (mysql_errno(mysql) == 0) {
153 delete mariaDBCommand;
157 if (!commandSequenceQueue.empty()) {
158 currentCommand = commandSequenceQueue.front().nextCommand();
178 }
else if ((status & MYSQL_WAIT_READ) != 0 && commandSequenceQueue.empty()) {
187 commandSequenceQueue.front().commandCompleted();
189 if (commandSequenceQueue.front().empty()) {
190 commandSequenceQueue.pop_front();
200 if (currentCommand ==
nullptr && commandSequenceQueue.empty()) {
215 if ((status & MYSQL_WAIT_READ) != 0) {
223 if ((status & MYSQL_WAIT_WRITE) != 0) {
231 if ((status & MYSQL_WAIT_EXCEPT) != 0) {
239 if ((status & MYSQL_WAIT_TIMEOUT) != 0) {
250 if (mysql_errno(mysql) == 0) {
void setTimeout(const utils::Timeval &timeout)
EventReceiver(const std::string &name)
void connectionVanished()
MariaDBCommandSequence()=default
MariaDBCommandSequence & execute_async(MariaDBCommand *mariaDBCommand) final
MariaDBConnection * mariaDBConnection
void onEvent(const utils::Timeval ¤tTime) override
virtual std::string commandInfo()
virtual int commandContinue(int status)=0
void setMariaDBConnection(MariaDBConnection *mariaDBConnection)
virtual void commandError(const std::string &errorString, unsigned int errorNumber)=0
virtual int commandStart()=0
virtual bool commandCompleted()=0
void unobservedEvent() override
MariaDBCommandStartEvent commandStartEvent
void writeTimeout() override
void outOfBandTimeout() override
MariaDBConnection(MariaDBClient *mariaDBClient, const MariaDBConnectionDetails &connectionDetails, const std::function< void(const MariaDBState &)> &onStateChanged)
void outOfBandEvent() override
void writeEvent() override
MariaDBCommand * currentCommand
MariaDBCommandSequence & execute_async(MariaDBCommandSequence &&commandSequence)
~MariaDBConnection() override
const std::string connectionName
void readTimeout() override
void commandContinue(int status)
void commandStart(const utils::Timeval ¤tTime)
void execute_sync(MariaDBCommand *mariaDBCommand)
MariaDBClient * mariaDBClient
void readEvent() override
void checkStatus(int status)
static Timeval currentTime()
static const utils::Timeval DISABLE
static const utils::Timeval DEFAULT
std::string connectionName