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
8 years ago
by
Sergey Lyubka
Committed by
Cesanta Bot
8 years ago
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
MODULE_CFLAGS
=
-DMG_ENABLE_DNS_SERVER
-DMG_ENABLE_IPV6
SSL_LIB
=
openssl
include
../examples.mk
This diff is collapsed.
Click to expand it.
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) {
struct
mg_connection
*
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
);
}
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[]) {
fprintf
(
stderr
,
"Cannot connect to port %s
\n
"
,
argv
[
1
]);
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
mg_socketpair
(
fds
,
SOCK_STREAM
);
...
...
This diff is collapsed.
Click to expand it.
examples/simple_crawler/simple_crawler.c
View file @
17cfecc5
#include <stdio.h>
#include <string.h>
#include "mongoose.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'
\"
<>]*)"
;
const
int
max_depth
=
2
;
...
...
@@ -44,7 +45,7 @@ int main(void) {
struct
mg_mgr
mgr
;
mg_mgr_init
(
&
mgr
,
NULL
);
crawl_page
(
&
mgr
,
"http://www.simpleweb.org/"
,
~
0
,
0
);
crawl_page
(
&
mgr
,
initial_url
,
~
0
,
0
);
for
(;;)
{
mg_mgr_poll
(
&
mgr
,
1000
);
...
...
@@ -69,7 +70,12 @@ void crawl_page(struct mg_mgr *mgr, const char *url, size_t url_len,
data
->
depth
=
depth
;
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
)
{
...
...
This diff is collapsed.
Click to expand it.
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