Many changes
This commit is contained in:
1 parent
50bbfcc3c3
commit
46f98dff69
11 files changed
+110
-100
No files matched your search
+19
-12
@@ -6,8 +6,9 @@
|
||||
|
||||
namespace core {
|
||||
|
||||
TCPServer::TCPServer(EPoll &ePoll, IPAddress address, std::string text)
|
||||
: TCPSocket(ePoll, text) {
|
||||
TCPServer::TCPServer(EPoll &ePoll, IPAddress address, std::string delimiter, std::string text)
|
||||
: TCPSocket(ePoll, text), commands(delimiter) {
|
||||
|
||||
setDescriptor(socket(AF_INET, SOCK_STREAM, 0));
|
||||
int yes = 1;
|
||||
setsockopt(getDescriptor(), SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));
|
||||
@@ -68,27 +69,33 @@ namespace core {
|
||||
session->send();
|
||||
}
|
||||
|
||||
int TCPServer::processCommand(coreutils::ZString command, TCPSession *session, std::stringstream &data) {
|
||||
int TCPServer::processCommand(coreutils::ZString &request, TCPSession &session) {
|
||||
int sequence = 0;
|
||||
for(auto *sessionx : sessions) {
|
||||
data << "|" << ++sequence;
|
||||
sessionx->output(data);
|
||||
data << "|" << std::endl;
|
||||
session.out << "|" << ++sequence;
|
||||
sessionx->output(session.out);
|
||||
session.out << "|" << std::endl;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void TCPServer::sendToAll(std::stringstream &data, TCPSession *sender) {
|
||||
|
||||
void TCPServer::sendToAll(std::stringstream &data) {
|
||||
for(auto session : sessions)
|
||||
if(session != sender)
|
||||
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) {
|
||||
|
||||
void TCPServer::sendToAll(std::stringstream &data, TCPSession &sender, SessionFilter filter) {
|
||||
for(auto session : sessions)
|
||||
if(filter.test(*session))
|
||||
if(session != sender)
|
||||
if(session != &sender)
|
||||
session->write(data.str());
|
||||
data.str("");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user