summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-12-30 15:11:40 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-12-30 15:11:40 +0000
commit6fff3c54be91dbbfe5e3ffca4204ad0378d70b7d (patch)
tree7c10778fc957a26c2e9b00882459e163aa548f40 /src
parentfce2d243c023660a9afbf01143cde6eda2ec7a88 (diff)
Tons of optimization of WriteChannel, WriteChannelWithServ, WriteCommon etc, dont call userrec::GetFullHost or snprintf for every item, call it just once.
Turns O(n) calls for every write into O(~1) calls per write. Remove some debug from the socketengines which makes debugging hard on large channels (write availability message) git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6171 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/channels.cpp10
-rw-r--r--src/socketengine_epoll.cpp1
-rw-r--r--src/socketengine_kqueue.cpp1
-rw-r--r--src/socketengine_select.cpp1
-rw-r--r--src/users.cpp18
5 files changed, 22 insertions, 9 deletions
diff --git a/src/channels.cpp b/src/channels.cpp
index ea7edd71f..df1f77976 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -612,14 +612,17 @@ void chanrec::WriteChannel(userrec* user, char* text, ...)
void chanrec::WriteChannel(userrec* user, const std::string &text)
{
CUList *ulist = this->GetUsers();
+ char tb[MAXBUF];
if (!user)
return;
+ snprintf(tb,MAXBUF,":%s %s",user->GetFullHost(),text.c_str());
+
for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
{
if (IS_LOCAL(i->second))
- user->WriteTo(i->second,text);
+ i->second->Write(std::string(tb));
}
}
@@ -684,6 +687,7 @@ void chanrec::WriteAllExcept(userrec* user, bool serversource, char status, CULi
void chanrec::WriteAllExcept(userrec* user, bool serversource, char status, CUList &except_list, const std::string &text)
{
CUList *ulist;
+ char tb[MAXBUF];
switch (status)
{
@@ -701,6 +705,8 @@ void chanrec::WriteAllExcept(userrec* user, bool serversource, char status, CULi
break;
}
+ snprintf(tb,MAXBUF,":%s %s",user->GetFullHost(),text.c_str());
+
for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
{
if ((IS_LOCAL(i->second)) && (except_list.find(i->second) == except_list.end()))
@@ -708,7 +714,7 @@ void chanrec::WriteAllExcept(userrec* user, bool serversource, char status, CULi
if (serversource)
i->second->WriteServ(text);
else
- i->second->WriteFrom(user,text);
+ i->second->Write(std::string(tb));
}
}
}
diff --git a/src/socketengine_epoll.cpp b/src/socketengine_epoll.cpp
index 0be3b25c8..c36e964f8 100644
--- a/src/socketengine_epoll.cpp
+++ b/src/socketengine_epoll.cpp
@@ -129,7 +129,6 @@ int EPollEngine::DispatchEvents()
int i = epoll_wait(EngineHandle, events, MAX_DESCRIPTORS, 150);
for (int j = 0; j < i; j++)
{
- ServerInstance->Log(DEBUG,"Handle %s event on fd %d",events[j].events & EPOLLOUT ? "write" : "read", events[j].data.fd);
if (events[j].events & EPOLLHUP)
{
ServerInstance->Log(DEBUG,"Handle error event on fd %d", events[j].data.fd);
diff --git a/src/socketengine_kqueue.cpp b/src/socketengine_kqueue.cpp
index bbc36ea7f..ebc1fffbd 100644
--- a/src/socketengine_kqueue.cpp
+++ b/src/socketengine_kqueue.cpp
@@ -137,7 +137,6 @@ int KQueueEngine::DispatchEvents()
int i = kevent(EngineHandle, NULL, 0, &ke_list[0], MAX_DESCRIPTORS, &ts);
for (int j = 0; j < i; j++)
{
- ServerInstance->Log(DEBUG,"Handle %s event on fd %d",ke_list[j].flags & EVFILT_WRITE ? "write" : "read", ke_list[j].ident);
if (ke_list[j].flags & EV_EOF)
{
ServerInstance->Log(DEBUG,"kqueue: Error on FD %d", ke_list[j].ident);
diff --git a/src/socketengine_select.cpp b/src/socketengine_select.cpp
index f1960f09d..5be97eff6 100644
--- a/src/socketengine_select.cpp
+++ b/src/socketengine_select.cpp
@@ -146,7 +146,6 @@ int SelectEngine::DispatchEvents()
}
if (ev[i])
{
- ServerInstance->Log(DEBUG,"Handle %s event on fd %d",writeable[ev[i]->GetFd()] || !ev[i]->Readable() ? "write" : "read", ev[i]->GetFd());
if (writeable[ev[i]->GetFd()])
{
if (ev[i])
diff --git a/src/users.cpp b/src/users.cpp
index e4f63e3ba..e3c432caf 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -1560,11 +1560,15 @@ void userrec::WriteCommon(const std::string &text)
try
{
bool sent_to_at_least_one = false;
+ char tb[MAXBUF];
if (this->registered != REG_ALL)
return;
uniq_id++;
+
+ /* We dont want to be doing this n times, just once */
+ snprintf(tb,MAXBUF,":%s %s",this->GetFullHost(),text.c_str());
for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
{
@@ -1574,7 +1578,7 @@ void userrec::WriteCommon(const std::string &text)
if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id))
{
already_sent[i->second->fd] = uniq_id;
- i->second->WriteFrom(this, std::string(text));
+ i->second->Write(std::string(tb));
sent_to_at_least_one = true;
}
}
@@ -1586,7 +1590,7 @@ void userrec::WriteCommon(const std::string &text)
*/
if (!sent_to_at_least_one)
{
- this->WriteFrom(this,std::string(text));
+ this->WriteFrom(this,std::string(tb));
}
}
@@ -1618,6 +1622,8 @@ void userrec::WriteCommonExcept(const std::string &text)
bool quit_munge = false;
char oper_quit[MAXBUF];
char textbuffer[MAXBUF];
+ char tb1[MAXBUF];
+ char tb2[MAXBUF];
strlcpy(textbuffer, text.c_str(), MAXBUF);
@@ -1626,6 +1632,8 @@ void userrec::WriteCommonExcept(const std::string &text)
uniq_id++;
+ snprintf(tb1,MAXBUF,":%s %s",this->GetFullHost(),textbuffer);
+
/* TODO: We need some form of WriteCommonExcept that will send two lines, one line to
* opers and the other line to non-opers, then all this hidebans and hidesplits gunk
* can go byebye.
@@ -1648,6 +1656,7 @@ void userrec::WriteCommonExcept(const std::string &text)
strlcpy(oper_quit,textbuffer,MAXQUIT);
strlcpy(check,"*.net *.split",MAXQUIT);
quit_munge = true;
+ snprintf(tb2,MAXBUF,":%s %s",this->GetFullHost(),oper_quit);
}
}
}
@@ -1661,6 +1670,7 @@ void userrec::WriteCommonExcept(const std::string &text)
strlcpy(oper_quit,textbuffer,MAXQUIT);
*check = 0; // We don't need to strlcpy, we just chop it from the :
quit_munge = true;
+ snprintf(tb2,MAXBUF,":%s %s",this->GetFullHost(),oper_quit);
}
}
@@ -1675,9 +1685,9 @@ void userrec::WriteCommonExcept(const std::string &text)
{
already_sent[i->second->fd] = uniq_id;
if (quit_munge)
- i->second->WriteFrom(this, *i->second->oper ? std::string(oper_quit) : std::string(textbuffer));
+ i->second->Write(*i->second->oper ? std::string(tb2) : std::string(tb1));
else
- i->second->WriteFrom(this, std::string(textbuffer));
+ i->second->Write(std::string(tb1));
}
}
}