Android-cuttlefish cvd tool
epoll.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <sys/epoll.h>
20
21#include <optional>
22#include <set>
23#include <shared_mutex>
24
27
28namespace cuttlefish {
29
30struct EpollEvent {
32 uint32_t events;
33};
34
35class Epoll {
36 public:
37 static Result<Epoll> Create();
38 Epoll(); // Invalid instance
39 Epoll(Epoll&&);
41
42 Result<void> Add(SharedFD fd, uint32_t events);
43 Result<void> Modify(SharedFD fd, uint32_t events);
44 Result<void> AddOrModify(SharedFD fd, uint32_t events);
47
48 private:
50
56 std::shared_mutex watched_mutex_;
57 std::set<SharedFD> watched_;
58};
59
60} // namespace cuttlefish
Definition: epoll.h:35
Epoll & operator=(Epoll &&)
Definition: epoll.cpp:51
SharedFD epoll_fd_
Definition: epoll.h:51
static Result< Epoll > Create()
Definition: epoll.cpp:33
Result< void > Delete(SharedFD fd)
Definition: epoll.cpp:112
Result< void > AddOrModify(SharedFD fd, uint32_t events)
Definition: epoll.cpp:78
Result< void > Modify(SharedFD fd, uint32_t events)
Definition: epoll.cpp:95
Result< std::optional< EpollEvent > > Wait()
Definition: epoll.cpp:127
std::set< SharedFD > watched_
Definition: epoll.h:57
Result< void > Add(SharedFD fd, uint32_t events)
Definition: epoll.cpp:57
std::shared_mutex watched_mutex_
Definition: epoll.h:56
Definition: shared_fd.h:124
Definition: alloc_driver.h:20
tl::expected< T, StackTraceError > Result
Definition: result_type.h:30
Definition: epoll.h:30
uint32_t events
Definition: epoll.h:32
SharedFD fd
Definition: epoll.h:31