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
17cfecc5
Commit
17cfecc5
authored
Feb 20, 2017
by
Sergey Lyubka
Committed by
Cesanta Bot
Feb 20, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mongoose examples fixes
PUBLISHED_FROM=b47a5b6987ee8d9e7c9bae2bd4d2943d2e7f76a9
parent
ebdd1876
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
4 deletions
+16
-4
Makefile
examples/captive_dns_server/Makefile
+0
-1
publish_subscribe.c
examples/publish_subscribe/publish_subscribe.c
+7
-0
simple_crawler.c
examples/simple_crawler/simple_crawler.c
+9
-3
No files found.
examples/captive_dns_server/Makefile
View file @
17cfecc5
PROG
=
captive_dns_server
PROG
=
captive_dns_server
MODULE_CFLAGS
=
-DMG_ENABLE_DNS_SERVER
-DMG_ENABLE_IPV6
MODULE_CFLAGS
=
-DMG_ENABLE_DNS_SERVER
-DMG_ENABLE_IPV6
SSL_LIB
=
openssl
include
../examples.mk
include
../examples.mk
examples/publish_subscribe/publish_subscribe.c
View file @
17cfecc5
...
@@ -36,9 +36,15 @@ static void server_handler(struct mg_connection *nc, int ev, void *p) {
...
@@ -36,9 +36,15 @@ static void server_handler(struct mg_connection *nc, int ev, void *p) {
struct
mg_connection
*
c
;
struct
mg_connection
*
c
;
for
(
c
=
mg_next
(
nc
->
mgr
,
NULL
);
c
!=
NULL
;
c
=
mg_next
(
nc
->
mgr
,
c
))
{
for
(
c
=
mg_next
(
nc
->
mgr
,
NULL
);
c
!=
NULL
;
c
=
mg_next
(
nc
->
mgr
,
c
))
{
if
(
!
(
c
->
flags
|=
MG_F_USER_2
))
continue
;
// Skip non-client connections
mg_send
(
c
,
io
->
buf
,
io
->
len
);
mg_send
(
c
,
io
->
buf
,
io
->
len
);
}
}
mbuf_remove
(
io
,
io
->
len
);
mbuf_remove
(
io
,
io
->
len
);
}
else
if
(
ev
==
MG_EV_ACCEPT
)
{
char
addr
[
32
];
mg_sock_addr_to_str
(
p
,
addr
,
sizeof
(
addr
),
MG_SOCK_STRINGIFY_IP
|
MG_SOCK_STRINGIFY_PORT
);
printf
(
"New client connected from %s
\n
"
,
addr
);
}
}
}
}
...
@@ -87,6 +93,7 @@ int main(int argc, char *argv[]) {
...
@@ -87,6 +93,7 @@ int main(int argc, char *argv[]) {
fprintf
(
stderr
,
"Cannot connect to port %s
\n
"
,
argv
[
1
]);
fprintf
(
stderr
,
"Cannot connect to port %s
\n
"
,
argv
[
1
]);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
server_conn
->
flags
|=
MG_F_USER_2
;
// Mark this as a client connection
// Create a socketpair and give one end to the thread that reads stdin
// Create a socketpair and give one end to the thread that reads stdin
mg_socketpair
(
fds
,
SOCK_STREAM
);
mg_socketpair
(
fds
,
SOCK_STREAM
);
...
...
examples/simple_crawler/simple_crawler.c
View file @
17cfecc5
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
#include "mongoose.h"
#include "../../../slre/slre.h"
#include "../../../slre/slre.h"
#include "mongoose.h"
static
const
char
*
initial_url
=
"http://test.mosquitto.org"
;
static
const
char
*
regex
=
"href=
\"
((https?://)[^
\\
s/'
\"
<>]+/?[^
\\
s'
\"
<>]*)"
;
static
const
char
*
regex
=
"href=
\"
((https?://)[^
\\
s/'
\"
<>]+/?[^
\\
s'
\"
<>]*)"
;
const
int
max_depth
=
2
;
const
int
max_depth
=
2
;
...
@@ -44,7 +45,7 @@ int main(void) {
...
@@ -44,7 +45,7 @@ int main(void) {
struct
mg_mgr
mgr
;
struct
mg_mgr
mgr
;
mg_mgr_init
(
&
mgr
,
NULL
);
mg_mgr_init
(
&
mgr
,
NULL
);
crawl_page
(
&
mgr
,
"http://www.simpleweb.org/"
,
~
0
,
0
);
crawl_page
(
&
mgr
,
initial_url
,
~
0
,
0
);
for
(;;)
{
for
(;;)
{
mg_mgr_poll
(
&
mgr
,
1000
);
mg_mgr_poll
(
&
mgr
,
1000
);
...
@@ -69,7 +70,12 @@ void crawl_page(struct mg_mgr *mgr, const char *url, size_t url_len,
...
@@ -69,7 +70,12 @@ void crawl_page(struct mg_mgr *mgr, const char *url, size_t url_len,
data
->
depth
=
depth
;
data
->
depth
=
depth
;
nc
=
mg_connect_http
(
mgr
,
event_handler
,
url
,
NULL
,
NULL
);
nc
=
mg_connect_http
(
mgr
,
event_handler
,
url
,
NULL
,
NULL
);
nc
->
user_data
=
data
;
if
(
nc
!=
NULL
)
{
nc
->
user_data
=
data
;
}
else
{
printf
(
"Error connecting to [%s]
\n
"
,
url
);
free
(
data
);
}
}
}
void
handle_reply
(
struct
mg_connection
*
nc
,
struct
http_message
*
hm
)
{
void
handle_reply
(
struct
mg_connection
*
nc
,
struct
http_message
*
hm
)
{
...
...
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