summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-04-22 23:52:35 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-04-22 23:52:35 +0000
commit3e87dae328c282016472f02fa5cc0431a922bcdc (patch)
treeae854861596e9f8634598afa02efdf0c7a7d5f3f
parent4fff701800cfb3f5a27d7889561dceba18e29239 (diff)
Added server input buffers (for systems that decide buffering is fun)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@1165 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/connection.h9
-rw-r--r--src/connection.cpp83
2 files changed, 52 insertions, 40 deletions
diff --git a/include/connection.h b/include/connection.h
index ed88d83f7..65b6deed3 100644
--- a/include/connection.h
+++ b/include/connection.h
@@ -78,6 +78,10 @@ class ircd_connector : public Extensible
*/
bool SetHostAddress(char* host, int port);
+ /** IRCD Buffer for input characters, holds one line
+ */
+ std::string ircdbuffer;
+
public:
/** When MakeOutboundConnection is called, these public members are
@@ -158,6 +162,11 @@ class ircd_connector : public Extensible
* This function call updates no other data.
*/
void CloseConnection();
+
+ void AddBuffer(char a);
+ bool BufferIsComplete();
+ void ClearBuffer();
+ std::string GetBuffer();
};
diff --git a/src/connection.cpp b/src/connection.cpp
index f6b2cea96..e6a2dc1d0 100644
--- a/src/connection.cpp
+++ b/src/connection.cpp
@@ -136,9 +136,42 @@ void ircd_connector::SetServerPort(int p)
this->port = p;
}
+void ircd_connector::AddBuffer(char a)
+{
+ if (a != '\r')
+ ircdbuffer = ircdbuffer + a;
+}
+
+bool ircd_connector::BufferIsComplete()
+{
+ if (ircdbuffer.length())
+ {
+ return (ircdbuffer[ircdbuffer.length()-1] == '\n');
+ }
+ return false;
+}
+
+void ircd_connector::ClearBuffer()
+{
+ ircdbuffer = "";
+}
+
+std::string ircd_connector::GetBuffer()
+{
+ if (ircdbuffer.length() < 510)
+ {
+ return ircdbuffer;
+ }
+ else
+ {
+ return ircdbuffer.substr(510);
+ }
+}
+
bool ircd_connector::MakeOutboundConnection(char* host, int port)
{
log(DEBUG,"MakeOutboundConnection: Original param: %s",host);
+ ClearBuffer();
hostent* hoste = gethostbyname(host);
if (!hoste)
{
@@ -415,15 +448,15 @@ bool connection::SendPacket(char *message, const char* host)
bool connection::RecvPacket(std::deque<std::string> &messages, char* host)
{
- char data[32767];
- memset(data, 0, 32767);
+ char data[4096];
+ memset(data, 0, 4096);
for (int i = 0; i < this->connectors.size(); i++)
{
if (this->connectors[i].GetState() != STATE_DISCONNECTED)
{
// returns false if the packet could not be sent (e.g. target host down)
int rcvsize = 0;
- rcvsize = recv(this->connectors[i].GetDescriptor(),data,32767,0);
+ rcvsize = recv(this->connectors[i].GetDescriptor(),data,1,0);
if (rcvsize == -1)
{
if (errno != EAGAIN)
@@ -436,45 +469,15 @@ bool connection::RecvPacket(std::deque<std::string> &messages, char* host)
}
if (rcvsize > 0)
{
- if ((data[rcvsize-1] != '\r') && (data[rcvsize-1] != '\n'))
- {
- char foo = ' ';
- while ((foo != '\n') && (rcvsize < 32767))
- {
- int x = recv(this->connectors[i].GetDescriptor(),(void*)&foo,1,0);
- if ((x == -1) && (errno != EAGAIN))
- break;
- if ((x) && (rcvsize < 32767))
- {
- data[rcvsize] = foo;
- data[++rcvsize] = '\0';
- }
- }
- }
- char* l = strtok(data,"\n");
- while (l)
+ this->connectors[i].AddBuffer(data[0]);
+ if (this->connectors[i].BufferIsComplete())
{
- char sanitized[32767];
- memset(sanitized, 0, 32767);
- int ptt = 0;
- for (int pt = 0; pt < strlen(l); pt++)
- {
- if (l[pt] != '\r')
- {
- sanitized[ptt++] = l[pt];
- }
- }
- sanitized[ptt] = '\0';
- if (strlen(sanitized))
- {
- messages.push_back(sanitized);
- strlcpy(host,this->connectors[i].GetServerName().c_str(),160);
- log(DEBUG,"main: Connection::RecvPacket() got '%s' from %s",sanitized,host);
-
- }
- l = strtok(NULL,"\n");
+ messages.push_back(this->connectors[i].GetBuffer().c_str());
+ strlcpy(host,this->connectors[i].GetServerName().c_str(),160);
+ log(DEBUG,"main: Connection::RecvPacket() got '%s' from %s",this->connectors[i].GetBuffer().c_str(),host);
+ this->connectors[i].ClearBuffer();
+ return true;
}
- return true;
}
}
}