Backport r9247: server buffering improvements (don't constantly flush write buffer) QA: this needs testing of server linking and SSL, and SSL server linking

git-svn-id: http://svn.inspircd.org/repository/branches/1_1_stable@9248 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
w00t 2008-04-01 19:38:11 +00:00
parent c2f63c607d
commit fda193662c
6 changed files with 30 additions and 18 deletions

View File

@ -339,7 +339,7 @@ class CoreExport InspSocket : public EventHandler
* returns or linefeeds are appended to the string.
* @param data The data to send
*/
virtual int Write(const std::string &data);
virtual void Write(const std::string &data);
/**
* If your socket is a listening socket, when a new

View File

@ -439,17 +439,24 @@ void InspSocket::MarkAsClosed()
{
}
// There are two possible outcomes to this function.
// It will either write all of the data, or an undefined amount.
// If an undefined amount is written the connection has failed
// and should be aborted.
int InspSocket::Write(const std::string &data)
/*
* This function formerly tried to flush write buffer each call.
* While admirable in attempting to get the data out to wherever
* it is going, on a full socket, it's just going to syscall write() and
* EAGAIN constantly, instead of waiting in the SE to know if it can write
* which will chew a bit of CPU.
*
* So, now this function returns void (take note) and just adds to the sendq.
*
* It'll get written at a determinate point when the socketengine tells us it can write.
* -- w00t (april 1, 2008)
*/
void InspSocket::Write(const std::string &data)
{
/* Try and append the data to the back of the queue, and send it on its way
*/
outbuffer.push_back(data);
this->Instance->SE->WantWrite(this);
return (!this->FlushWriteBuffer());
}
bool InspSocket::FlushWriteBuffer()

View File

@ -276,7 +276,9 @@ bool HTTPSocket::OnConnected()
this->status = HTTP_REQSENT;
return this->Write(request);
this->Write(request);
return true;
}
bool HTTPSocket::OnDataReady()

View File

@ -267,7 +267,7 @@ class TreeSocket : public InspSocket
/** Send one or more complete lines down the socket
*/
int WriteLine(std::string line);
void WriteLine(std::string line);
/** Handle ERROR command */
bool Error(std::deque<std::string> &params);

View File

@ -1032,7 +1032,6 @@ bool TreeSocket::IntroduceClient(const std::string &source, std::deque<std::stri
*/
void TreeSocket::SendFJoins(TreeServer* Current, chanrec* c)
{
std::string buffer;
char list[MAXBUF];
std::string individual_halfops = std::string(":")+this->Instance->Config->ServerName+" FMODE "+c->name+" "+ConvToStr(c->age);
@ -1057,7 +1056,7 @@ void TreeSocket::SendFJoins(TreeServer* Current, chanrec* c)
if (curlen > (480-NICKMAX))
{
buffer.append(list).append("\r\n");
this->WriteLine(list);
dlen = curlen = snprintf(list,MAXBUF,":%s FJOIN %s %lu",this->Instance->Config->ServerName,c->name,(unsigned long)c->age);
ptr = list + dlen;
ptrlen = 0;
@ -1066,9 +1065,10 @@ void TreeSocket::SendFJoins(TreeServer* Current, chanrec* c)
}
if (numusers)
buffer.append(list).append("\r\n");
this->WriteLine(list);
buffer.append(":").append(this->Instance->Config->ServerName).append(" FMODE ").append(c->name).append(" ").append(ConvToStr(c->age)).append(" +").append(c->ChanModes(true)).append("\r\n");
snprintf(list, MAXBUF, ":%s FMODE %s %lu +%s", this->Instance->Config->ServerName, c->name, (unsigned long)c->age, c->ChanModes(true));
this->WriteLine(list);
int linesize = 1;
for (BanList::iterator b = c->bans.begin(); b != c->bans.end(); b++)
@ -1084,7 +1084,8 @@ void TreeSocket::SendFJoins(TreeServer* Current, chanrec* c)
if ((params.length() >= MAXMODES) || (currsize > 350))
{
/* Wrap at MAXMODES */
buffer.append(":").append(this->Instance->Config->ServerName).append(" FMODE ").append(c->name).append(" ").append(ConvToStr(c->age)).append(" +").append(modes).append(params).append("\r\n");
snprintf(list, MAXBUF, ":%s FMODE %s %lu +%s%s", this->Instance->Config->ServerName, c->name, (unsigned long)c->age, modes.c_str(), params.c_str());
this->WriteLine(list);
modes.clear();
params.clear();
linesize = 1;
@ -1093,9 +1094,11 @@ void TreeSocket::SendFJoins(TreeServer* Current, chanrec* c)
/* Only send these if there are any */
if (!modes.empty())
buffer.append(":").append(this->Instance->Config->ServerName).append(" FMODE ").append(c->name).append(" ").append(ConvToStr(c->age)).append(" +").append(modes).append(params);
{
snprintf(list, MAXBUF, ":%s FMODE %s %lu +%s%s", this->Instance->Config->ServerName, c->name, (unsigned long)c->age, modes.c_str(), params.c_str());
this->WriteLine(list);
this->WriteLine(buffer);
}
}
/** Send G, Q, Z and E lines */

View File

@ -36,11 +36,11 @@
static std::map<std::string, std::string> warned; /* Server names that have had protocol violation warnings displayed for them */
int TreeSocket::WriteLine(std::string line)
void TreeSocket::WriteLine(std::string line)
{
Instance->Log(DEBUG, "S[%d] -> %s", this->GetFd(), line.c_str());
line.append("\r\n");
return this->Write(line);
this->Write(line);
}