*NEXT/*DIE
This commit is contained in:
1 parent
48be555724
commit
9a39b6224c
14 files changed
+352
-209
No files matched your search
+26
-16
@@ -8,7 +8,8 @@ namespace core
|
||||
{
|
||||
|
||||
TCPServer::TCPServer(EPoll &ePoll, IPAddress address, std::string delimiter, int depth, std::string text)
|
||||
: TCPSocket(ePoll, text), commands(delimiter, depth) {
|
||||
: TCPSocket(ePoll, text), commands(delimiter, depth)
|
||||
{
|
||||
|
||||
commands.add(subscriptions, "publish");
|
||||
commands.add(subscriptions, "unpublish");
|
||||
@@ -35,7 +36,8 @@ namespace core
|
||||
close(getDescriptor());
|
||||
}
|
||||
|
||||
void TCPServer::onDataReceived(std::string data) {
|
||||
void TCPServer::onDataReceived(std::string data)
|
||||
{
|
||||
lock.lock();
|
||||
TCPSession *session = accept();
|
||||
if (session)
|
||||
@@ -43,9 +45,11 @@ namespace core
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
TCPSession * TCPServer::accept() {
|
||||
TCPSession *TCPServer::accept()
|
||||
{
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
|
||||
TCPSession *session = getSocketAccept(ePoll);
|
||||
session->setDescriptor(::accept(getDescriptor(), (struct sockaddr *)&session->ipAddress.addr, &session->ipAddress.addressLength));
|
||||
@@ -72,30 +76,36 @@ namespace core
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void TCPServer::removeFromSessionList(TCPSession *session) {
|
||||
void TCPServer::removeFromSessionList(TCPSession *session)
|
||||
{
|
||||
std::vector<TCPSession *>::iterator cursor;
|
||||
lock.lock();
|
||||
for(cursor = sessions.begin(); cursor < sessions.end(); ++cursor)
|
||||
if(*cursor == session) {
|
||||
sessions.erase(cursor);
|
||||
break;
|
||||
}
|
||||
for (cursor = sessions.begin(); cursor < sessions.end(); ++cursor)
|
||||
if (*cursor == session)
|
||||
{
|
||||
sessions.erase(cursor);
|
||||
break;
|
||||
}
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
void TCPServer::sessionErrorHandler(std::string errorString, std::stringstream &out) {
|
||||
void TCPServer::sessionErrorHandler(std::string errorString, std::stringstream &out)
|
||||
{
|
||||
throw coreutils::Exception(errorString);
|
||||
}
|
||||
|
||||
TCPSession * TCPServer::getSocketAccept(EPoll &ePoll) {
|
||||
TCPSession *TCPServer::getSocketAccept(EPoll &ePoll)
|
||||
{
|
||||
return new TCPSession(ePoll, *this);
|
||||
}
|
||||
|
||||
void TCPServer::output(std::stringstream &out) {
|
||||
void TCPServer::output(std::stringstream &out)
|
||||
{
|
||||
out << "Use the 'help' command to list the commands for this server." << std::endl;
|
||||
}
|
||||
|
||||
int TCPServer::processCommand(coreutils::ZString &request, TCPSession &session) {
|
||||
int TCPServer::processCommand(coreutils::ZString &request, TCPSession &session)
|
||||
{
|
||||
int sequence = 0;
|
||||
for (auto *sessionx : sessions)
|
||||
{
|
||||
@@ -130,11 +140,11 @@ namespace core
|
||||
data.str("");
|
||||
}
|
||||
|
||||
TCPSession *TCPServer::getSessionByAlias(void *alias)
|
||||
TCPSession *TCPServer::getSessionByAlias(coreutils::MString *alias)
|
||||
{
|
||||
coreutils::Log(coreutils::LOG_DEBUG_1) << alias;
|
||||
for (auto session : sessions)
|
||||
if (session->compareAlias(alias))
|
||||
if (session->compareAlias(*alias))
|
||||
return session;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user