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
464c7731
Commit
464c7731
authored
Jun 03, 2014
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Amended file sending example
parent
f51ca8d5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
36 deletions
+14
-36
Makefile
examples/Makefile
+4
-1
file.c
examples/file.c
+10
-35
No files found.
examples/Makefile
View file @
464c7731
...
...
@@ -50,6 +50,9 @@ upload: upload.c ../mongoose.c
auth
:
auth.c ../mongoose.c
$(CC)
auth.c ../mongoose.c
$(OUT)
$(CFLAGS)
file
:
file.c ../mongoose.c
$(CC)
file.c ../mongoose.c
$(OUT)
$(CFLAGS)
form
:
form.c ../mongoose.c
$(CC)
form.c ../mongoose.c
$(OUT)
$(CFLAGS)
...
...
@@ -68,4 +71,4 @@ u:
./
$@
clean
:
-
@
$(RM)
hello mjpg upload post websocket auth server multi_threaded proxy websocket_html.c
*
.exe
*
.dSYM
*
.obj .
*
o u a.out
-
@
$(RM)
hello mjpg upload post websocket auth
file
server multi_threaded proxy websocket_html.c
*
.exe
*
.dSYM
*
.obj .
*
o u a.out
examples/file.c
View file @
464c7731
#include <stdio.h>
#include <string.h>
#include "mongoose.h"
static
int
index_html
(
struct
mg_connection
*
conn
)
{
FILE
*
fp
=
(
FILE
*
)
conn
->
connection_param
;
char
buf
[
200
];
size_t
n
=
0
;
if
(
fp
==
NULL
)
{
fp
=
fopen
(
"../mongoose.c"
,
"r"
);
conn
->
connection_param
=
(
void
*
)
fp
;
}
if
(
fp
!=
NULL
)
{
n
=
fread
(
buf
,
1
,
sizeof
(
buf
),
fp
);
mg_send_data
(
conn
,
buf
,
n
);
if
(
n
<
sizeof
(
buf
)
||
conn
->
wsbits
!=
0
)
{
fclose
(
fp
);
conn
->
connection_param
=
NULL
;
}
static
int
ev_handler
(
struct
mg_connection
*
conn
,
enum
mg_event
ev
)
{
switch
(
ev
)
{
case
MG_REQUEST
:
mg_send_file
(
conn
,
"file.c"
);
return
MG_MORE
;
// It is important to return MG_MORE after mg_send_file!
case
MG_AUTH
:
return
MG_TRUE
;
default:
return
MG_FALSE
;
}
return
n
<
sizeof
(
buf
)
?
MG_REQUEST_PROCESSED
:
MG_REQUEST_CALL_AGAIN
;
}
int
main
(
void
)
{
struct
mg_server
*
server
;
// Create and configure the server
server
=
mg_create_server
(
NULL
);
struct
mg_server
*
server
=
mg_create_server
(
NULL
,
ev_handler
);
mg_set_option
(
server
,
"listening_port"
,
"8080"
);
mg_set_request_handler
(
server
,
index_html
);
// Serve request. Hit Ctrl-C to terminate the program
printf
(
"Starting on port %s
\n
"
,
mg_get_option
(
server
,
"listening_port"
));
for
(;;)
{
mg_poll_server
(
server
,
1000
);
}
// Cleanup, and free server instance
for
(;;)
mg_poll_server
(
server
,
1000
);
mg_destroy_server
(
&
server
);
return
0
;
}
}
\ No newline at end of file
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