1 // Copyright 2018 The Android Open Source Project 2 // 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 #pragma once 16 17 #ifdef _MSC_VER 18 #include "msvc-posix.h" 19 #endif 20 21 #include <sys/types.h> 22 23 namespace android { 24 namespace base { 25 26 // Create a unidirectional pipe with the read-end connected to |readPipe| and 27 // the write-end connected to |writePipe|. This is equivalent to calling the 28 // POSIX function: 29 // pipe(&fds); 30 // On Windows this will not use TCP loopback or sockets but instead the _pipe 31 // call making this an efficient form of communication on all platforms. 32 int ipcPipeCreate(int* readPipe, int* writePipe); 33 34 // Closes one end of a pipe. The ends of the pipe need to be closed separately. 35 void ipcPipeClose(int pipe); 36 37 // Try to read up to |bufferLen| bytes from |pipe| into |buffer|. 38 // Return the number of bytes actually read, 0 in case of disconnection, 39 // or -1/errno in case of error. Note that this loops around EINTR as 40 // a convenience. Only works on the read end of a pipe. 41 ssize_t ipcPipeRead(int pipe, void* buffer, size_t bufferLen); 42 43 // Try to write up to |bufferLen| bytes to |pipe| from |buffer|. 44 // Return the number of bytes actually written, 0 in case of disconnection, 45 // or -1/errno in case of error. Note that this loops around EINTR as 46 // a convenience. Only works on the write end of a pipe. 47 ssize_t ipcPipeWrite(int pipe, const void* buffer, size_t bufferLen); 48 49 } // namespace base 50 } // namespace android 51 52