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
b830f4c6
Commit
b830f4c6
authored
Apr 17, 2016
by
Paul Sokolovsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extmod/modlwip: lwip_tcp_send(): Full error handling.
parent
d49a5470
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
7 deletions
+17
-7
extmod/modlwip.c
extmod/modlwip.c
+17
-7
No files found.
extmod/modlwip.c
View file @
b830f4c6
...
...
@@ -409,15 +409,27 @@ STATIC mp_uint_t lwip_udp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_
return
(
mp_uint_t
)
result
;
}
// For use in stream virtual methods
#define STREAM_ERROR_CHECK(socket) \
if (socket->state < 0) { \
*_errno = error_lookup_table[-socket->state]; \
return MP_STREAM_ERROR; \
} \
assert(socket->pcb.tcp);
// Helper function for send/sendto to handle TCP packets
STATIC
mp_uint_t
lwip_tcp_send
(
lwip_socket_obj_t
*
socket
,
const
byte
*
buf
,
mp_uint_t
len
,
int
*
_errno
)
{
// Check for any pending errors
STREAM_ERROR_CHECK
(
socket
);
u16_t
available
=
tcp_sndbuf
(
socket
->
pcb
.
tcp
);
if
(
available
==
0
)
{
// Non-blocking socket
if
(
socket
->
timeout
==
0
)
{
*
_errno
=
EAGAIN
;
return
-
1
;
return
MP_STREAM_ERROR
;
}
mp_uint_t
start
=
mp_hal_ticks_ms
();
...
...
@@ -430,15 +442,13 @@ STATIC mp_uint_t lwip_tcp_send(lwip_socket_obj_t *socket, const byte *buf, mp_ui
while
(
socket
->
state
>=
STATE_CONNECTED
&&
(
available
=
tcp_sndbuf
(
socket
->
pcb
.
tcp
))
<
16
)
{
if
(
socket
->
timeout
!=
-
1
&&
mp_hal_ticks_ms
()
-
start
>
socket
->
timeout
)
{
*
_errno
=
ETIMEDOUT
;
return
-
1
;
return
MP_STREAM_ERROR
;
}
poll_sockets
();
}
if
(
socket
->
state
<
0
)
{
*
_errno
=
error_lookup_table
[
-
socket
->
state
];
return
-
1
;
}
// While we waited, something could happen
STREAM_ERROR_CHECK
(
socket
);
}
u16_t
write_len
=
MIN
(
available
,
len
);
...
...
@@ -447,7 +457,7 @@ STATIC mp_uint_t lwip_tcp_send(lwip_socket_obj_t *socket, const byte *buf, mp_ui
if
(
err
!=
ERR_OK
)
{
*
_errno
=
error_lookup_table
[
-
err
];
return
-
1
;
return
MP_STREAM_ERROR
;
}
return
write_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