]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Add a method for swapping user I/O handlers.
authorPeter Powell <petpow@saberuk.com>
Sun, 21 Jul 2019 15:56:55 +0000 (16:56 +0100)
committerPeter Powell <petpow@saberuk.com>
Sun, 21 Jul 2019 15:57:19 +0000 (16:57 +0100)
include/inspsocket.h
include/socketengine.h
include/users.h
src/inspsocket.cpp
src/socketengine.cpp
src/users.cpp

index a07c2eb6f82c2aaf4519496fa7dadee80b69e560..208644645210a96427effdb354e65b3e2415983c 100644 (file)
@@ -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)
index d8d127f8bb21fa2233d85cb4360ca8087942b4e4..9202c179dab36ff553dfc8058fa99ab3daa19266 100644 (file)
@@ -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
index dc7da40fe2a7e2adb817fcba8894f4b185ffa3d7..94a8af9a4115d95b502eeadcdfa69e56035e5b26 100644 (file)
@@ -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;
index 684ee051dd96cdc4ede09f68895a785912672ad8..44fe7b72b5e28b1d2375e47d8df5fd0191a22b54 100644 (file)
@@ -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);
+}
index df6ff5a0206d0471b41d962ffe115a9add91ab1f..f447fded84bb6b6806c22ec2535ba98bfc306a41 100644 (file)
@@ -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;
index c0dc69ff4fc3b2dff5048ab9924d1579c83b5a18..26353ab24039f6a71626cfecf6b92b08e2d48e53 100644 (file)
@@ -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));