CCF
Loading...
Searching...
No Matches
pending_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 <sys/socket.h>
6
16template <class T>
18{
19 using free_cb_t = void (*)(T*);
20 T* req;
21 size_t len;
22 sockaddr addr;
24 bool clear = false;
25
27 T* req_, size_t len_, sockaddr addr_, free_cb_t free_cb_ = nullptr) :
28 req(req_),
29 len(len_),
30 addr(addr_),
31 free_cb(free_cb_)
32 {
33 if (free_cb == nullptr)
34 {
35 // Assume we take ownership
36 auto orig = req;
37 req = new T[len]; // NOLINT(cppcoreguidelines-owning-memory)
38 memcpy(req, orig, len);
39 }
40 }
41
42 PendingIO(PendingIO&& that) noexcept :
43 req(that.req),
44 len(that.len),
45 addr(that.addr),
46 free_cb(that.free_cb),
47 clear(that.clear)
48 {
49 that.req = nullptr;
50 }
51
53 {
54 req = std::move(that.req);
55 len = std::move(that.len);
56 addr = std::move(that.addr);
57 free_cb = std::move(that.free_cb);
58 clear = std::move(that.clear);
59 that.req = nullptr;
60 return *this;
61 }
62
64 {
65 if (free_cb)
66 {
67 free_cb(req);
68 }
69 else
70 {
71 delete[] req;
72 }
73 }
74
79 static void clear_empty(std::vector<PendingIO<T>>& list)
80 {
81 list.erase(
82 std::remove_if(
83 list.begin(), list.end(), [](PendingIO<T>& p) { return p.clear; }),
84 list.end());
85 }
86};
Pending writes on both host and enclave, with data, length and destination address.
Definition pending_io.h:18
size_t len
Definition pending_io.h:21
sockaddr addr
Definition pending_io.h:22
PendingIO(PendingIO &&that) noexcept
Definition pending_io.h:42
void(*)(T *) free_cb_t
Definition pending_io.h:19
~PendingIO()
Definition pending_io.h:63
static void clear_empty(std::vector< PendingIO< T > > &list)
Clears a list of PendingIO<T> of all elements that were marked to remove (clear flag == true).
Definition pending_io.h:79
PendingIO< T > & operator=(PendingIO &&that) noexcept
Definition pending_io.h:52
PendingIO(T *req_, size_t len_, sockaddr addr_, free_cb_t free_cb_=nullptr)
Definition pending_io.h:26
free_cb_t free_cb
Definition pending_io.h:23
bool clear
Definition pending_io.h:24
T * req
Definition pending_io.h:20