Apollo 10.0
自动驾驶开放平台
poll_handler.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
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#ifndef CYBER_IO_POLL_HANDLER_H_
18#define CYBER_IO_POLL_HANDLER_H_
19
20#include <atomic>
21#include <memory>
22
24#include "cyber/io/poll_data.h"
25
26namespace apollo {
27namespace cyber {
28namespace io {
29
31 public:
32 explicit PollHandler(int fd);
33 virtual ~PollHandler() = default;
34
35 bool Block(int timeout_ms, bool is_read);
36 bool Unblock();
37
38 int fd() const { return fd_; }
39 void set_fd(int fd) { fd_ = fd; }
40
41 private:
42 bool Check(int timeout_ms);
43 void Fill(int timeout_ms, bool is_read);
44 void ResponseCallback(const PollResponse& rsp);
45
46 int fd_;
47 PollRequest request_;
48 PollResponse response_;
49 std::atomic<bool> is_read_;
50 std::atomic<bool> is_blocking_;
51 croutine::CRoutine* routine_;
52};
53
54} // namespace io
55} // namespace cyber
56} // namespace apollo
57
58#endif // CYBER_IO_POLL_HANDLER_H_
virtual ~PollHandler()=default
bool Block(int timeout_ms, bool is_read)
class register implement
Definition arena_queue.h:37