added Stream::shutdown
This commit is contained in:
parent
ced7ad47d5
commit
bc1e5919a6
@ -13,6 +13,10 @@ template<typename T>
|
||||
class Stream: public Handle<T> {
|
||||
static constexpr unsigned int DEFAULT_BACKLOG = 128;
|
||||
|
||||
static void shutdownCallback(T &t, std::function<void(UVWError, T &)> &cb, uv_shutdown_t *, int status) {
|
||||
cb(UVWError{status}, t);
|
||||
}
|
||||
|
||||
static void listenCallback(T &t, std::function<void(UVWError, T &)> &cb, uv_stream_t *, int status) {
|
||||
cb(UVWError{status}, t);
|
||||
}
|
||||
@ -21,10 +25,11 @@ protected:
|
||||
using Handle<T>::Handle;
|
||||
|
||||
public:
|
||||
// TODO shutdown
|
||||
|
||||
void listen(std::function<void(UVWError, T &)> cb) noexcept {
|
||||
listen(DEFAULT_BACKLOG, std::move(cb));
|
||||
void shutdown(std::function<void(UVWError, T &)> cb) noexcept {
|
||||
using CBF = typename Handle<T>::template CallbackFactory<void(uv_shutdown_t *, int)>;
|
||||
auto func = CBF::template on<&Stream<T>::shutdownCallback>(*static_cast<T*>(this), cb);
|
||||
auto err = uv_shutdown(sdown.get(), this->template get<uv_stream_t>(), func);
|
||||
if(err) { Stream<T>::error(err); }
|
||||
}
|
||||
|
||||
void listen(int backlog, std::function<void(UVWError, T &)> cb) noexcept {
|
||||
@ -34,8 +39,11 @@ public:
|
||||
if(err) { Stream<T>::error(err); }
|
||||
}
|
||||
|
||||
void listen(std::function<void(UVWError, T &)> cb) noexcept {
|
||||
listen(DEFAULT_BACKLOG, std::move(cb));
|
||||
}
|
||||
|
||||
// TODO read
|
||||
// TODO stop
|
||||
|
||||
UVWError stop() noexcept {
|
||||
return UVWError{uv_read_stop(this->template get<uv_stream_t>())};
|
||||
@ -53,7 +61,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
std::function<void(UVWError)> listenCb;
|
||||
std::unique_ptr<uv_shutdown_t> sdown;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user