X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Finspsocket.cpp;h=ee5287e5f33888e0cd24b46f0ce68979cf2d33f9;hb=e9b021cc990deaf3028cb09efa3db0040b0d62a9;hp=d15a1b6a5953518ef1bff1cad757073ea93661bf;hpb=4ec65c6231df9fcb38210f9b885cdf73b72cc176;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp index d15a1b6a5..ee5287e5f 100644 --- a/src/inspsocket.cpp +++ b/src/inspsocket.cpp @@ -23,9 +23,6 @@ #include "inspircd.h" -#include "socket.h" -#include "inspstring.h" -#include "socketengine.h" #include "iohook.h" #ifndef DISABLE_WRITEV @@ -110,8 +107,8 @@ BufferedSocketError BufferedSocket::BeginConnect(const irc::sockets::sockaddrs& if (!SocketEngine::AddFd(this, FD_WANT_NO_READ | FD_WANT_SINGLE_WRITE | FD_WRITE_WILL_BLOCK)) return I_ERR_NOMOREFDS; - this->Timeout = new SocketTimeout(this->GetFd(), this, timeout, ServerInstance->Time()); - ServerInstance->Timers->AddTimer(this->Timeout); + this->Timeout = new SocketTimeout(this->GetFd(), this, timeout); + ServerInstance->Timers.AddTimer(this->Timeout); ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "BufferedSocket::DoConnect success"); return I_ERR_NONE; @@ -153,9 +150,8 @@ bool StreamSocket::GetNextLine(std::string& line, char delim) std::string::size_type i = recvq.find(delim); if (i == std::string::npos) return false; - line = recvq.substr(0, i); - // TODO is this the most efficient way to split? - recvq = recvq.substr(i + 1); + line.assign(recvq, 0, i); + recvq.erase(0, i + 1); return true; } @@ -223,7 +219,7 @@ void StreamSocket::DoWrite() { if (sendq.empty()) return; - if (!error.empty() || fd < 0 || fd == INT_MAX) + if (!error.empty() || fd < 0) { ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "DoWrite on errored or closed socket"); return; @@ -302,7 +298,7 @@ void StreamSocket::DoWrite() else if (rv < itemlen) { SocketEngine::ChangeEventMask(this, FD_WANT_FAST_WRITE | FD_WRITE_WILL_BLOCK); - front = front.substr(rv); + front.erase(0, rv); sendq_len -= rv; return; } @@ -343,15 +339,17 @@ void StreamSocket::DoWrite() } int rv_max = 0; - iovec* iovecs = new iovec[bufcount]; - for(int i=0; i < bufcount; i++) + int rv; { - iovecs[i].iov_base = const_cast(sendq[i].data()); - iovecs[i].iov_len = sendq[i].length(); - rv_max += sendq[i].length(); + iovec iovecs[MYIOV_MAX]; + for (int i = 0; i < bufcount; i++) + { + iovecs[i].iov_base = const_cast(sendq[i].data()); + iovecs[i].iov_len = sendq[i].length(); + rv_max += sendq[i].length(); + } + rv = writev(fd, iovecs, bufcount); } - int rv = writev(fd, iovecs, bufcount); - delete[] iovecs; if (rv == (int)sendq_len) { @@ -381,7 +379,7 @@ void StreamSocket::DoWrite() else { // stopped in the middle of this string - front = front.substr(rv); + front.erase(0, rv); rv = 0; } } @@ -479,11 +477,8 @@ void BufferedSocket::DoWrite() BufferedSocket::~BufferedSocket() { this->Close(); - if (Timeout) - { - // The timer is removed from the TimerManager in Timer::~Timer() - delete Timeout; - } + // The timer is removed from the TimerManager in Timer::~Timer() + delete Timeout; } void StreamSocket::HandleEvent(EventType et, int errornum)