Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
micropython
Commits
f38e8f52
Commit
f38e8f52
authored
Apr 09, 2016
by
Paul Sokolovsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extmod/modwebsocket: Record current fragment type (binary/text/etc.)
Also, handle continuation frames (untested).
parent
5b1c2217
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
0 deletions
+24
-0
extmod/modwebsocket.c
extmod/modwebsocket.c
+24
-0
No files found.
extmod/modwebsocket.c
View file @
f38e8f52
...
...
@@ -37,6 +37,12 @@
#if MICROPY_PY_WEBSOCKET
enum
{
FRAME_HEADER
,
FRAME_OPT
,
PAYLOAD
};
#define FRAME_OPCODE_MASK 0x0f
enum
{
FRAME_CONT
,
FRAME_TXT
,
FRAME_BIN
,
FRAME_CLOSE
=
0x8
,
FRAME_PING
,
FRAME_PONG
};
enum
{
BLOCKING_WRITE
=
1
};
typedef
struct
_mp_obj_websocket_t
{
...
...
@@ -50,6 +56,8 @@ typedef struct _mp_obj_websocket_t {
byte
buf_pos
;
byte
buf
[
6
];
byte
opts
;
// Copy of current frame's flags
byte
ws_flags
;
}
mp_obj_websocket_t
;
STATIC
mp_obj_t
websocket_make_new
(
const
mp_obj_type_t
*
type
,
size_t
n_args
,
size_t
n_kw
,
const
mp_obj_t
*
args
)
{
...
...
@@ -87,8 +95,24 @@ STATIC mp_uint_t websocket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int
switch
(
self
->
state
)
{
case
FRAME_HEADER
:
{
// TODO: Split frame handling below is untested so far, so conservatively disable it
assert
(
self
->
buf
[
0
]
&
0x80
);
// "Control frames MAY be injected in the middle of a fragmented message."
// So, they must be processed before data frames (and not alter
// self->ws_flags)
if
((
self
->
buf
[
0
]
&
FRAME_OPCODE_MASK
)
>=
FRAME_CLOSE
)
{
// TODO: implement
assert
(
0
);
}
if
((
self
->
buf
[
0
]
&
FRAME_OPCODE_MASK
)
==
FRAME_CONT
)
{
// Preserve previous frame type
self
->
ws_flags
=
(
self
->
ws_flags
&
FRAME_OPCODE_MASK
)
|
(
self
->
buf
[
0
]
&
~
FRAME_OPCODE_MASK
);
}
else
{
self
->
ws_flags
=
self
->
buf
[
0
];
}
// Reset mask in case someone will use "simplified" protocol
// without masks.
memset
(
self
->
mask
,
0
,
sizeof
(
self
->
mask
));
...
...
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