Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
d5f0c87b
Commit
d5f0c87b
authored
5 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
extmod/modlwip: Abort TCP conns that didn't close cleanly in a while.
parent
358364b4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
extmod/modlwip.c
+16
-0
16 additions, 0 deletions
extmod/modlwip.c
with
16 additions
and
0 deletions
extmod/modlwip.c
+
16
−
0
View file @
d5f0c87b
...
...
@@ -57,6 +57,10 @@
#define DEBUG_printf(...) (void)0
#endif
// Timeout between closing a TCP socket and doing a tcp_abort on that
// socket, if the connection isn't closed cleanly in that time.
#define MICROPY_PY_LWIP_TCP_CLOSE_TIMEOUT_MS (10000)
// All socket options should be globally distinct,
// because we ignore option levels for efficiency.
#define IP_ADD_MEMBERSHIP 0x400
...
...
@@ -1342,6 +1346,13 @@ STATIC mp_uint_t lwip_socket_write(mp_obj_t self_in, const void *buf, mp_uint_t
return
MP_STREAM_ERROR
;
}
STATIC
err_t
_lwip_tcp_close_poll
(
void
*
arg
,
struct
tcp_pcb
*
pcb
)
{
// Connection has not been cleanly closed so just abort it to free up memory
tcp_poll
(
pcb
,
NULL
,
0
);
tcp_abort
(
pcb
);
return
ERR_OK
;
}
STATIC
mp_uint_t
lwip_socket_ioctl
(
mp_obj_t
self_in
,
mp_uint_t
request
,
uintptr_t
arg
,
int
*
errcode
)
{
lwip_socket_obj_t
*
socket
=
MP_OBJ_TO_PTR
(
self_in
);
mp_uint_t
ret
;
...
...
@@ -1401,6 +1412,8 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
}
// Deregister callback (pcb.tcp is set to NULL below so must deregister now)
tcp_arg
(
socket
->
pcb
.
tcp
,
NULL
);
tcp_err
(
socket
->
pcb
.
tcp
,
NULL
);
tcp_recv
(
socket
->
pcb
.
tcp
,
NULL
);
switch
(
socket
->
type
)
{
...
...
@@ -1408,6 +1421,9 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
if
(
tcp_close
(
socket
->
pcb
.
tcp
)
!=
ERR_OK
)
{
DEBUG_printf
(
"lwip_close: had to call tcp_abort()
\n
"
);
tcp_abort
(
socket
->
pcb
.
tcp
);
}
else
{
// If connection not cleanly closed after timeout then abort the connection
tcp_poll
(
socket
->
pcb
.
tcp
,
_lwip_tcp_close_poll
,
MICROPY_PY_LWIP_TCP_CLOSE_TIMEOUT_MS
/
500
);
}
break
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment