diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-12-15 20:37:33 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-12-15 20:37:33 +0000 |
commit | 181d7379971c7381b6cbd17d6a0ae24ac588c90c (patch) | |
tree | a50a6ba7014564e80123dd437d456644018c7abf /src/socket.cpp | |
parent | 554ea040741f1341d5b6a1f972e03e6e7afeb848 (diff) |
New socket handling code
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2491 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/socket.cpp')
-rw-r--r-- | src/socket.cpp | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/src/socket.cpp b/src/socket.cpp index e3d8483fb..7be61c9d4 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -175,25 +175,24 @@ char* InspSocket::Read() // and should be aborted. int InspSocket::Write(std::string data) { - char* d = (char*)data.c_str(); - unsigned int written = 0; - int n = 0; - int s = data.length(); - while ((written < data.length()) && (n >= 0)) + this->Buffer = this->Buffer + data; + this->FlushWriteBuffer(); +} + +void InspSocket::FlushWriteBuffer() +{ + int result = 0; + if (this->Buffer.length()) { - n = send(this->fd,d,s,0); - if (n > 0) + result = send(this->fd,this->Buffer,this->Buffer.length(),0); + if (result > 0) { - // If we didnt write everything, advance - // the pointers so that when we retry - // the next time around the loop, we try - // to write what we failed to write before. - written += n; - s -= n; - d += n; + /* If we wrote some, advance the buffer forwards */ + char* n = (char*)this->Buffer.c_str(); + n += result; + this->Buffer = n; } } - return written; } bool InspSocket::Timeout(time_t current) @@ -210,6 +209,8 @@ bool InspSocket::Timeout(time_t current) this->state = I_ERROR; return true; } + if (this->Buffer.length()) + this->FlushWriteBuffer(); return false; } |