From 53f280ed2ec0fdcac4e0e60f5d2566ae9f701a97 Mon Sep 17 00:00:00 2001 From: brain Date: Tue, 7 Mar 2006 17:32:55 +0000 Subject: Check for write errors in inspsocket (this is probably causing excessive cpu use when we have a large buffer to flush but a write error has occured (which we missed)) git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@3518 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/socket.cpp | 23 ++++++++++++++++------- src/svn-rev.sh | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/socket.cpp b/src/socket.cpp index 4c03c933d..4b139c7f5 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -232,7 +232,7 @@ char* InspSocket::Read() } else { - log(DEBUG,"EOF or error on socket"); + log(DEBUG,"EOF or error on socket: %s",strerror(errno)); return NULL; } } @@ -257,7 +257,7 @@ int InspSocket::Write(std::string data) return data.length(); } -void InspSocket::FlushWriteBuffer() +bool InspSocket::FlushWriteBuffer() { if ((this->fd > -1) && (this->state == I_CONNECTED)) { @@ -280,8 +280,16 @@ void InspSocket::FlushWriteBuffer() Buffer = n; } } + else if (result == -1) + { + log(DEBUG,"Write error on socket: %s",strerror(errno)); + this->OnError(I_ERR_WRITE); + this->state = I_ERROR; + return false; + } } } + return true; } bool InspSocket::Timeout(time_t current) @@ -299,8 +307,7 @@ bool InspSocket::Timeout(time_t current) this->state = I_ERROR; return true; } - this->FlushWriteBuffer(); - return false; + return this->FlushWriteBuffer(); } bool InspSocket::Poll() @@ -334,9 +341,11 @@ bool InspSocket::Poll() case I_CONNECTED: n = this->OnDataReady(); /* Flush any pending, but not till after theyre done with the event - * so there are less write calls involved. */ - this->FlushWriteBuffer(); - return n; + * so there are less write calls involved. + * Both FlushWriteBuffer AND the return result of OnDataReady must + * return true for this to be ok. + */ + return (n && this->FlushWriteBuffer()); break; default: break; diff --git a/src/svn-rev.sh b/src/svn-rev.sh index 7b85fd8af..5fa9d51df 100755 --- a/src/svn-rev.sh +++ b/src/svn-rev.sh @@ -1 +1 @@ -echo 3515 +echo 3517 -- cgit v1.2.3