Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
HR_Socket_Msg_Demo
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
马伊齐
HR_Socket_Msg_Demo
Commits
b0db938c
Commit
b0db938c
authored
Dec 20, 2023
by
马伊齐
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加通道初始话函数
parent
12008a6a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
2 deletions
+36
-2
sock_msg.c
lib/sock_msg.c
+36
-2
No files found.
lib/sock_msg.c
View file @
b0db938c
...
...
@@ -20,6 +20,7 @@
int
msgid
=
-
1
;
// 全局变量,用于存储消息队列ID
int
shmid
;
messageQueue
*
queue
;
static
int
is_initialized
=
0
;
// 通道发送接收是否已经初始化标志
// 全局数组来保存socket信息
socket_info_t
sockets
[
MAX_CLIENTS
+
1
]
=
{
0
};
...
...
@@ -31,6 +32,12 @@ const char *msg_channel_paths[MSG_CHAN_MAX] = {
"/tmp/msg_channel_iomod"
,
};
/**
* @brief 通道发送接收初始化
*
*/
void
init_msg_channel
();
int
sock_init
(
int
server
,
uint32_t
ipaddr
,
uint32_t
port
)
{
int
sockfd
;
...
...
@@ -363,8 +370,28 @@ int msg_local_recv_pulse(uint16_t *type, uint32_t *code)
}
}
void
init_msg_channel
()
{
for
(
int
i
=
0
;
i
<
MSG_CHAN_MAX
;
i
++
)
{
if
(
access
(
msg_channel_paths
[
i
],
F_OK
)
==
-
1
)
{
if
(
mkfifo
(
msg_channel_paths
[
i
],
0666
)
==
-
1
)
{
perror
(
"init_msg_channel: mkfifo"
);
exit
(
EXIT_FAILURE
);
}
}
}
}
int
msg_recv
(
int
channel
,
msg_data_t
*
msg
)
{
if
(
is_initialized
==
0
)
{
is_initialized
=
1
;
init_msg_channel
();
}
if
(
channel
<
0
||
channel
>=
MSG_CHAN_MAX
||
msg
==
NULL
)
{
return
-
1
;
...
...
@@ -385,6 +412,12 @@ int msg_recv(int channel, msg_data_t *msg)
int
msg_send
(
int
channel
,
uint16_t
type
,
uint32_t
code
,
void
*
pad
,
int
len
)
{
if
(
is_initialized
==
0
)
{
is_initialized
=
1
;
init_msg_channel
();
}
if
(
channel
<
0
||
channel
>=
MSG_CHAN_MAX
||
(
len
>
0
&&
pad
==
NULL
))
{
return
-
1
;
...
...
@@ -393,8 +426,9 @@ int msg_send(int channel, uint16_t type, uint32_t code, void *pad, int len)
msg_data_t
msg
=
{
.
type
=
type
,
.
code
=
code
,
.
len
=
len
};
memcpy
((
void
*
)(
msg
.
pad
),
pad
,
len
);
.
len
=
len
,
};
memcpy
((
void
*
)
msg
.
pad
,
pad
,
msg
.
len
);
int
fd
=
open
(
msg_channel_paths
[
channel
],
O_WRONLY
);
if
(
fd
==
-
1
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment