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