diff options
author | Peter Powell <petpow@saberuk.com> | 2019-07-21 16:56:55 +0100 |
---|---|---|
committer | Peter Powell <petpow@saberuk.com> | 2019-07-21 16:57:19 +0100 |
commit | 5f387071d339892ebed5accba92f91f997396476 (patch) | |
tree | c91e7f11859dc267b8c2b946f159abe28d558038 | |
parent | 62f6e56e158a3c147cd1395dab790f918ce2d1b4 (diff) |
Add a method for swapping user I/O handlers.
-rw-r--r-- | include/inspsocket.h | 7 | ||||
-rw-r--r-- | include/socketengine.h | 6 | ||||
-rw-r--r-- | include/users.h | 5 | ||||
-rw-r--r-- | src/inspsocket.cpp | 14 | ||||
-rw-r--r-- | src/socketengine.cpp | 6 | ||||
-rw-r--r-- | src/users.cpp | 6 |
6 files changed, 44 insertions, 0 deletions
diff --git a/include/inspsocket.h b/include/inspsocket.h index a07c2eb6f..208644645 100644 --- a/include/inspsocket.h +++ b/include/inspsocket.h @@ -275,7 +275,14 @@ class CoreExport StreamSocket : public EventHandler int HookChainRead(IOHook* hook, std::string& rq); protected: + /** The data which has been received from the socket. */ std::string recvq; + + /** Swaps the internals of this StreamSocket with another one. + * @param other A StreamSocket to swap internals with. + */ + void SwapInternals(StreamSocket& other); + public: const Type type; StreamSocket(Type sstype = SS_UNKNOWN) diff --git a/include/socketengine.h b/include/socketengine.h index d8d127f8b..9202c179d 100644 --- a/include/socketengine.h +++ b/include/socketengine.h @@ -164,6 +164,12 @@ class CoreExport EventHandler : public classbase * registered with the SocketEngine */ int fd; + + /** Swaps the internals of this EventHandler with another one. + * @param other A EventHandler to swap internals with. + */ + void SwapInternals(EventHandler& other); + public: /** Get the current file descriptor * @return The file descriptor of this handler diff --git a/include/users.h b/include/users.h index dc7da40fe..94a8af9a4 100644 --- a/include/users.h +++ b/include/users.h @@ -700,6 +700,11 @@ class CoreExport UserIOHandler : public StreamSocket * @param data The data to add to the write buffer */ void AddWriteBuf(const std::string &data); + + /** Swaps the internals of this UserIOHandler with another one. + * @param other A UserIOHandler to swap internals with. + */ + void SwapInternals(UserIOHandler& other); }; typedef unsigned int already_sent_t; diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp index 684ee051d..44fe7b72b 100644 --- a/src/inspsocket.cpp +++ b/src/inspsocket.cpp @@ -541,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); +} diff --git a/src/socketengine.cpp b/src/socketengine.cpp index df6ff5a02..f447fded8 100644 --- a/src/socketengine.cpp +++ b/src/socketengine.cpp @@ -50,6 +50,12 @@ EventHandler::EventHandler() event_mask = 0; } +void EventHandler::SwapInternals(EventHandler& other) +{ + std::swap(fd, other.fd); + std::swap(event_mask, other.event_mask); +} + void EventHandler::SetFd(int FD) { this->fd = FD; diff --git a/src/users.cpp b/src/users.cpp index c0dc69ff4..26353ab24 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -301,6 +301,12 @@ void UserIOHandler::AddWriteBuf(const std::string &data) WriteData(data); } +void UserIOHandler::SwapInternals(UserIOHandler& other) +{ + StreamSocket::SwapInternals(other); + std::swap(checked_until, other.checked_until); +} + bool UserIOHandler::OnSetEndPoint(const irc::sockets::sockaddrs& server, const irc::sockets::sockaddrs& client) { memcpy(&user->server_sa, &server, sizeof(irc::sockets::sockaddrs)); |