}
}
+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");
this->state = I_CONNECTING;
ServerInstance->SE->AddFd(this->fd,false,X_ESTAB_MODULE);
socket_ref[this->fd] = this;
+ this->SetQueues(this->fd);
return true;
}
// and should be aborted.
int InspSocket::Write(std::string data)
{
- this->Buffer = this->Buffer + data;
- this->FlushWriteBuffer();
+ this->Buffer.append(data);
return data.length();
}
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;
+ }
}
}
}
this->state = I_ERROR;
return true;
}
- if (this->Buffer.length())
- this->FlushWriteBuffer();
+ this->FlushWriteBuffer();
return false;
}
bool InspSocket::Poll()
{
int incoming = -1;
+ bool n = true;
switch (this->state)
{
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;
case I_CONNECTED:
- return this->OnDataReady();
+ 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;
break;
default:
break;
}
-
- if (this->Buffer.length())
- this->FlushWriteBuffer();
-
return true;
}