clean up
This commit is contained in:
parent
13c8c4e4ec
commit
f658a850c4
@ -6,7 +6,6 @@
|
||||
#include "uvw/loop.hpp"
|
||||
#include "uvw/prepare.hpp"
|
||||
#include "uvw/request.hpp"
|
||||
#include "uvw/self.hpp"
|
||||
#include "uvw/stream.hpp"
|
||||
#include "uvw/tcp.hpp"
|
||||
#include "uvw/timer.hpp"
|
||||
|
||||
@ -5,7 +5,6 @@
|
||||
#include <memory>
|
||||
#include <uv.h>
|
||||
#include "emitter.hpp"
|
||||
#include "self.hpp"
|
||||
#include "loop.hpp"
|
||||
|
||||
|
||||
@ -23,7 +22,7 @@ template<> struct HandleType<uv_tcp_t> { };
|
||||
|
||||
|
||||
template<typename T>
|
||||
class Handle: public Emitter<T>, public Self<T> {
|
||||
class Handle: public Emitter<T>, public std::enable_shared_from_this<T> {
|
||||
struct BaseWrapper {
|
||||
virtual ~BaseWrapper() = default;
|
||||
virtual void * get() const noexcept = 0;
|
||||
@ -41,15 +40,17 @@ class Handle: public Emitter<T>, public Self<T> {
|
||||
Handle<T> &ref = *(static_cast<T*>(handle->data));
|
||||
ref.initialized = false;
|
||||
ref.publish(CloseEvent{});
|
||||
ref.reset();
|
||||
ref.leak.reset();
|
||||
}
|
||||
|
||||
protected:
|
||||
template<typename U>
|
||||
explicit Handle(HandleType<U>, std::shared_ptr<Loop> ref)
|
||||
: Emitter<T>{}, Self<T>{},
|
||||
: Emitter<T>{},
|
||||
std::enable_shared_from_this<T>{},
|
||||
wrapper{std::make_unique<Wrapper<U>>()},
|
||||
pLoop{std::move(ref)},
|
||||
leak{nullptr},
|
||||
initialized{false}
|
||||
{
|
||||
this->template get<uv_handle_t>()->data = static_cast<T*>(this);
|
||||
@ -71,8 +72,8 @@ protected:
|
||||
this->publish(ErrorEvent{err});
|
||||
ret = false;
|
||||
} else {
|
||||
leak = this->shared_from_this();
|
||||
initialized = true;
|
||||
this->leak();
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,6 +109,7 @@ public:
|
||||
private:
|
||||
std::unique_ptr<BaseWrapper> wrapper;
|
||||
std::shared_ptr<Loop> pLoop;
|
||||
std::shared_ptr<void> leak;
|
||||
bool initialized;
|
||||
};
|
||||
|
||||
|
||||
@ -1,25 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
||||
namespace uvw {
|
||||
|
||||
|
||||
template<typename T>
|
||||
struct Self: public std::enable_shared_from_this<T> {
|
||||
virtual ~Self() {
|
||||
static_assert(std::is_base_of<Self<T>, T>::value, "!");
|
||||
}
|
||||
|
||||
protected:
|
||||
void leak() noexcept { self = this->shared_from_this(); }
|
||||
void reset() noexcept { self.reset(); }
|
||||
|
||||
private:
|
||||
std::shared_ptr<void> self;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user