Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
mongoose
Commits
fc37b081
Commit
fc37b081
authored
Jan 14, 2014
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
URI handler status code drives streaming behavior
parent
3aaf47d4
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
9 deletions
+67
-9
file.c
examples/file.c
+47
-0
mongoose.c
mongoose.c
+20
-9
No files found.
examples/file.c
0 → 100644
View file @
fc37b081
#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
;
}
}
return
n
<
sizeof
(
buf
)
?
1
:
0
;
}
int
main
(
void
)
{
struct
mg_server
*
server
;
// Create and configure the server
server
=
mg_create_server
(
NULL
);
mg_set_option
(
server
,
"listening_port"
,
"8080"
);
mg_add_uri_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
mg_destroy_server
(
&
server
);
return
0
;
}
mongoose.c
View file @
fc37b081
...
...
@@ -1896,6 +1896,19 @@ static void ping_idle_websocket_connection(struct connection *conn, time_t t) {
#define ping_idle_websocket_connection(conn, t)
#endif // !NO_WEBSOCKET
static
void
write_terminating_chunk
(
struct
connection
*
conn
)
{
mg_write
(
&
conn
->
mg_conn
,
"0
\r\n\r\n
"
,
5
);
}
static
void
call_uri_handler
(
struct
connection
*
conn
)
{
if
(
conn
->
endpoint
.
uh
->
handler
(
&
conn
->
mg_conn
))
{
if
(
conn
->
flags
&
CONN_HEADERS_SENT
)
{
write_terminating_chunk
(
conn
);
}
close_local_endpoint
(
conn
);
}
}
static
void
write_to_client
(
struct
connection
*
conn
)
{
struct
iobuf
*
io
=
&
conn
->
remote_iobuf
;
int
n
=
conn
->
ssl
==
NULL
?
send
(
conn
->
client_sock
,
io
->
buf
,
io
->
len
,
0
)
:
...
...
@@ -1915,6 +1928,12 @@ static void write_to_client(struct connection *conn) {
io
->
len
-=
n
;
conn
->
num_bytes_sent
+=
n
;
}
if
(
conn
->
endpoint_type
==
EP_USER
)
{
conn
->
mg_conn
.
wsbits
=
conn
->
flags
&
CONN_CLOSE
?
1
:
0
;
call_uri_handler
(
conn
);
}
if
(
io
->
len
==
0
&&
conn
->
flags
&
CONN_SPOOL_DONE
)
{
conn
->
flags
|=
CONN_CLOSE
;
}
...
...
@@ -2163,10 +2182,6 @@ static void open_file_endpoint(struct connection *conn, const char *path,
#endif // NO_FILESYSTEM
static
void
write_terminating_chunk
(
struct
connection
*
conn
)
{
mg_write
(
&
conn
->
mg_conn
,
"0
\r\n\r\n
"
,
5
);
}
static
void
call_uri_handler_if_data_is_buffered
(
struct
connection
*
conn
)
{
struct
iobuf
*
loc
=
&
conn
->
local_iobuf
;
struct
mg_connection
*
c
=
&
conn
->
mg_conn
;
...
...
@@ -2178,11 +2193,7 @@ static void call_uri_handler_if_data_is_buffered(struct connection *conn) {
}
else
#endif
if
(
loc
->
len
>=
c
->
content_len
)
{
conn
->
endpoint
.
uh
->
handler
(
c
);
if
(
conn
->
flags
&
CONN_HEADERS_SENT
)
{
write_terminating_chunk
(
conn
);
}
close_local_endpoint
(
conn
);
call_uri_handler
(
conn
);
}
}
...
...
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