1 #pragma once 2 3 /* 4 * Copyright (C) 2019 The Android Open Source Project 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 #include "sysdeps.h" 20 21 #include <deque> 22 #include <list> 23 #include <mutex> 24 #include <unordered_map> 25 26 #include <android-base/thread_annotations.h> 27 28 #include "adb_unique_fd.h" 29 #include "fdevent.h" 30 31 struct PollNode { 32 fdevent* fde; 33 adb_pollfd pollfd; 34 PollNodePollNode35 explicit PollNode(fdevent* fde) : fde(fde) { 36 memset(&pollfd, 0, sizeof(pollfd)); 37 pollfd.fd = fde->fd.get(); 38 39 #if defined(__linux__) 40 // Always enable POLLRDHUP, so the host server can take action when some clients disconnect. 41 // Then we can avoid leaving many sockets in CLOSE_WAIT state. See http://b/23314034. 42 pollfd.events = POLLRDHUP; 43 #endif 44 } 45 }; 46 47 struct fdevent_context_poll final : public fdevent_context { 48 fdevent_context_poll(); 49 virtual ~fdevent_context_poll(); 50 51 virtual void Register(fdevent* fde) final; 52 virtual void Unregister(fdevent* fde) final; 53 54 virtual void Set(fdevent* fde, unsigned events) final; 55 56 virtual void Loop() final; 57 58 virtual size_t InstalledCount() final; 59 60 protected: 61 virtual void Interrupt() final; 62 63 public: 64 unique_fd interrupt_fd_; 65 fdevent* interrupt_fde_ = nullptr; 66 }; 67