mirror of
https://github.com/joyieldInc/predixy.git
synced 2025-12-24 22:46:41 +08:00
Add a fix(by @fortrue)
This commit is contained in:
parent
a559ac0d4f
commit
a13bb36159
@ -9,6 +9,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include "String.h"
|
#include "String.h"
|
||||||
#include "Command.h"
|
#include "Command.h"
|
||||||
|
#include "Conf.h"
|
||||||
|
|
||||||
Command Command::CmdPool[AvailableCommands] = {
|
Command Command::CmdPool[AvailableCommands] = {
|
||||||
{None, "", 0, MaxArgs, Read},
|
{None, "", 0, MaxArgs, Read},
|
||||||
@ -190,15 +191,20 @@ void Command::init()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Command::addCustomCommand(const Command& c) {
|
void Command::addCustomCommand(const CustomCommandConf& ccc) {
|
||||||
if (Sentinel >= AvailableCommands) {
|
if (Sentinel >= AvailableCommands) {
|
||||||
Throw(InitFail, "too many custom commands(>%d)", MaxCustomCommands);
|
Throw(InitFail, "too many custom commands(>%d)", MaxCustomCommands);
|
||||||
}
|
}
|
||||||
if (nullptr != find(c.name)) {
|
if (nullptr != find(ccc.name)) {
|
||||||
Throw(InitFail, "custom command %s is duplicated", c.name);
|
Throw(InitFail, "custom command %s is duplicated", ccc.name);
|
||||||
}
|
}
|
||||||
CmdPool[Sentinel] = c;
|
auto* p = &CmdPool[Sentinel];
|
||||||
CmdMap[c.name] = &CmdPool[Sentinel];
|
p->name = ccc.name.c_str();
|
||||||
|
p->minArgs = ccc.minArgs;
|
||||||
|
p->maxArgs = ccc.maxArgs;
|
||||||
|
p->mode = ccc.mode;
|
||||||
|
p->type = (Command::Type)ccc.type;
|
||||||
|
CmdMap[ccc.name] = p;
|
||||||
Sentinel++;
|
Sentinel++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -11,6 +11,8 @@
|
|||||||
#include "Exception.h"
|
#include "Exception.h"
|
||||||
#include "HashFunc.h"
|
#include "HashFunc.h"
|
||||||
|
|
||||||
|
struct CustomCommandConf;
|
||||||
|
|
||||||
class Command
|
class Command
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -251,7 +253,7 @@ public:
|
|||||||
auto it = CmdMap.find(cmd);
|
auto it = CmdMap.find(cmd);
|
||||||
return it == CmdMap.end() ? nullptr : it->second;
|
return it == CmdMap.end() ? nullptr : it->second;
|
||||||
}
|
}
|
||||||
static void addCustomCommand(const Command& pc);
|
static void addCustomCommand(const CustomCommandConf& pc);
|
||||||
static int Sentinel;
|
static int Sentinel;
|
||||||
private:
|
private:
|
||||||
static const int MaxArgs = 100000000;
|
static const int MaxArgs = 100000000;
|
||||||
|
|||||||
16
src/Conf.cpp
16
src/Conf.cpp
@ -41,14 +41,6 @@ void CustomCommandConf::init(CustomCommandConf&c, const char* name, const int ty
|
|||||||
c.mode = Command::Write;
|
c.mode = Command::Write;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomCommandConf::convert(const CustomCommandConf&c, Command &cmd) {
|
|
||||||
cmd.name = strdup(c.name.c_str());
|
|
||||||
cmd.minArgs = c.minArgs;
|
|
||||||
cmd.maxArgs = c.maxArgs;
|
|
||||||
cmd.mode = c.mode;
|
|
||||||
cmd.type = (Command::Type)c.type;
|
|
||||||
}
|
|
||||||
|
|
||||||
Conf::Conf():
|
Conf::Conf():
|
||||||
mBind("0.0.0.0:7617"),
|
mBind("0.0.0.0:7617"),
|
||||||
mWorkerThreads(1),
|
mWorkerThreads(1),
|
||||||
@ -197,7 +189,7 @@ void Conf::setGlobal(const ConfParser::Node* node)
|
|||||||
if (dataCenter) {
|
if (dataCenter) {
|
||||||
setDataCenter(dataCenter);
|
setDataCenter(dataCenter);
|
||||||
}
|
}
|
||||||
for (auto latencyMonitor : latencyMonitors) {
|
for (auto& latencyMonitor : latencyMonitors) {
|
||||||
mLatencyMonitors.push_back(LatencyMonitorConf{});
|
mLatencyMonitors.push_back(LatencyMonitorConf{});
|
||||||
setLatencyMonitor(mLatencyMonitors.back(), latencyMonitor);
|
setLatencyMonitor(mLatencyMonitors.back(), latencyMonitor);
|
||||||
}
|
}
|
||||||
@ -402,9 +394,9 @@ void Conf::setCustomCommand(const ConfParser::Node* node)
|
|||||||
if (cc.maxArgs < cc.minArgs) {
|
if (cc.maxArgs < cc.minArgs) {
|
||||||
Throw(InvalidValue, "%s:%d must be MaxArgs >= MinArgs", p->file, p->line);
|
Throw(InvalidValue, "%s:%d must be MaxArgs >= MinArgs", p->file, p->line);
|
||||||
}
|
}
|
||||||
Command cmd;
|
}
|
||||||
CustomCommandConf::convert(cc, cmd);
|
for (const auto& cc : mCustomCommands) {
|
||||||
Command::addCustomCommand(cmd);
|
Command::addCustomCommand(cc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -103,7 +103,6 @@ struct CustomCommandConf
|
|||||||
int mode;
|
int mode;
|
||||||
|
|
||||||
static void init(CustomCommandConf &c, const char* name, const int type);
|
static void init(CustomCommandConf &c, const char* name, const int type);
|
||||||
static void convert(const CustomCommandConf&c, Command &cmd);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Conf
|
class Conf
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user