Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
Project
Project
Details
Activity
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
40ab4a8d
Commit
40ab4a8d
authored
Sep 29, 2013
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed websocket example logic when freeing the message, again!
parent
e84d0574
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
4 deletions
+8
-4
websocket.c
examples/websocket.c
+8
-4
No files found.
examples/websocket.c
View file @
40ab4a8d
...
...
@@ -19,7 +19,7 @@ static int event_handler(struct mg_event *event) {
}
else
{
static
const
char
*
server_ready_message
=
"server ready"
;
char
*
data
;
int
bits
,
len
;
int
bits
,
len
,
must_exit
=
0
;
// Handshake, and send initial server message
mg_websocket_handshake
(
event
->
conn
);
...
...
@@ -27,17 +27,21 @@ static int event_handler(struct mg_event *event) {
server_ready_message
,
strlen
(
server_ready_message
));
// Read messages sent by client. Echo them back.
while
((
len
=
mg_websocket_read
(
event
->
conn
,
&
bits
,
&
data
))
>
0
)
{
while
(
must_exit
==
0
&&
(
len
=
mg_websocket_read
(
event
->
conn
,
&
bits
,
&
data
))
>
0
)
{
printf
(
"got message: [%.*s]
\n
"
,
len
,
data
);
mg_websocket_write
(
event
->
conn
,
WEBSOCKET_OPCODE_TEXT
,
data
,
len
);
free
(
data
);
// It's our responsibility to free allocated message
// If the message is "exit", close the connection, exit the loop
if
(
memcmp
(
data
,
"exit"
,
4
)
==
0
)
{
mg_websocket_write
(
event
->
conn
,
WEBSOCKET_OPCODE_CONNECTION_CLOSE
,
""
,
0
);
break
;
must_exit
=
1
;
}
// It's our responsibility to free allocated message
free
(
data
);
}
}
return
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