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
6f946f5e
Commit
6f946f5e
authored
May 10, 2013
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
websocket code fix,
https://github.com/valenok/mongoose/pull/146
parent
39cd5b83
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
22 deletions
+30
-22
index.html
examples/websocket_html_root/index.html
+6
-6
mongoose.c
mongoose.c
+24
-16
No files found.
examples/websocket_html_root/index.html
View file @
6f946f5e
<!DOCTYPE html>
<!DOCTYPE html>
<meta
charset=
"utf-8"
/>
<meta
charset=
"utf-8"
/>
<title>
WebSocket Test
</title>
<title>
WebSocket Test
</title>
<script
language=
"javascript"
type=
"text/javascript"
>
<script
language=
"javascript"
type=
"text/javascript"
>
var
writeToScreen
=
function
(
message
)
{
var
writeToScreen
=
function
(
message
)
{
...
@@ -29,9 +29,9 @@
...
@@ -29,9 +29,9 @@
writeToScreen
(
'<span style="color: red; ">ERROR: </span> '
+
ev
.
data
);
writeToScreen
(
'<span style="color: red; ">ERROR: </span> '
+
ev
.
data
);
};
};
};
};
</script>
</script>
<style>
div
{
font
:
small
Verdana
;
}
</style>
<style>
div
{
font
:
small
Verdana
;
}
</style>
<h2>
Mongoose WebSocket Test
</h2>
<h2>
Mongoose WebSocket Test
</h2>
<div
style=
"width: 400px; color: #aaa; padding: 1em; "
>
<div
style=
"width: 400px; color: #aaa; padding: 1em; "
>
This page code creates websocket to the URI "/foo",
This page code creates websocket to the URI "/foo",
...
@@ -40,5 +40,5 @@
...
@@ -40,5 +40,5 @@
receiving the "exit" message.
receiving the "exit" message.
</div>
</div>
<div
id=
"output"
></div>
<div
id=
"output"
></div>
</html>
</html>
mongoose.c
View file @
6f946f5e
...
@@ -1509,6 +1509,26 @@ static int pull(FILE *fp, struct mg_connection *conn, char *buf, int len) {
...
@@ -1509,6 +1509,26 @@ static int pull(FILE *fp, struct mg_connection *conn, char *buf, int len) {
return
conn
->
ctx
->
stop_flag
?
-
1
:
nread
;
return
conn
->
ctx
->
stop_flag
?
-
1
:
nread
;
}
}
static
int
pull_all
(
FILE
*
fp
,
struct
mg_connection
*
conn
,
char
*
buf
,
int
len
)
{
int
n
,
nread
=
0
;
while
(
len
>
0
)
{
n
=
pull
(
fp
,
conn
,
buf
+
nread
,
len
);
if
(
n
<
0
)
{
nread
=
n
;
// Propagate the error
break
;
}
else
if
(
n
==
0
)
{
break
;
// No more data to read
}
else
{
conn
->
consumed_content
+=
n
;
nread
+=
n
;
len
-=
n
;
}
}
return
nread
;
}
int
mg_read
(
struct
mg_connection
*
conn
,
void
*
buf
,
size_t
len
)
{
int
mg_read
(
struct
mg_connection
*
conn
,
void
*
buf
,
size_t
len
)
{
int
n
,
buffered_len
,
nread
;
int
n
,
buffered_len
,
nread
;
const
char
*
body
;
const
char
*
body
;
...
@@ -1536,20 +1556,8 @@ int mg_read(struct mg_connection *conn, void *buf, size_t len) {
...
@@ -1536,20 +1556,8 @@ int mg_read(struct mg_connection *conn, void *buf, size_t len) {
}
}
// We have returned all buffered data. Read new data from the remote socket.
// We have returned all buffered data. Read new data from the remote socket.
while
(
len
>
0
)
{
n
=
pull_all
(
NULL
,
conn
,
(
char
*
)
buf
,
(
int
)
len
);
n
=
pull
(
NULL
,
conn
,
(
char
*
)
buf
,
(
int
)
len
);
nread
=
n
>=
0
?
nread
+
n
:
n
;
if
(
n
<
0
)
{
nread
=
n
;
// Propagate the error
break
;
}
else
if
(
n
==
0
)
{
break
;
// No more data to read
}
else
{
buf
=
(
char
*
)
buf
+
n
;
conn
->
consumed_content
+=
n
;
nread
+=
n
;
len
-=
n
;
}
}
}
}
return
nread
;
return
nread
;
}
}
...
@@ -3841,8 +3849,8 @@ static void read_websocket(struct mg_connection *conn) {
...
@@ -3841,8 +3849,8 @@ static void read_websocket(struct mg_connection *conn) {
len
=
body_len
-
header_len
;
len
=
body_len
-
header_len
;
memcpy
(
data
,
buf
+
header_len
,
len
);
memcpy
(
data
,
buf
+
header_len
,
len
);
// TODO: handle pull error
// TODO: handle pull error
pull
(
NULL
,
conn
,
data
+
len
,
data_len
-
len
);
pull
_all
(
NULL
,
conn
,
data
+
len
,
data_len
-
len
);
conn
->
data_len
=
0
;
conn
->
data_len
=
conn
->
request_len
;
}
else
{
}
else
{
len
=
data_len
+
header_len
;
len
=
data_len
+
header_len
;
memcpy
(
data
,
buf
+
header_len
,
data_len
);
memcpy
(
data
,
buf
+
header_len
,
data_len
);
...
...
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