1 /*
2  * Copyright (c) 2006-2023, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2023-12-06     zmq810150896      The first version.
9  */
10 #ifndef __SAL_MSG_H__
11 #define __SAL_MSG_H__
12 #include <rtthread.h>
13 
14 /* message frame */
15 struct msg_buf
16 {
17     void *parm;             /* Parameters for message detection */
18     void *buf;              /* Data to be sent */
19     rt_size_t length;       /* Data length */
20     void *control_data;     /* Additional data to send the message */
21     rt_size_t data_len;     /* Additional data length */
22     int msg_type;           /* message type */
23     int data_type;          /* Addittional data length */
24     int msg_level;
25     int *fd;                /* Pass the array used by fd */
26     rt_slist_t msg_next;    /* Next message */
27     rt_slist_t msg_node;    /* sendmsg is used to send multiple messages at the same time */
28 };
29 
30 /* Remaining message */
31 struct last_buf
32 {
33     void *buf;              /* Data to be sent */
34     rt_size_t length;       /* Data length */
35     rt_size_t offset;       /* Data Offset */
36     struct msg_buf *msg;
37 };
38 
39 /* sock */
40 struct unix_sock
41 {
42     rt_uint8_t len;
43     int flags;
44     uint8_t family;             /* protocol */
45     char path[108];             /* file name */
46     struct unix_conn *conn;     /* connecting processing */
47     rt_wqueue_t wq_head;        /* Waiting queue head */
48     rt_atomic_t listen_num;     /* Maximum listening quantity */
49     rt_atomic_t conn_counter;   /*  connected num */
50     struct rt_mutex sock_lock;
51     rt_slist_t wait_conn_head;
52     struct last_buf pbuf;
53 };
54 
55 struct unix_conn
56 {
57     int state;                                          /*  connect state */
58     int type;
59     int proto;
60 
61 #ifdef SAL_USING_AF_UNIX
62     rt_atomic_t msg_count;
63 #endif
64     rt_uint32_t send_timeout;
65     rt_uint32_t recv_timeout;
66     rt_wqueue_t wq_read_head;
67     rt_wqueue_t wq_confirm;
68     struct rt_mutex conn_lock;
69     rt_slist_t msg_head;                                /* message head */
70     rt_slist_t conn_node;
71     struct unix_sock *sock;
72     struct unix_sock *ser_sock;
73     struct unix_conn *correl_conn;                      /* Information about the other party */
74     int (* conn_callback)(struct unix_conn *conn);      /* The callback function that establishes the connection */
75 };
76 
77 #endif
78