b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame^] | 1 | #ifndef __MBTK_AT_TCPIP_H__ |
| 2 | #define __MBTK_AT_TCPIP_H__ |
| 3 | |
| 4 | #include <pthread.h> |
| 5 | /*******************DEFINE**********************/ |
| 6 | #define task_mutex pthread_mutex_t |
| 7 | /*******************DEFINE**********************/ |
| 8 | |
| 9 | /*******************TYPEDEF**********************/ |
| 10 | typedef void (*mbtk_tcpip_read_callback_func)(int link_id, const char* data, int data_len); |
| 11 | /*******************TYPEDEF**********************/ |
| 12 | |
| 13 | /*******************ENUM**********************/ |
| 14 | typedef enum { |
| 15 | MBTK_TCPIP_ERR_SUCCESS, |
| 16 | MBTK_TCPIP_ERR_NET_UNAVAILABLE, /* Network unavailable. */ |
| 17 | MBTK_TCPIP_ERR_NET_HANDLE, /* Network handle error. */ |
| 18 | MBTK_TCPIP_ERR_ARG, /* Parameter error. */ |
| 19 | MBTK_TCPIP_ERR_LINK_UNAVAILABLE, /* Link unavailable. */ |
| 20 | MBTK_TCPIP_ERR_LINK_NOT_CONNECT, /* Link not connect. */ |
| 21 | MBTK_TCPIP_ERR_UNKNOWN |
| 22 | } mbtk_tcpip_err_enum; |
| 23 | |
| 24 | typedef enum |
| 25 | { |
| 26 | MBTK_SOCK_TCP = 0, |
| 27 | MBTK_SOCK_UDP |
| 28 | } mbtk_sock_type; |
| 29 | |
| 30 | typedef enum { |
| 31 | MBTK_TCPIP_TYPE_CLIENT, |
| 32 | MBTK_TCPIP_TYPE_SERVER |
| 33 | } mbtk_tcpip_type_enum; |
| 34 | /*******************ENUM**********************/ |
| 35 | |
| 36 | /*******************STRUCT**********************/ |
| 37 | typedef struct |
| 38 | { |
| 39 | unsigned int sig; |
| 40 | void* payload; |
| 41 | } mbtk_signal_info; |
| 42 | |
| 43 | |
| 44 | typedef struct{ |
| 45 | task_mutex crit_sect; //User-defined data type |
| 46 | } mbtk_mutex; |
| 47 | |
| 48 | typedef struct node |
| 49 | { |
| 50 | void *payload; |
| 51 | int count; //only used to count for internal |
| 52 | mbtk_mutex mutex; //only used to count for internal |
| 53 | struct node *front; |
| 54 | struct node *rear; |
| 55 | } mbtk_queue_node_t; |
| 56 | |
| 57 | typedef struct { |
| 58 | pthread_t thread_id; |
| 59 | pthread_cond_t cond; |
| 60 | mbtk_mutex mutex; |
| 61 | mbtk_queue_node_t queue; |
| 62 | } mbtk_task_queue_info; |
| 63 | |
| 64 | typedef struct { |
| 65 | int link_id; |
| 66 | char ser_addr[256]; |
| 67 | int ser_port; |
| 68 | mbtk_sock_type prot_type; // TCP/UDP |
| 69 | mbtk_tcpip_type_enum tcpip_type; // Only support client. |
| 70 | int local_port; |
| 71 | bool ack_support; |
| 72 | bool ssl_support; |
| 73 | bool ignore_cert; |
| 74 | uint32 heartbeat_time; |
| 75 | uint32 delay_time; |
| 76 | |
| 77 | mbtk_tcpip_read_callback_func read_cb; |
| 78 | } mbtk_tcpip_info_t; |
| 79 | |
| 80 | typedef struct { |
| 81 | int link_id; |
| 82 | int sock_fd; |
| 83 | int state; |
| 84 | int recv_data_len; |
| 85 | } mbtk_tcpip_tcp_state_info_s; |
| 86 | /*******************STRUCT**********************/ |
| 87 | |
| 88 | |
| 89 | |
| 90 | #endif |