Major changes to socket scheduling in EPoll.

This commit is contained in:
barant committed 2020-02-29 19:27:58 -08:00
1 parent 790906a6dc
commit a5a51f8aae
512 files changed
+22663 -2121

No files matched your search

+9 -5
View File
@@ -6,17 +6,19 @@
namespace core {
TCPServer::TCPServer(EPoll &ePoll, IPAddress address) : TCPSocket(ePoll) {
TCPServer::TCPServer(EPoll &ePoll, IPAddress address, std::string text)
: TCPSocket(ePoll, text) {
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));
if(listen(getDescriptor(), 10) < 0)
if(listen(getDescriptor(), 20) < 0)
throw coreutils::Exception("Error on listen to socket");
}
TCPServer::~TCPServer() {
coreutils::Log(coreutils::LOG_DEBUG_2) << "Closing server socket " << getDescriptor() << ".";
close(getDescriptor());
}
@@ -52,7 +54,7 @@ namespace core {
sessions.erase(cursor);
}
void TCPServer::sessionErrorHandler(std::string errorString) {
void TCPServer::sessionErrorHandler(std::string errorString, std::stringstream &out) {
throw coreutils::Exception(errorString);
}
@@ -61,7 +63,9 @@ namespace core {
}
void TCPServer::output(TCPSession *session) {
session->out << "|" << session->ipAddress.getClientAddressAndPort();
std::stringstream out;
out << "|" << session->ipAddress.getClientAddressAndPort();
session->send(out.str());
}
int TCPServer::processCommand(std::string command, TCPSession *session, std::stringstream &data) {