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
c16612ee
Commit
c16612ee
authored
Aug 05, 2016
by
Paul Sokolovsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extmod/modwebrepl: Factor out "GET" iteration to write_file_chunk().
parent
7fb31479
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
9 deletions
+17
-9
extmod/modwebrepl.c
extmod/modwebrepl.c
+17
-9
No files found.
extmod/modwebrepl.c
View file @
c16612ee
...
@@ -111,6 +111,22 @@ STATIC mp_obj_t webrepl_make_new(const mp_obj_type_t *type, size_t n_args, size_
...
@@ -111,6 +111,22 @@ STATIC mp_obj_t webrepl_make_new(const mp_obj_type_t *type, size_t n_args, size_
return
o
;
return
o
;
}
}
STATIC
int
write_file_chunk
(
mp_obj_webrepl_t
*
self
)
{
const
mp_stream_p_t
*
file_stream
=
mp_get_stream_raise
(
self
->
cur_file
,
MP_STREAM_OP_READ
|
MP_STREAM_OP_WRITE
|
MP_STREAM_OP_IOCTL
);
byte
readbuf
[
2
+
256
];
int
err
;
mp_uint_t
out_sz
=
file_stream
->
read
(
self
->
cur_file
,
readbuf
+
2
,
sizeof
(
readbuf
)
-
2
,
&
err
);
if
(
out_sz
==
MP_STREAM_ERROR
)
{
return
out_sz
;
}
readbuf
[
0
]
=
out_sz
;
readbuf
[
1
]
=
out_sz
>>
8
;
DEBUG_printf
(
"webrepl: Sending %d bytes of file
\n
"
,
out_sz
);
write_webrepl
(
self
->
sock
,
readbuf
,
2
+
out_sz
);
return
out_sz
;
}
STATIC
void
handle_op
(
mp_obj_webrepl_t
*
self
)
{
STATIC
void
handle_op
(
mp_obj_webrepl_t
*
self
)
{
mp_obj_t
open_args
[
2
]
=
{
mp_obj_t
open_args
[
2
]
=
{
mp_obj_new_str
(
self
->
hdr
.
fname
,
strlen
(
self
->
hdr
.
fname
),
false
),
mp_obj_new_str
(
self
->
hdr
.
fname
,
strlen
(
self
->
hdr
.
fname
),
false
),
...
@@ -122,8 +138,6 @@ STATIC void handle_op(mp_obj_webrepl_t *self) {
...
@@ -122,8 +138,6 @@ STATIC void handle_op(mp_obj_webrepl_t *self) {
}
}
self
->
cur_file
=
mp_builtin_open
(
2
,
open_args
,
(
mp_map_t
*
)
&
mp_const_empty_map
);
self
->
cur_file
=
mp_builtin_open
(
2
,
open_args
,
(
mp_map_t
*
)
&
mp_const_empty_map
);
const
mp_stream_p_t
*
file_stream
=
mp_get_stream_raise
(
self
->
cur_file
,
MP_STREAM_OP_READ
|
MP_STREAM_OP_WRITE
|
MP_STREAM_OP_IOCTL
);
#if 0
#if 0
struct mp_stream_seek_t seek = { .offset = self->hdr.offset, .whence = 0 };
struct mp_stream_seek_t seek = { .offset = self->hdr.offset, .whence = 0 };
...
@@ -137,17 +151,11 @@ STATIC void handle_op(mp_obj_webrepl_t *self) {
...
@@ -137,17 +151,11 @@ STATIC void handle_op(mp_obj_webrepl_t *self) {
if
(
self
->
hdr
.
type
==
PUT_FILE
)
{
if
(
self
->
hdr
.
type
==
PUT_FILE
)
{
self
->
data_to_recv
=
self
->
hdr
.
size
;
self
->
data_to_recv
=
self
->
hdr
.
size
;
}
else
if
(
self
->
hdr
.
type
==
GET_FILE
)
{
}
else
if
(
self
->
hdr
.
type
==
GET_FILE
)
{
byte
readbuf
[
2
+
256
];
int
err
;
// TODO: It's not ideal that we block connection while sending file
// TODO: It's not ideal that we block connection while sending file
// and don't process any input.
// and don't process any input.
while
(
1
)
{
while
(
1
)
{
mp_uint_t
out_sz
=
file_stream
->
read
(
self
->
cur_file
,
readbuf
+
2
,
sizeof
(
readbuf
)
-
2
,
&
err
);
mp_uint_t
out_sz
=
write_file_chunk
(
self
);
assert
(
out_sz
!=
MP_STREAM_ERROR
);
assert
(
out_sz
!=
MP_STREAM_ERROR
);
readbuf
[
0
]
=
out_sz
;
readbuf
[
1
]
=
out_sz
>>
8
;
DEBUG_printf
(
"webrepl: Sending %d bytes of file
\n
"
,
out_sz
);
write_webrepl
(
self
->
sock
,
readbuf
,
2
+
out_sz
);
if
(
out_sz
==
0
)
{
if
(
out_sz
==
0
)
{
break
;
break
;
}
}
...
...
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