1 /* 2 * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED. 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 POSIX_HELP_H 17 #define POSIX_HELP_H 18 19 #include <errno.h> 20 #include <strings.h> 21 #include <stdint.h> 22 #include <netinet/in.h> 23 #include <pthread.h> 24 25 #if __cplusplus 26 extern "C" { 27 #endif 28 29 /* 30 * usleep time length 31 * The unit of usleep() is microseconds 32 */ 33 #define HI_USLEEP_MS 1000 34 35 /* Socketpair channel */ 36 typedef struct SkPair { 37 int in; // in fd 38 int out; // out fd 39 } SkPair; 40 41 /* SkPair create */ 42 int SkPairCreate(SkPair* chn); 43 44 /* Read complete message */ 45 int FdReadMsg(int fd, HI_VOID* msgBuf, int msgSize); 46 47 /* Write complete message */ 48 int FdWriteMsg(int fd, const HI_VOID* msgData, int msgLen); 49 50 /* SkPair destroy */ 51 void SkPairDestroy(SkPair* chn); 52 53 void RecurMutexInit(pthread_mutex_t* mutex); 54 55 #ifdef __cplusplus 56 } 57 #endif 58 #endif 59