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
8354319e
Commit
8354319e
authored
Apr 14, 2017
by
Ruslan Valiullin
Committed by
Cesanta Bot
Apr 14, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
websocket_chat added MG_EV_HTTP_REQUEST
PUBLISHED_FROM=6f5e1b4a97ada21025f892d3348808bffb469dfa
parent
f9596cc1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
1 deletion
+8
-1
Makefile
examples/websocket_chat/Makefile
+1
-1
websocket_chat.c
examples/websocket_chat/websocket_chat.c
+7
-0
No files found.
examples/websocket_chat/Makefile
View file @
8354319e
PROG
=
websocket_chat
PROG
=
websocket_chat
MODULE_CFLAGS
=
-DMG_ENABLE_FILESYSTEM
=
0
MODULE_CFLAGS
=
-DMG_ENABLE_FILESYSTEM
=
1
include
../examples.mk
include
../examples.mk
examples/websocket_chat/websocket_chat.c
View file @
8354319e
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
static
sig_atomic_t
s_signal_received
=
0
;
static
sig_atomic_t
s_signal_received
=
0
;
static
const
char
*
s_http_port
=
"8000"
;
static
const
char
*
s_http_port
=
"8000"
;
static
struct
mg_serve_http_opts
s_http_server_opts
;
static
void
signal_handler
(
int
sig_num
)
{
static
void
signal_handler
(
int
sig_num
)
{
signal
(
sig_num
,
signal_handler
);
// Reinstantiate signal handler
signal
(
sig_num
,
signal_handler
);
// Reinstantiate signal handler
...
@@ -46,6 +47,10 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
...
@@ -46,6 +47,10 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
broadcast
(
nc
,
d
);
broadcast
(
nc
,
d
);
break
;
break
;
}
}
case
MG_EV_HTTP_REQUEST
:
{
mg_serve_http
(
nc
,
(
struct
http_message
*
)
ev_data
,
s_http_server_opts
);
break
;
}
case
MG_EV_CLOSE
:
{
case
MG_EV_CLOSE
:
{
/* Disconnect. Tell everybody. */
/* Disconnect. Tell everybody. */
if
(
is_websocket
(
nc
))
{
if
(
is_websocket
(
nc
))
{
...
@@ -69,6 +74,8 @@ int main(void) {
...
@@ -69,6 +74,8 @@ int main(void) {
nc
=
mg_bind
(
&
mgr
,
s_http_port
,
ev_handler
);
nc
=
mg_bind
(
&
mgr
,
s_http_port
,
ev_handler
);
mg_set_protocol_http_websocket
(
nc
);
mg_set_protocol_http_websocket
(
nc
);
s_http_server_opts
.
document_root
=
"."
;
// Serve current directory
s_http_server_opts
.
enable_directory_listing
=
"yes"
;
printf
(
"Started on port %s
\n
"
,
s_http_port
);
printf
(
"Started on port %s
\n
"
,
s_http_port
);
while
(
s_signal_received
==
0
)
{
while
(
s_signal_received
==
0
)
{
...
...
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