mirror of
https://github.com/joyieldInc/predixy.git
synced 2025-12-24 22:46:41 +08:00
support QUIT command
This commit is contained in:
parent
db2b856211
commit
6da3706900
@ -19,6 +19,7 @@ const Command Command::CmdPool[Sentinel] = {
|
|||||||
{AuthServ, "auth", 2, 2, Inner},
|
{AuthServ, "auth", 2, 2, Inner},
|
||||||
{Select, "select", 2, 2, Read},
|
{Select, "select", 2, 2, Read},
|
||||||
{SelectServ, "select", 2, 2, Inner},
|
{SelectServ, "select", 2, 2, Inner},
|
||||||
|
{Quit, "quit", 1, MaxArgs, Read},
|
||||||
{SentinelSentinels, "sentinel sentinels",3, 3, Inner},
|
{SentinelSentinels, "sentinel sentinels",3, 3, Inner},
|
||||||
{SentinelGetMaster, "sentinel get-m-a..",3, 3, Inner},
|
{SentinelGetMaster, "sentinel get-m-a..",3, 3, Inner},
|
||||||
{SentinelSlaves, "sentinel slaves", 3, 3, Inner},
|
{SentinelSlaves, "sentinel slaves", 3, 3, Inner},
|
||||||
|
|||||||
@ -25,6 +25,7 @@ public:
|
|||||||
AuthServ,
|
AuthServ,
|
||||||
Select,
|
Select,
|
||||||
SelectServ,
|
SelectServ,
|
||||||
|
Quit,
|
||||||
|
|
||||||
SentinelSentinels,
|
SentinelSentinels,
|
||||||
SentinelGetMaster,
|
SentinelGetMaster,
|
||||||
|
|||||||
@ -9,7 +9,8 @@
|
|||||||
Connection::Connection():
|
Connection::Connection():
|
||||||
mPostEvts(0),
|
mPostEvts(0),
|
||||||
mBufCnt(0),
|
mBufCnt(0),
|
||||||
mDb(0)
|
mDb(0),
|
||||||
|
mCloseASAP(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -29,6 +29,14 @@ public:
|
|||||||
};
|
};
|
||||||
public:
|
public:
|
||||||
Connection();
|
Connection();
|
||||||
|
void closeASAP()
|
||||||
|
{
|
||||||
|
mCloseASAP = true;
|
||||||
|
}
|
||||||
|
bool isCloseASAP() const
|
||||||
|
{
|
||||||
|
return mCloseASAP;
|
||||||
|
}
|
||||||
int getPostEvent() const
|
int getPostEvent() const
|
||||||
{
|
{
|
||||||
return mPostEvts;
|
return mPostEvts;
|
||||||
@ -56,6 +64,7 @@ private:
|
|||||||
BufferPtr mBuf;
|
BufferPtr mBuf;
|
||||||
int mBufCnt;
|
int mBufCnt;
|
||||||
int mDb;
|
int mDb;
|
||||||
|
bool mCloseASAP;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -166,11 +166,14 @@ void Handler::postAcceptConnectionEvent()
|
|||||||
bool ret;
|
bool ret;
|
||||||
if (finished) {
|
if (finished) {
|
||||||
ret = mEventLoop->delEvent(c, Multiplexor::WriteEvent);
|
ret = mEventLoop->delEvent(c, Multiplexor::WriteEvent);
|
||||||
|
if (c->isCloseASAP()) {
|
||||||
|
c->setStatus(AcceptConnection::None);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ret = mEventLoop->addEvent(c, Multiplexor::WriteEvent);
|
ret = mEventLoop->addEvent(c, Multiplexor::WriteEvent);
|
||||||
}
|
}
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
c->setStatus(Multiplexor::ErrorEvent);
|
c->setStatus(AcceptConnection::IOError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -460,7 +463,7 @@ void Handler::handleRequest(Request* req)
|
|||||||
{
|
{
|
||||||
FuncCallTimer();
|
FuncCallTimer();
|
||||||
auto c = req->connection();
|
auto c = req->connection();
|
||||||
if (c && c->isBlockRequest()) {
|
if (c && (c->isBlockRequest() || c->isCloseASAP())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
++mStats.requests;
|
++mStats.requests;
|
||||||
@ -550,6 +553,12 @@ bool Handler::preHandleRequest(Request* req, const String& key)
|
|||||||
directResponse(req, Response::InvalidDb);
|
directResponse(req, Response::InvalidDb);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
case Command::Quit:
|
||||||
|
directResponse(req, Response::Ok);
|
||||||
|
if (c) {
|
||||||
|
c->closeASAP();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
case Command::Cmd:
|
case Command::Cmd:
|
||||||
directResponse(req, Response::Cmd);
|
directResponse(req, Response::Cmd);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -469,6 +469,7 @@ void RequestParser::parseCmd()
|
|||||||
case Command::Echo:
|
case Command::Echo:
|
||||||
case Command::Auth:
|
case Command::Auth:
|
||||||
case Command::Select:
|
case Command::Select:
|
||||||
|
case Command::Quit:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
mStatus = CmdError;
|
mStatus = CmdError;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user