• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * This file is part of the openHiTLS project.
3  *
4  * openHiTLS is licensed under the Mulan PSL v2.
5  * You can use this software according to the terms and conditions of the Mulan PSL v2.
6  * You may obtain a copy of Mulan PSL v2 at:
7  *
8  *     http://license.coscl.org.cn/MulanPSL2
9  *
10  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13  * See the Mulan PSL v2 for more details.
14  */
15 
16 #ifndef UIO_ABSTRACTION_H
17 #define UIO_ABSTRACTION_H
18 
19 #include "hitls_build.h"
20 #ifdef HITLS_BSL_UIO_PLT
21 
22 #include "bsl_uio.h"
23 #include "uio_base.h"
24 #include "sal_atomic.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #define IP_ADDR_V4_LEN 4
31 #define IP_ADDR_V6_LEN 16
32 #define IP_ADDR_MAX_LEN IP_ADDR_V6_LEN
33 
34 #define SOCK_ADDR_V4_LEN     (sizeof(struct sockaddr_in))
35 #define SOCK_ADDR_V6_LEN     (sizeof(struct sockaddr_in6))
36 #define SOCK_ADDR_UNIX_LEN   (sizeof(struct sockaddr_un))
37 #define DGRAM_SOCKADDR_MAX_LEN SOCK_ADDR_UNIX_LEN
38 
39 struct UIO_ControlBlock {
40     struct BSL_UIO_MethodStruct method;
41 
42     uint32_t flags;             // Read/write retry flag. For details, see BSL_UIO_FLAGS_* in bsl_uio.h
43     bool init;              // Initialization flag. 1 means it's initialized, and 0 means it's not initialized.
44 
45     int64_t writeNum;          // count of write
46     int64_t readNum;           // count of read
47 
48     void *ctx;                  // Context
49     uint32_t ctxLen;            // Context length
50 
51     void *userData;             // User data
52     BSL_UIO_USERDATA_FREE_FUNC userDataFreeFunc;  // Release User Data
53 
54     struct UIO_ControlBlock *prev; // Previous UIO object of the current UIO object in the UIO chain
55     struct UIO_ControlBlock *next; // Next UIO object of the current UIO object in the UIO chain
56 
57     bool isUnderlyingClosedByUio; // Indicates whether related resources are released together with the UIO.
58     BSL_SAL_RefCount references;    // reference count
59 };
60 
61 typedef struct {
62     uint8_t *data;
63     uint64_t size;
64 } BSL_UIO_CtrlGetInfoParam;
65 
66 /**
67  * @brief Check whether a given error code is a fatal error.
68  *
69  * @param err [IN] Error code.
70  *
71  * @return true: A fatal error occurs.
72  *         false: No fatal error occurs.
73  */
74 bool UioIsNonFatalErr(int32_t err);
75 
76 #ifdef __cplusplus
77 }
78 #endif
79 
80 #endif /* HITLS_BSL_UIO_PLT */
81 
82 #endif // UIO_ABSTRACTION_H
83 
84