1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "ffrt_descriptor_listener.h" 17 #include "event_logger.h" 18 19 namespace OHOS { 20 namespace AppExecFwk { 21 namespace { 22 DEFINE_EH_HILOG_LABEL("FfrtDescriptorListener"); 23 } OnReadable(int32_t fileDescriptor)24void FfrtDescriptorListener::OnReadable(int32_t fileDescriptor) 25 { 26 if (fileDescriptor < 0) { 27 HILOGW("OnReadable bad fd"); 28 return; 29 } 30 InvokePollCb(EPOLLIN); 31 } 32 OnWritable(int32_t fileDescriptor)33void FfrtDescriptorListener::OnWritable(int32_t fileDescriptor) 34 { 35 if (fileDescriptor < 0) { 36 HILOGW("OnWritable bad fd"); 37 return; 38 } 39 InvokePollCb(EPOLLOUT); 40 } 41 OnShutdown(int32_t fileDescriptor)42void FfrtDescriptorListener::OnShutdown(int32_t fileDescriptor) 43 { 44 if (fileDescriptor < 0) { 45 HILOGW("OnShutdown bad fd"); 46 return; 47 } 48 HILOGW("OnShutdown bad fd %{public}d", fileDescriptor); 49 InvokePollCb(EPOLLHUP); 50 } 51 OnException(int32_t fileDescriptor)52void FfrtDescriptorListener::OnException(int32_t fileDescriptor) 53 { 54 if (fileDescriptor < 0) { 55 HILOGW("OnException bad fd"); 56 return; 57 } 58 HILOGW("OnException bad fd %{public}d", fileDescriptor); 59 InvokePollCb(EPOLLERR); 60 } 61 ConvertEvents(uint32_t events)62uint32_t FfrtDescriptorListener::ConvertEvents(uint32_t events) 63 { 64 uint32_t epollEvents = 0; 65 if ((events & EPOLLIN) != 0) { 66 epollEvents |= FILE_DESCRIPTOR_INPUT_EVENT; 67 } 68 69 if ((events & EPOLLOUT) != 0) { 70 epollEvents |= FILE_DESCRIPTOR_OUTPUT_EVENT; 71 } 72 return epollEvents; 73 } 74 }} 75