Android-cuttlefish cvd tool
shared_select.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016 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#ifndef CUTTLEFISH_COMMON_COMMON_LIBS_FS_SHARED_SELECT_H_
17#define CUTTLEFISH_COMMON_COMMON_LIBS_FS_SHARED_SELECT_H_
18
19#include <set>
20
22
23namespace cuttlefish {
35 public:
36 // These methods and types have more to do with the STL than POSIX,
37 // so I'm using STL-compatible notation.
38 typedef std::set<SharedFD>::iterator iterator;
39 typedef std::set<SharedFD>::const_iterator const_iterator;
40
41 iterator begin() { return value_.begin(); }
42 iterator end() { return value_.end(); }
43 const_iterator begin() const { return value_.begin(); }
44 const_iterator end() const { return value_.end(); }
45
46 void swap(SharedFDSet* rhs) {
47 value_.swap(rhs->value_);
48 }
49
50 void Clr(const SharedFD& in) {
51 value_.erase(in);
52 }
53
54 bool IsSet(const SharedFD& in) const {
55 return value_.count(in) != 0;
56 }
57
58 void Set(const SharedFD& in) {
59 value_.insert(in);
60 }
61
62 void Zero() {
63 value_.clear();
64 }
65
66 private:
67 std::set<SharedFD> value_;
68};
69
76int Select(SharedFDSet* read_set, SharedFDSet* write_set,
77 SharedFDSet* error_set, struct timeval* timeout);
78
79} // namespace cuttlefish
80
81#endif // CUTTLEFISH_COMMON_COMMON_LIBS_FS_SHARED_SELECT_H_
Definition: shared_select.h:34
std::set< SharedFD >::const_iterator const_iterator
Definition: shared_select.h:39
void Zero()
Definition: shared_select.h:62
std::set< SharedFD > value_
Definition: shared_select.h:67
const_iterator end() const
Definition: shared_select.h:44
std::set< SharedFD >::iterator iterator
Definition: shared_select.h:38
bool IsSet(const SharedFD &in) const
Definition: shared_select.h:54
void Set(const SharedFD &in)
Definition: shared_select.h:58
const_iterator begin() const
Definition: shared_select.h:43
iterator end()
Definition: shared_select.h:42
void swap(SharedFDSet *rhs)
Definition: shared_select.h:46
void Clr(const SharedFD &in)
Definition: shared_select.h:50
iterator begin()
Definition: shared_select.h:41
Definition: shared_fd.h:129
Definition: alloc_utils.cpp:23
int Select(SharedFDSet *read_set, SharedFDSet *write_set, SharedFDSet *error_set, struct timeval *timeout)
Definition: shared_fd.cpp:292