X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Finspsocket.cpp;h=44fe7b72b5e28b1d2375e47d8df5fd0191a22b54;hb=9acece70e533fc45d5401e331af25a5e99dab660;hp=59d9558a4ecd25a83930ff9a2935e853080d39b3;hpb=87b1461e2a4710a38b32186c2582da9fe9bb3804;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp index 59d9558a4..44fe7b72b 100644 --- a/src/inspsocket.cpp +++ b/src/inspsocket.cpp @@ -95,6 +95,10 @@ BufferedSocketError BufferedSocket::BeginConnect(const irc::sockets::sockaddrs& void StreamSocket::Close() { + if (closing) + return; + + closing = true; if (this->fd > -1) { // final chance, dump as much of the sendq as we can @@ -114,6 +118,14 @@ void StreamSocket::Close() } } +void StreamSocket::Close(bool writeblock) +{ + if (getSendQSize() != 0 && writeblock) + closeonempty = true; + else + Close(); +} + CullResult StreamSocket::cull() { Close(); @@ -206,7 +218,12 @@ static const int MYIOV_MAX = IOV_MAX < 128 ? IOV_MAX : 128; void StreamSocket::DoWrite() { if (getSendQSize() == 0) + { + if (closeonempty) + Close(); + return; + } if (!error.empty() || fd < 0) { ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "DoWrite on errored or closed socket"); @@ -242,6 +259,9 @@ void StreamSocket::DoWrite() if (psendq) FlushSendQ(*psendq); + + if (getSendQSize() == 0 && closeonempty) + Close(); } void StreamSocket::FlushSendQ(SendQueue& sq) @@ -521,3 +541,17 @@ size_t StreamSocket::getSendQSize() const } return ret; } + +void StreamSocket::SwapInternals(StreamSocket& other) +{ + if (type != other.type) + return; + + EventHandler::SwapInternals(other); + std::swap(closeonempty, other.closeonempty); + std::swap(closing, other.closing); + std::swap(error, other.error); + std::swap(iohook, other.iohook); + std::swap(recvq, other.recvq); + std::swap(sendq, other.sendq); +}