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
5571d66a
Commit
5571d66a
authored
Dec 20, 2023
by
马伊齐
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
自动格式化
parent
41a4b49e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
14 deletions
+14
-14
sock_msg.c
lib/sock_msg.c
+14
-14
No files found.
lib/sock_msg.c
View file @
5571d66a
...
@@ -16,14 +16,11 @@
...
@@ -16,14 +16,11 @@
#include <sys/shm.h>
#include <sys/shm.h>
#define SHM_KEY 1234
#define SHM_KEY 1234
int
msgid
=
-
1
;
// 全局变量,用于存储消息队列ID
int
msgid
=
-
1
;
// 全局变量,用于存储消息队列ID
int
shmid
;
int
shmid
;
messageQueue
*
queue
;
messageQueue
*
queue
;
// 全局数组来保存socket信息
// 全局数组来保存socket信息
socket_info_t
sockets
[
MAX_CLIENTS
+
1
]
=
{
0
};
socket_info_t
sockets
[
MAX_CLIENTS
+
1
]
=
{
0
};
...
@@ -284,9 +281,10 @@ int msg_local_send(uint16_t type, uint32_t code, void *pad, int len)
...
@@ -284,9 +281,10 @@ int msg_local_send(uint16_t type, uint32_t code, void *pad, int len)
int
msg_local_ssignal_init
(
void
)
int
msg_local_ssignal_init
(
void
)
{
{
// 获取已存在的共享内存
// 获取已存在的共享内存
if
((
shmid
=
shmget
(
SHM_KEY
,
sizeof
(
int
),
IPC_CREAT
|
0666
))
<
0
)
{
if
((
shmid
=
shmget
(
SHM_KEY
,
sizeof
(
int
),
IPC_CREAT
|
0666
))
<
0
)
{
perror
(
"shmget"
);
perror
(
"shmget"
);
return
-
1
;
return
-
1
;
}
}
...
@@ -304,7 +302,8 @@ int msg_local_rsignal_init(void)
...
@@ -304,7 +302,8 @@ int msg_local_rsignal_init(void)
{
{
shmid
=
shmget
(
SHM_KEY
,
sizeof
(
int
),
0666
);
shmid
=
shmget
(
SHM_KEY
,
sizeof
(
int
),
0666
);
// 获取已存在的共享内存
// 获取已存在的共享内存
if
((
shmid
=
shmget
(
SHM_KEY
,
sizeof
(
int
),
0666
))
<
0
)
{
if
((
shmid
=
shmget
(
SHM_KEY
,
sizeof
(
int
),
0666
))
<
0
)
{
perror
(
"shmget"
);
perror
(
"shmget"
);
return
-
1
;
return
-
1
;
}
}
...
@@ -316,7 +315,8 @@ int msg_local_rsignal_init(void)
...
@@ -316,7 +315,8 @@ int msg_local_rsignal_init(void)
}
}
}
}
int
msg_local_send_pulse
(
uint16_t
type
,
uint32_t
code
)
{
int
msg_local_send_pulse
(
uint16_t
type
,
uint32_t
code
)
{
if
(
queue
->
rear
==
queue
->
front
)
if
(
queue
->
rear
==
queue
->
front
)
{
{
...
@@ -335,13 +335,14 @@ int msg_local_send_pulse(uint16_t type, uint32_t code) {
...
@@ -335,13 +335,14 @@ int msg_local_send_pulse(uint16_t type, uint32_t code) {
{
{
queue
->
mQueue
[
queue
->
front
].
type
=
type
;
queue
->
mQueue
[
queue
->
front
].
type
=
type
;
queue
->
mQueue
[
queue
->
front
].
code
=
code
;
queue
->
mQueue
[
queue
->
front
].
code
=
code
;
queue
->
front
=
(
queue
->
front
+
1
)
%
MAX_QSIZE
;
queue
->
front
=
(
queue
->
front
+
1
)
%
MAX_QSIZE
;
return
0
;
return
0
;
}
}
}
}
int
msg_local_recv_pulse
(
uint16_t
*
type
,
uint32_t
*
code
)
{
int
msg_local_recv_pulse
(
uint16_t
*
type
,
uint32_t
*
code
)
{
if
(
queue
->
rear
==
-
1
)
if
(
queue
->
rear
==
-
1
)
{
{
printf
(
"Null signal queue
\n
"
);
printf
(
"Null signal queue
\n
"
);
...
@@ -360,8 +361,7 @@ int msg_local_recv_pulse(uint16_t *type, uint32_t *code) {
...
@@ -360,8 +361,7 @@ int msg_local_recv_pulse(uint16_t *type, uint32_t *code) {
*
code
=
queue
->
mQueue
[
queue
->
rear
].
code
;
*
code
=
queue
->
mQueue
[
queue
->
rear
].
code
;
queue
->
rear
=
(
queue
->
rear
+
1
)
%
MAX_QSIZE
;
queue
->
rear
=
(
queue
->
rear
+
1
)
%
MAX_QSIZE
;
return
0
;
return
0
;
}
}
}
}
int
msg_recv
(
int
channel
,
msg_data_t
*
msg
)
int
msg_recv
(
int
channel
,
msg_data_t
*
msg
)
...
...
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