summaryrefslogtreecommitdiff
path: root/src/connection.cpp
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-05-23 17:52:46 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-05-23 17:52:46 +0000
commit45b07a069108d661f7d3b63b040e4db5166a2dd8 (patch)
treea7905796cc4d41f5b10fe735232bed1d8ea55828 /src/connection.cpp
parentb8e97ead2880337ea270ed36b785b6103c46a5c2 (diff)
Output buffering on server connections
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@1475 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/connection.cpp')
-rw-r--r--src/connection.cpp68
1 files changed, 63 insertions, 5 deletions
diff --git a/src/connection.cpp b/src/connection.cpp
index 222251bb4..7d5df66f9 100644
--- a/src/connection.cpp
+++ b/src/connection.cpp
@@ -72,10 +72,18 @@ std::string CreateSum()
connection::connection()
{
- fd = 0;
+ fd = -1;
}
+ircd_connector::ircd_connector()
+{
+ fd = -1;
+ port = 0;
+ sendq = "";
+ WriteError = "";
+}
+
char* ircd_connector::GetServerIP()
{
return this->host;
@@ -154,6 +162,59 @@ std::string ircd_connector::GetBuffer()
return ret;
}
+bool ircd_connector::AddWriteBuf(std::string data)
+{
+ log(DEBUG,"connector::AddWriteBuf(%s)",data.c_str());
+ if (this->GetWriteError() != "")
+ return false;
+ std::stringstream stream;
+ stream << sendq << data;
+ sendq = stream.str();
+ return true;
+}
+
+bool ircd_connector::HasBufferedOutput()
+{
+ return (sendq.length() > 0);
+}
+
+// send AS MUCH OF THE USERS SENDQ as we are able to (might not be all of it)
+bool ircd_connector::FlushWriteBuf()
+{
+ log(DEBUG,"connector::FlushWriteBuf()");
+ if (sendq.length())
+ {
+ char* tb = (char*)this->sendq.c_str();
+ int n_sent = write(this->fd,tb,this->sendq.length());
+ if (n_sent == -1)
+ {
+ this->SetWriteError(strerror(errno));
+ return false;
+ }
+ else
+ {
+ log(DEBUG,"Wrote %d chars to socket",n_sent);
+ // advance the queue
+ tb += n_sent;
+ this->sendq = tb;
+ return true;
+ }
+ }
+ return true;
+}
+
+void ircd_connector::SetWriteError(std::string error)
+{
+ if (this->WriteError == "")
+ this->WriteError = error;
+}
+
+std::string ircd_connector::GetWriteError()
+{
+ return this->WriteError;
+}
+
+
bool ircd_connector::MakeOutboundConnection(char* newhost, int newport)
{
log(DEBUG,"MakeOutboundConnection: Original param: %s",newhost);
@@ -255,11 +316,8 @@ void ircd_connector::SetState(int newstate)
void ircd_connector::CloseConnection()
{
- int flags = fcntl(this->fd, F_GETFL, 0);
- fcntl(this->fd, F_SETFL, flags ^ O_NONBLOCK);
+ shutdown(this->fd,2);
close(this->fd);
- flags = fcntl(this->fd, F_GETFL, 0);
- fcntl(this->fd, F_SETFL, flags | O_NONBLOCK);
}
void ircd_connector::SetDescriptor(int newfd)