]> git.tdb.fi Git - libs/net.git/blobdiff - source/net/resolve.h
Use std::unique_ptr for owning pointers
[libs/net.git] / source / net / resolve.h
index 5e7781dfc64a3e66bf16d1b02c8beed05aaefc83..ae0411bd807c5e37292e0fd76f75e1fd34f9d94d 100644 (file)
@@ -2,6 +2,7 @@
 #define MSP_NET_RESOLVE_H_
 
 #include <deque>
+#include <memory>
 #include <string>
 #include <msp/core/mutex.h>
 #include <msp/core/semaphore.h>
@@ -36,14 +37,12 @@ class Resolver
 private:
        struct Task
        {
-               unsigned tag;
+               unsigned tag = 0;
                std::string host;
                std::string serv;
-               Family family;
-               SockAddr *addr;
-               std::runtime_error *error;
-
-               Task();
+               Family family = UNSPEC;
+               std::unique_ptr<SockAddr> addr;
+               std::unique_ptr<std::runtime_error> error;
 
                bool is_complete() const { return addr || error; }
        };
@@ -55,20 +54,20 @@ private:
                Mutex queue_mutex;
                Semaphore sem;
                IO::Pipe notify_pipe;
-               bool done;
+               bool done = false;
 
        public:
                WorkerThread();
                ~WorkerThread();
 
-               void add_task(const Task &);
+               void add_task(Task &&);
                Task *get_complete_task();
                void pop_complete_task();
 
                IO::Pipe &get_notify_pipe() { return notify_pipe; }
 
        private:
-               virtual void main();
+               void main() override;
        };
 
 public:
@@ -76,9 +75,9 @@ public:
        sigc::signal<void, unsigned, const std::exception &> signal_resolve_failed;
 
 private:
-       IO::EventDispatcher *event_disp;
+       IO::EventDispatcher *event_disp = nullptr;
        WorkerThread thread;
-       unsigned next_tag;
+       unsigned next_tag = 1;
 
 public:
        Resolver();