CCF
Loading...
Searching...
No Matches
after_io.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
5#include "proxy.h"
6
7namespace asynchost
8{
9 template <typename Behaviour>
10 class AfterIO : public with_uv_handle<uv_check_t>
11 {
12 private:
13 friend class close_ptr<AfterIO<Behaviour>>;
14 Behaviour behaviour;
15
16 template <typename... Args>
17 AfterIO(Args&&... args) : behaviour(std::forward<Args>(args)...)
18 {
19 int rc;
20
21 if ((rc = uv_check_init(uv_default_loop(), &uv_handle)) < 0)
22 {
23 LOG_FAIL_FMT("uv_check_init failed: {}", uv_strerror(rc));
24 throw std::logic_error("uv_check_init failed");
25 }
26
27 uv_handle.data = this;
28
29 if ((rc = uv_check_start(&uv_handle, on_check)) < 0)
30 {
31 LOG_FAIL_FMT("uv_check_start failed: {}", uv_strerror(rc));
32 throw std::logic_error("uv_check_start failed");
33 }
34 }
35
36 static void on_check(uv_check_t* handle)
37 {
38 static_cast<AfterIO*>(handle->data)->on_check();
39 }
40
41 void on_check()
42 {
43 behaviour.after_io();
44 }
45 };
46}
Definition after_io.h:11
Definition proxy.h:15
Definition proxy.h:82
uv_check_t uv_handle
Definition proxy.h:84
#define LOG_FAIL_FMT
Definition logger.h:363
Definition after_io.h:8