Wierd reason after pull of new branch.
This commit is contained in:
commit
48e2c27c3c
585 files changed
+5665
-25219
No files matched your search
+89
-19
@@ -1,11 +1,13 @@
|
||||
#include "TCPServer.h"
|
||||
#include "EPoll.h"
|
||||
#include "TCPSession.h"
|
||||
#include "Exception.h"
|
||||
#include "Log.h"
|
||||
#include "TCPSession.h"
|
||||
|
||||
namespace core {
|
||||
namespace core
|
||||
{
|
||||
|
||||
<<<<<<< HEAD
|
||||
TCPServer::TCPServer(EPoll &ePoll,
|
||||
IPAddress address,
|
||||
std::string delimiter,
|
||||
@@ -30,10 +32,32 @@ namespace core {
|
||||
|
||||
if(listen(getDescriptor(), 20) < 0)
|
||||
throw coreutils::Exception("Error on listen to socket");
|
||||
=======
|
||||
TCPServer::TCPServer(EPoll &ePoll, IPAddress address, std::string delimiter, int depth, std::string text)
|
||||
: TCPSocket(ePoll, text), commands(delimiter, depth) {
|
||||
|
||||
commands.add(subscriptions, "publish");
|
||||
commands.add(subscriptions, "unpublish");
|
||||
commands.add(subscriptions, "subscribe");
|
||||
commands.add(subscriptions, "unsubscribe");
|
||||
commands.add(subscriptions, "catalog");
|
||||
commands.add(subscriptions, "event");
|
||||
commands.add(subscriptions, "invite");
|
||||
|
||||
setDescriptor(socket(AF_INET, SOCK_STREAM, 0));
|
||||
int yes = 1;
|
||||
setsockopt(getDescriptor(), SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));
|
||||
|
||||
if (bind(getDescriptor(), address.getPointer(), address.addressLength) < 0)
|
||||
throw coreutils::Exception("Error on bind to socket: " + std::to_string(errno));
|
||||
>>>>>>> 519faa535b82c6b3f982f2ab1c42d252e62fa7f6
|
||||
|
||||
if (listen(getDescriptor(), 20) < 0)
|
||||
throw coreutils::Exception("Error on listen to socket");
|
||||
}
|
||||
|
||||
TCPServer::~TCPServer() {
|
||||
TCPServer::~TCPServer()
|
||||
{
|
||||
coreutils::Log(coreutils::LOG_DEBUG_2) << "Closing server socket " << getDescriptor() << ".";
|
||||
close(getDescriptor());
|
||||
}
|
||||
@@ -41,8 +65,8 @@ namespace core {
|
||||
void TCPServer::onDataReceived(std::string data) {
|
||||
lock.lock();
|
||||
TCPSession *session = accept();
|
||||
if(session)
|
||||
sessions.push_back(session);
|
||||
if (session)
|
||||
sessions.push_back(session);
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
@@ -52,22 +76,24 @@ namespace core {
|
||||
|
||||
TCPSession *session = getSocketAccept(ePoll);
|
||||
session->setDescriptor(::accept(getDescriptor(), (struct sockaddr *)&session->ipAddress.addr, &session->ipAddress.addressLength));
|
||||
// if(blackList && blackList->contains(session->ipAddress.getClientAddress())) {
|
||||
// session->shutdown();
|
||||
// Log(LOG_WARN) << "Client at IP address " << session->ipAddress.getClientAddress() << " is blacklisted and was denied a connection.";
|
||||
// return NULL;
|
||||
// }
|
||||
// if(whiteList && !whiteList->contains(session->ipAddress.getClientAddress())) {
|
||||
// session->shutdown();
|
||||
// Log(LOG_WARN) << "Client at IP address " << session->ipAddress.getClientAddress() << " is not authorized and was denied a connection.";
|
||||
// return NULL;
|
||||
// }
|
||||
// if(blackList && blackList->contains(session->ipAddress.getClientAddress())) {
|
||||
// session->shutdown();
|
||||
// Log(LOG_WARN) << "Client at IP address " << session->ipAddress.getClientAddress() << " is blacklisted and was denied a connection.";
|
||||
// return NULL;
|
||||
// }
|
||||
// if(whiteList && !whiteList->contains(session->ipAddress.getClientAddress())) {
|
||||
// session->shutdown();
|
||||
// Log(LOG_WARN) << "Client at IP address " << session->ipAddress.getClientAddress() << " is not authorized and was denied a connection.";
|
||||
// return NULL;
|
||||
// }
|
||||
return session;
|
||||
}
|
||||
catch(coreutils::Exception e) {
|
||||
catch (coreutils::Exception e)
|
||||
{
|
||||
coreutils::Log(coreutils::LOG_EXCEPT) << "Major error on session initialization. Error is '" << e.text << "'.";
|
||||
}
|
||||
catch(...) {
|
||||
catch (...)
|
||||
{
|
||||
coreutils::Log(coreutils::LOG_EXCEPT) << "Unnspecified error on session initialization.";
|
||||
}
|
||||
return NULL;
|
||||
@@ -75,13 +101,20 @@ namespace core {
|
||||
|
||||
void TCPServer::removeFromSessionList(TCPSession *session) {
|
||||
std::vector<TCPSession *>::iterator cursor;
|
||||
lock.lock();
|
||||
lock.lock();
|
||||
for(cursor = sessions.begin(); cursor < sessions.end(); ++cursor)
|
||||
if(*cursor == session) {
|
||||
<<<<<<< HEAD
|
||||
sessions.erase(cursor);
|
||||
break;
|
||||
}
|
||||
lock.unlock();
|
||||
=======
|
||||
sessions.erase(cursor);
|
||||
break;
|
||||
}
|
||||
lock.unlock();
|
||||
>>>>>>> 519faa535b82c6b3f982f2ab1c42d252e62fa7f6
|
||||
}
|
||||
|
||||
void TCPServer::sessionErrorHandler(std::string errorString, std::stringstream &out) {
|
||||
@@ -98,7 +131,8 @@ namespace core {
|
||||
|
||||
int TCPServer::processCommand(coreutils::ZString &request, TCPSession &session) {
|
||||
int sequence = 0;
|
||||
for(auto *sessionx : sessions) {
|
||||
for (auto *sessionx : sessions)
|
||||
{
|
||||
session.out << "|" << ++sequence;
|
||||
sessionx->output(session.out);
|
||||
session.out << "|" << std::endl;
|
||||
@@ -106,6 +140,7 @@ namespace core {
|
||||
return 1;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
void TCPServer::sendToAll(std::stringstream &data) {
|
||||
for(auto session : sessions)
|
||||
session->write(data.str());
|
||||
@@ -127,4 +162,39 @@ namespace core {
|
||||
data.str("");
|
||||
}
|
||||
|
||||
=======
|
||||
void TCPServer::sendToAll(std::stringstream &data)
|
||||
{
|
||||
for (auto session : sessions)
|
||||
session->write(data.str());
|
||||
data.str("");
|
||||
}
|
||||
|
||||
void TCPServer::sendToAll(std::stringstream &data, TCPSession &sender)
|
||||
{
|
||||
for (auto session : sessions)
|
||||
if (session != &sender)
|
||||
session->write(data.str());
|
||||
data.str("");
|
||||
}
|
||||
|
||||
void TCPServer::sendToAll(std::stringstream &data, TCPSession &sender, SessionFilter filter)
|
||||
{
|
||||
for (auto session : sessions)
|
||||
if (filter.test(*session))
|
||||
if (session != &sender)
|
||||
session->write(data.str());
|
||||
data.str("");
|
||||
}
|
||||
|
||||
TCPSession *TCPServer::getSessionByAlias(void *alias)
|
||||
{
|
||||
coreutils::Log(coreutils::LOG_DEBUG_1) << alias;
|
||||
for (auto session : sessions)
|
||||
if (session->compareAlias(alias))
|
||||
return session;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
>>>>>>> 519faa535b82c6b3f982f2ab1c42d252e62fa7f6
|
||||
}
|
||||
Reference in new issue
Block a user