1 /* 2 * Copyright (c) 2021 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 #ifndef LOCAL_SOCAKT_PAIR_H 17 #define LOCAL_SOCAKT_PAIR_H 18 19 #include <sys/types.h> 20 #include <refbase.h> 21 #include "message_parcel.h" 22 23 namespace OHOS { 24 class LocalSocketPair : public RefBase { 25 public: 26 LocalSocketPair(); 27 virtual ~LocalSocketPair(); 28 LocalSocketPair(const LocalSocketPair &) = delete; 29 LocalSocketPair &operator=(const LocalSocketPair &) = delete; 30 int32_t CreateChannel(size_t sendSize, size_t receiveSize); GetSendDataFd()31 int32_t GetSendDataFd() const 32 { 33 return sendFd_; 34 }; GetReceiveDataFd()35 int32_t GetReceiveDataFd() const 36 { 37 return receiveFd_; 38 }; 39 40 // send sendfd to binder 41 int32_t SendToBinder(MessageParcel &data); 42 43 // send receivefd to binder 44 int32_t ReceiveToBinder(MessageParcel &data); 45 46 int32_t SendData(const void *vaddr, size_t size); 47 int32_t ReceiveData(void *vaddr, size_t size); 48 private: 49 int32_t SendFdToBinder(MessageParcel &data, int32_t &fd); 50 void CloseFd(int32_t &fd); 51 int32_t SetSockopt(size_t sendSize, size_t receiveSize, int32_t* socketPair, int32_t socketPairSize); 52 53 private: 54 int32_t sendFd_; 55 int32_t receiveFd_; 56 }; 57 } 58 59 #endif // BS_LOCAL_SOCAKTPAIR_H 60