X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Finspsocket.cpp;h=f22645168499d686178b680b504c218fe3184577;hb=9ca7437e8faa192d26e1170e5825318ea0088be2;hp=d7a25785d1d6506f1ca132211cfe8b91a60d83ab;hpb=1031f333332cf1b09db4fd632f141143ee637c34;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp index d7a25785d..f22645168 100644 --- a/src/inspsocket.cpp +++ b/src/inspsocket.cpp @@ -48,7 +48,7 @@ BufferedSocket::BufferedSocket(int newfd) this->fd = newfd; this->state = I_CONNECTED; if (fd > -1) - ServerInstance->SE->AddFd(this, FD_WANT_FAST_READ | FD_WANT_EDGE_WRITE); + SocketEngine::AddFd(this, FD_WANT_FAST_READ | FD_WANT_EDGE_WRITE); } void BufferedSocket::DoConnect(const std::string &ipaddr, int aport, unsigned long maxtime, const std::string &connectbindip) @@ -93,13 +93,13 @@ BufferedSocketError BufferedSocket::BeginConnect(const irc::sockets::sockaddrs& if (bind.sa.sa_family != 0) { - if (ServerInstance->SE->Bind(fd, bind) < 0) + if (SocketEngine::Bind(fd, bind) < 0) return I_ERR_BIND; } - ServerInstance->SE->NonBlocking(fd); + SocketEngine::NonBlocking(fd); - if (ServerInstance->SE->Connect(this, &dest.sa, dest.sa_size()) == -1) + if (SocketEngine::Connect(this, &dest.sa, dest.sa_size()) == -1) { if (errno != EINPROGRESS) return I_ERR_CONNECT; @@ -107,11 +107,11 @@ BufferedSocketError BufferedSocket::BeginConnect(const irc::sockets::sockaddrs& this->state = I_CONNECTING; - if (!ServerInstance->SE->AddFd(this, FD_WANT_NO_READ | FD_WANT_SINGLE_WRITE | FD_WRITE_WILL_BLOCK)) + 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); + ServerInstance->Timers.AddTimer(this->Timeout); ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "BufferedSocket::DoConnect success"); return I_ERR_NONE; @@ -132,14 +132,13 @@ void StreamSocket::Close() catch (CoreException& modexcept) { ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "%s threw an exception: %s", - modexcept.GetSource(), modexcept.GetReason()); + modexcept.GetSource().c_str(), modexcept.GetReason().c_str()); } + delete iohook; DelIOHook(); } - ServerInstance->SE->Shutdown(this, 2); - ServerInstance->SE->DelFd(this); - ServerInstance->SE->Close(this); - fd = -1; + SocketEngine::Shutdown(this, 2); + SocketEngine::Close(this); } } @@ -172,7 +171,7 @@ void StreamSocket::DoRead() catch (CoreException& modexcept) { ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "%s threw an exception: %s", - modexcept.GetSource(), modexcept.GetReason()); + modexcept.GetSource().c_str(), modexcept.GetReason().c_str()); return; } if (rv > 0) @@ -183,36 +182,36 @@ void StreamSocket::DoRead() else { char* ReadBuffer = ServerInstance->GetReadBuffer(); - int n = ServerInstance->SE->Recv(this, ReadBuffer, ServerInstance->Config->NetBufferSize, 0); + int n = SocketEngine::Recv(this, ReadBuffer, ServerInstance->Config->NetBufferSize, 0); if (n == ServerInstance->Config->NetBufferSize) { - ServerInstance->SE->ChangeEventMask(this, FD_WANT_FAST_READ | FD_ADD_TRIAL_READ); + SocketEngine::ChangeEventMask(this, FD_WANT_FAST_READ | FD_ADD_TRIAL_READ); recvq.append(ReadBuffer, n); OnDataReady(); } else if (n > 0) { - ServerInstance->SE->ChangeEventMask(this, FD_WANT_FAST_READ); + SocketEngine::ChangeEventMask(this, FD_WANT_FAST_READ); recvq.append(ReadBuffer, n); OnDataReady(); } else if (n == 0) { error = "Connection closed"; - ServerInstance->SE->ChangeEventMask(this, FD_WANT_NO_READ | FD_WANT_NO_WRITE); + SocketEngine::ChangeEventMask(this, FD_WANT_NO_READ | FD_WANT_NO_WRITE); } else if (SocketEngine::IgnoreError()) { - ServerInstance->SE->ChangeEventMask(this, FD_WANT_FAST_READ | FD_READ_WILL_BLOCK); + SocketEngine::ChangeEventMask(this, FD_WANT_FAST_READ | FD_READ_WILL_BLOCK); } else if (errno == EINTR) { - ServerInstance->SE->ChangeEventMask(this, FD_WANT_FAST_READ | FD_ADD_TRIAL_READ); + SocketEngine::ChangeEventMask(this, FD_WANT_FAST_READ | FD_ADD_TRIAL_READ); } else { error = SocketEngine::LastError(); - ServerInstance->SE->ChangeEventMask(this, FD_WANT_NO_READ | FD_WANT_NO_WRITE); + SocketEngine::ChangeEventMask(this, FD_WANT_NO_READ | FD_WANT_NO_WRITE); } } } @@ -286,7 +285,7 @@ void StreamSocket::DoWrite() #ifdef DISABLE_WRITEV else { - rv = ServerInstance->SE->Send(this, front.data(), itemlen, 0); + rv = SocketEngine::Send(this, front.data(), itemlen, 0); if (rv == 0) { SetError("Connection closed"); @@ -295,14 +294,14 @@ void StreamSocket::DoWrite() else if (rv < 0) { if (errno == EINTR || SocketEngine::IgnoreError()) - ServerInstance->SE->ChangeEventMask(this, FD_WANT_FAST_WRITE | FD_WRITE_WILL_BLOCK); + SocketEngine::ChangeEventMask(this, FD_WANT_FAST_WRITE | FD_WRITE_WILL_BLOCK); else SetError(SocketEngine::LastError()); return; } else if (rv < itemlen) { - ServerInstance->SE->ChangeEventMask(this, FD_WANT_FAST_WRITE | FD_WRITE_WILL_BLOCK); + SocketEngine::ChangeEventMask(this, FD_WANT_FAST_WRITE | FD_WRITE_WILL_BLOCK); front = front.substr(rv); sendq_len -= rv; return; @@ -312,7 +311,7 @@ void StreamSocket::DoWrite() sendq_len -= itemlen; sendq.pop_front(); if (sendq.empty()) - ServerInstance->SE->ChangeEventMask(this, FD_WANT_EDGE_WRITE); + SocketEngine::ChangeEventMask(this, FD_WANT_EDGE_WRITE); } } #endif @@ -321,7 +320,7 @@ void StreamSocket::DoWrite() catch (CoreException& modexcept) { ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "%s threw an exception: %s", - modexcept.GetSource(), modexcept.GetReason()); + modexcept.GetSource().c_str(), modexcept.GetReason().c_str()); } } #ifndef DISABLE_WRITEV @@ -408,11 +407,11 @@ void StreamSocket::DoWrite() if (!error.empty()) { // error - kill all events - ServerInstance->SE->ChangeEventMask(this, FD_WANT_NO_READ | FD_WANT_NO_WRITE); + SocketEngine::ChangeEventMask(this, FD_WANT_NO_READ | FD_WANT_NO_WRITE); } else { - ServerInstance->SE->ChangeEventMask(this, eventChange); + SocketEngine::ChangeEventMask(this, eventChange); } } #endif @@ -431,15 +430,18 @@ void StreamSocket::WriteData(const std::string &data) sendq.push_back(data); sendq_len += data.length(); - ServerInstance->SE->ChangeEventMask(this, FD_ADD_TRIAL_WRITE); + SocketEngine::ChangeEventMask(this, FD_ADD_TRIAL_WRITE); } bool SocketTimeout::Tick(time_t) { ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "SocketTimeout::Tick"); - if (ServerInstance->SE->GetRef(this->sfd) != this->sock) + if (SocketEngine::GetRef(this->sfd) != this->sock) + { + delete this; return false; + } if (this->sock->state == I_CONNECTING) { @@ -455,6 +457,7 @@ bool SocketTimeout::Tick(time_t) } this->sock->Timeout = NULL; + delete this; return false; } @@ -467,10 +470,8 @@ void BufferedSocket::DoWrite() { state = I_CONNECTED; this->OnConnected(); - if (GetIOHook()) - GetIOHook()->OnStreamSocketConnect(this); - else - ServerInstance->SE->ChangeEventMask(this, FD_WANT_FAST_READ | FD_WANT_EDGE_WRITE); + if (!GetIOHook()) + SocketEngine::ChangeEventMask(this, FD_WANT_FAST_READ | FD_WANT_EDGE_WRITE); } this->StreamSocket::DoWrite(); } @@ -533,7 +534,7 @@ void StreamSocket::HandleEvent(EventType et, int errornum) catch (CoreException& ex) { ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "Caught exception in socket processing on FD %d - '%s'", - fd, ex.GetReason()); + fd, ex.GetReason().c_str()); SetError(ex.GetReason()); } if (!error.empty()) @@ -542,4 +543,3 @@ void StreamSocket::HandleEvent(EventType et, int errornum) OnError(errcode); } } -