fixed a Sttp::sendCmd()'s bug of calling itself recursively in Sttp.cpp
This commit is contained in:
parent
e53dbef46a
commit
6d03ba8ef2
@ -685,7 +685,7 @@ int Sttp::sendCmd (const qse_mchar_t* name, qse_size_t nargs, ...)
|
|||||||
int n;
|
int n;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start (ap, nargs);
|
va_start (ap, nargs);
|
||||||
n = this->sendCmd(name, nargs, ap);
|
n = this->sendCmdV(name, nargs, ap);
|
||||||
va_end (ap);
|
va_end (ap);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
@ -695,7 +695,7 @@ int Sttp::sendCmd (const qse_wchar_t* name, qse_size_t nargs, ...)
|
|||||||
int n;
|
int n;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start (ap, nargs);
|
va_start (ap, nargs);
|
||||||
n = this->sendCmd(name, nargs, ap);
|
n = this->sendCmdV(name, nargs, ap);
|
||||||
va_end (ap);
|
va_end (ap);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
@ -705,7 +705,7 @@ int Sttp::sendCmdL (const qse_mchar_t* name, qse_size_t nargs, ...)
|
|||||||
int n;
|
int n;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start (ap, nargs);
|
va_start (ap, nargs);
|
||||||
n = this->sendCmdL(name, nargs, ap);
|
n = this->sendCmdLV(name, nargs, ap);
|
||||||
va_end (ap);
|
va_end (ap);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
@ -715,7 +715,7 @@ int Sttp::sendCmdL (const qse_wchar_t* name, qse_size_t nargs, ...)
|
|||||||
int n;
|
int n;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start (ap, nargs);
|
va_start (ap, nargs);
|
||||||
n = this->sendCmdL(name, nargs, ap);
|
n = this->sendCmdLV(name, nargs, ap);
|
||||||
va_end (ap);
|
va_end (ap);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,33 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
class Proto: public QSE::Sttp
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Proto (QSE::Socket* sck): sck(sck) {}
|
||||||
|
|
||||||
|
int handle_command (const QSE::SttpCmd& cmd)
|
||||||
|
{
|
||||||
|
qse_printf (QSE_T("command -> %js\n"), cmd.name.getData());
|
||||||
|
int n = this->sendCmd(QSE_T("OK"), 1, cmd.name.getData());
|
||||||
|
if (cmd.name == QSE_T("quit"))
|
||||||
|
{
|
||||||
|
sck->shutdown ();
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
int write_bytes (const qse_uint8_t* data, qse_size_t len)
|
||||||
|
{
|
||||||
|
int n = this->sck->sendx(data, len, QSE_NULL);
|
||||||
|
if (QSE_UNLIKELY(n <= -1)) this->setErrorFmt(E_ESYSERR, QSE_T("%js"), sck->getErrorMsg());
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QSE::Socket* sck;
|
||||||
|
};
|
||||||
|
|
||||||
#if defined(QSE_LANG_CPP11)
|
#if defined(QSE_LANG_CPP11)
|
||||||
QSE::TcpServerL<int(QSE::TcpServer::Connection*)>* g_server;
|
QSE::TcpServerL<int(QSE::TcpServer::Connection*)>* g_server;
|
||||||
#else
|
#else
|
||||||
@ -33,22 +60,22 @@ public:
|
|||||||
connection->address.toStrBuf(addrbuf, QSE_COUNTOF(addrbuf));
|
connection->address.toStrBuf(addrbuf, QSE_COUNTOF(addrbuf));
|
||||||
qse_printf (QSE_T("hello word..from %s[%zu]\n"), addrbuf, connection->getWid());
|
qse_printf (QSE_T("hello word..from %s[%zu]\n"), addrbuf, connection->getWid());
|
||||||
|
|
||||||
QSE::Sttp sttp (&connection->socket);
|
Proto proto (&connection->socket);
|
||||||
QSE::SttpCmd cmd;
|
|
||||||
while (!server->isHaltRequested())
|
while (!server->isHaltRequested())
|
||||||
{
|
{
|
||||||
int n = sttp.receiveCmd(&cmd);
|
if ((n = connection->socket.receive(bb, QSE_COUNTOF(bb))) <= 0)
|
||||||
if (n <= -1)
|
|
||||||
{
|
{
|
||||||
qse_printf (QSE_T("%s[%zu] -> got error\n"), addrbuf, connection->getWid());
|
if (n <= -1)
|
||||||
|
qse_printf (QSE_T("%s[%zu] -> got error\n"), addrbuf, connection->getWid());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (n == 0) break;
|
|
||||||
|
|
||||||
if (cmd.name == QSE_T("quit")) break;
|
if (proto.feed(bb, n, QSE_NULL) <= -1)
|
||||||
|
{
|
||||||
qse_printf (QSE_T("received command %s\n"), cmd.name.getBuffer());
|
qse_printf (QSE_T("%s[%zu] -> protocol error - %js\n"), addrbuf, connection->getWid(), proto.getErrorMsg());
|
||||||
sttp.sendCmd(cmd);
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qse_printf (QSE_T("byte to %s -> wid %zu\n"), addrbuf, connection->getWid());
|
qse_printf (QSE_T("byte to %s -> wid %zu\n"), addrbuf, connection->getWid());
|
||||||
@ -76,22 +103,22 @@ static int test1 (void)
|
|||||||
connection->address.toStrBuf(addrbuf, QSE_COUNTOF(addrbuf));
|
connection->address.toStrBuf(addrbuf, QSE_COUNTOF(addrbuf));
|
||||||
qse_printf (QSE_T("hello word..from %s --> wid %zu\n"), addrbuf, connection->getWid());
|
qse_printf (QSE_T("hello word..from %s --> wid %zu\n"), addrbuf, connection->getWid());
|
||||||
|
|
||||||
QSE::Sttp sttp (&connection->socket);
|
Proto proto (&connection->socket);
|
||||||
QSE::SttpCmd cmd;
|
|
||||||
while (!server.isStopRequested())
|
while (!server.isHaltRequested())
|
||||||
{
|
{
|
||||||
int n = sttp.receiveCmd(&cmd);
|
if ((n = connection->socket.receive(bb, QSE_COUNTOF(bb))) <= 0)
|
||||||
if (n <= -1)
|
|
||||||
{
|
{
|
||||||
qse_printf (QSE_T("%s<%zu> --> got error\n"), addrbuf, connection->getWid());
|
if (n <= -1)
|
||||||
|
qse_printf (QSE_T("%s[%zu] -> got error\n"), addrbuf, connection->getWid());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (n == 0) break;
|
|
||||||
|
|
||||||
if (cmd.name == QSE_T("quit")) break;
|
if (proto.feed(bb, n, QSE_NULL) <= -1)
|
||||||
|
{
|
||||||
qse_printf (QSE_T("%s<%zu> --> received command %s\n"), addrbuf, connection->getWid(), cmd.name.getBuffer());
|
qse_printf (QSE_T("%s[%zu] -> protocol error - %js\n"), addrbuf, connection->getWid(), proto.getErrorMsg());
|
||||||
sttp.sendCmd(cmd);
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qse_printf (QSE_T("byte to %s -> wid %zu\n"), addrbuf, connection->getWid());
|
qse_printf (QSE_T("byte to %s -> wid %zu\n"), addrbuf, connection->getWid());
|
||||||
|
Loading…
Reference in New Issue
Block a user