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 /src | |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/connection.cpp | 39 |
1 files changed, 23 insertions, 16 deletions
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()); |