1 /* 2 * Copyright (C) 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 #ifndef FILLP_SYS_IO_H 17 #define FILLP_SYS_IO_H 18 19 #include "hlist.h" 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 26 typedef struct InnerSysIoOps { 27 int (*doSocket)(void *argSock); 28 int (*send)(void *arg, FILLP_CONST char *buf, FILLP_SIZE_T size, FILLP_SOCKADDR *dest, FILLP_UINT16 destAddrLen); 29 void *(*recv)(void *arg, FILLP_CONST void *buf, void *databuf); 30 void *(*fetchPacket)(void *sock, void *buf, void *count); 31 int (*select)(void *arg, FILLP_INT timeoutUs); 32 void *(*createSocket)(FILLP_INT domain, FILLP_INT type, FILLP_INT protocol); 33 int (*destroySysIoSocket)(void *arg); 34 int (*listen)(void *argSock); 35 36 int (*bind)(void *argSock, void *argPcb, FILLP_SOCKADDR *addr, FILLP_UINT16 len); 37 int (*connect)(void *sock, void *pcb); 38 int (*canSocketRead)(void *arg); /* Is this socket can read */ 39 int (*handlePacket)(int msgType, void *argSock, void *pcb, void *buf); 40 int (*sendPacket)(int msgType, void *argSock, void *pcb, void *buf); 41 void (*removePcb)(void *argSock, void *pcb); 42 void (*freeSock)(void *argSock, void *argOsSock); 43 int (*getSockName)(void *argSock, void *name, void *nameLen); 44 void (*addPcb)(void *argSock, void *argPcb); 45 int (*getOsSocket)(void *argSock); 46 void (*connected)(void *argSock, void *argOsSock); 47 int (*getsockopt)(void *argSock, FILLP_INT level, FILLP_INT optName, void *optVal, FILLP_INT *optLen); 48 int (*setsockopt)(void *argSock, FILLP_INT level, FILLP_INT optName, FILLP_CONST void *optVal, socklen_t optLen); 49 } SysIoOps; 50 51 52 typedef struct Innersysiosock { 53 SysIoOps *ops; 54 } SysIoSock; 55 56 57 typedef struct InnersysioUdpSock { 58 SysIoSock sysIoSock; 59 int udpSock; 60 int addrType; 61 FILLP_BOOL connected; 62 struct SpungePcbhashbucket *pcbHash; /* spunge_pcb will be added when do connect or do accept */ 63 } SysIoUdpSock; 64 65 typedef struct InnersysioUdp { 66 SysIoOps ops; 67 int maxUdpSock; 68 69 FT_FD_SET readSet; /* socket read set for select */ 70 FT_FD_SET readableSet; 71 struct Hlist listenPcbList; 72 } SysioUdpT; 73 extern SysioUdpT g_udpIo; 74 75 SysIoSock *SysIoSocketFactory(FILLP_INT domain, FILLP_INT type, FILLP_INT protocol); 76 77 int SysioSelect(FILLP_INT timeoutUs); 78 int SysioIsSockReadable(void *arg); 79 80 81 #ifdef __cplusplus 82 } 83 #endif 84 85 #endif /* FILLP_SYS_IO_H */ 86