mirror of
https://github.com/inspircd/inspircd.git
synced 2025-03-10 02:59:01 -04:00
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
This commit is contained in:
parent
4fff701800
commit
3e87dae328
@ -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();
|
||||
};
|
||||
|
||||
|
||||
|
@ -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'))
|
||||
this->connectors[i].AddBuffer(data[0]);
|
||||
if (this->connectors[i].BufferIsComplete())
|
||||
{
|
||||
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';
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
char* l = strtok(data,"\n");
|
||||
while (l)
|
||||
{
|
||||
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");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user