diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-02-07 16:55:02 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-02-07 16:55:02 +0000 |
commit | 0ebea1150578ffbc56b438ae2f85c6dc86153ed3 (patch) | |
tree | 27b6cffd10b89230d9f6946dfa1b5ff93413b147 /src | |
parent | 5f584c5ddbf0faf895fc91b22c74a660aeee8378 (diff) |
Slightly more efficient write buffers
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@3125 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/m_spanningtree.cpp | 2 | ||||
-rw-r--r-- | src/socket.cpp | 28 |
2 files changed, 24 insertions, 6 deletions
diff --git a/src/modules/m_spanningtree.cpp b/src/modules/m_spanningtree.cpp index 29146b1ea..9d29ae6ca 100644 --- a/src/modules/m_spanningtree.cpp +++ b/src/modules/m_spanningtree.cpp @@ -1300,7 +1300,7 @@ class TreeSocket : public InspSocket /* Check that the data read is a valid pointer and it has some content */ if (data && *data) { - this->in_buffer += data; + this->in_buffer.append(data); /* While there is at least one new line in the buffer, * do something useful (we hope!) with it. */ diff --git a/src/socket.cpp b/src/socket.cpp index 7b85f7f6b..15a076273 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -114,6 +114,15 @@ InspSocket::InspSocket(std::string host, int port, bool listening, unsigned long } } +void InspSocket::SetQueues(int nfd) +{ + // attempt to increase socket sendq and recvq as high as its possible + int sendbuf = 32768; + int recvbuf = 32768; + setsockopt(nfd,SOL_SOCKET,SO_SNDBUF,(const void *)&sendbuf,sizeof(sendbuf)); + setsockopt(nfd,SOL_SOCKET,SO_RCVBUF,(const void *)&recvbuf,sizeof(sendbuf)); +} + bool InspSocket::DoResolve() { log(DEBUG,"In DoResolve(), trying to resolve IP"); @@ -176,6 +185,7 @@ bool InspSocket::DoConnect() this->state = I_CONNECTING; ServerInstance->SE->AddFd(this->fd,false,X_ESTAB_MODULE); socket_ref[this->fd] = this; + this->SetQueues(this->fd); return true; } @@ -225,7 +235,7 @@ char* InspSocket::Read() // and should be aborted. int InspSocket::Write(std::string data) { - this->Buffer = this->Buffer + data; + this->Buffer.append(data); this->FlushWriteBuffer(); return data.length(); } @@ -238,10 +248,17 @@ void InspSocket::FlushWriteBuffer() result = send(this->fd,this->Buffer.c_str(),this->Buffer.length(),0); if (result > 0) { - /* If we wrote some, advance the buffer forwards */ - char* n = (char*)this->Buffer.c_str(); - n += result; - this->Buffer = n; + if (result == (int)this->Buffer.length()) + { + this->Buffer = ""; + } + else + { + /* If we wrote some, advance the buffer forwards */ + char* n = (char*)this->Buffer.c_str(); + n += result; + this->Buffer = n; + } } } } @@ -288,6 +305,7 @@ bool InspSocket::Poll() case I_LISTENING: length = sizeof (client); incoming = accept (this->fd, (sockaddr*)&client,&length); + this->SetQueues(incoming); this->OnIncomingConnection(incoming,inet_ntoa(client.sin_addr)); return true; break; |