diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-04-23 22:24:27 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-04-23 22:24:27 +0000 |
commit | a7ca75838a1e40fee7aa4b4434402c36a0a403ed (patch) | |
tree | 0f1aa1c45dc176043169254bb79814f34ccb6d6c | |
parent | 6dc6b84b60af9bb5ef8eddb7c38626ffee95fb2e (diff) |
Services speedups for stupid buffered i/o uplinks
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@1175 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | include/connection.h | 2 | ||||
-rw-r--r-- | src/connection.cpp | 39 |
2 files changed, 24 insertions, 17 deletions
diff --git a/include/connection.h b/include/connection.h index 65b6deed3..444d82d23 100644 --- a/include/connection.h +++ b/include/connection.h @@ -163,7 +163,7 @@ class ircd_connector : public Extensible */ void CloseConnection(); - void AddBuffer(char a); + void AddBuffer(std::string a); bool BufferIsComplete(); void ClearBuffer(); std::string GetBuffer(); diff --git a/src/connection.cpp b/src/connection.cpp index e6a2dc1d0..b7f99fb75 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -17,6 +17,7 @@ #include <connection.h> #include <unistd.h> #include <fcntl.h> +#include <poll.h> #include <sys/errno.h> #include <sys/ioctl.h> #include <sys/utsname.h> @@ -136,36 +137,41 @@ void ircd_connector::SetServerPort(int p) this->port = p; } -void ircd_connector::AddBuffer(char a) +void ircd_connector::AddBuffer(std::string a) { - if (a != '\r') - ircdbuffer = ircdbuffer + a; + for (int i = 0; i < a.length(); i++) + if (a[i] != '\r') + ircdbuffer = ircdbuffer + a[i]; } bool ircd_connector::BufferIsComplete() { - if (ircdbuffer.length()) - { - return (ircdbuffer[ircdbuffer.length()-1] == '\n'); - } + for (int i = 0; i < ircdbuffer.length(); i++) + if (ircdbuffer[i] == '\n') + return true; return false; } void ircd_connector::ClearBuffer() { - ircdbuffer = ""; + while ((ircdbuffer != "") && (ircdbuffer[0] != '\n')) + { + ircdbuffer.erase(ircdbuffer.begin()); + } + if (ircdbuffer != "") + ircdbuffer.erase(ircdbuffer.begin()); } std::string ircd_connector::GetBuffer() { - if (ircdbuffer.length() < 510) - { - return ircdbuffer; - } - else + std::string z = ""; + long t = 0; + while (ircdbuffer[t] != '\n') { - return ircdbuffer.substr(510); + z = z + ircdbuffer[t]; + t++; } + return z; } bool ircd_connector::MakeOutboundConnection(char* host, int port) @@ -456,7 +462,8 @@ bool connection::RecvPacket(std::deque<std::string> &messages, char* host) { // returns false if the packet could not be sent (e.g. target host down) int rcvsize = 0; - rcvsize = recv(this->connectors[i].GetDescriptor(),data,1,0); + rcvsize = recv(this->connectors[i].GetDescriptor(),data,32,0); + data[rcvsize] == '\0'; if (rcvsize == -1) { if (errno != EAGAIN) @@ -469,7 +476,7 @@ bool connection::RecvPacket(std::deque<std::string> &messages, char* host) } if (rcvsize > 0) { - this->connectors[i].AddBuffer(data[0]); + this->connectors[i].AddBuffer(data); if (this->connectors[i].BufferIsComplete()) { messages.push_back(this->connectors[i].GetBuffer().c_str()); |