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
d5f0c87b
Commit
d5f0c87b
authored
Apr 04, 2019
by
Damien George
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extmod/modlwip: Abort TCP conns that didn't close cleanly in a while.
parent
358364b4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
0 deletions
+16
-0
extmod/modlwip.c
extmod/modlwip.c
+16
-0
No files found.
extmod/modlwip.c
View file @
d5f0c87b
...
@@ -57,6 +57,10 @@
...
@@ -57,6 +57,10 @@
#define DEBUG_printf(...) (void)0
#define DEBUG_printf(...) (void)0
#endif
#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,
// All socket options should be globally distinct,
// because we ignore option levels for efficiency.
// because we ignore option levels for efficiency.
#define IP_ADD_MEMBERSHIP 0x400
#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
...
@@ -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
;
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
)
{
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
);
lwip_socket_obj_t
*
socket
=
MP_OBJ_TO_PTR
(
self_in
);
mp_uint_t
ret
;
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_
...
@@ -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)
// 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
);
tcp_recv
(
socket
->
pcb
.
tcp
,
NULL
);
switch
(
socket
->
type
)
{
switch
(
socket
->
type
)
{
...
@@ -1408,6 +1421,9 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
...
@@ -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
)
{
if
(
tcp_close
(
socket
->
pcb
.
tcp
)
!=
ERR_OK
)
{
DEBUG_printf
(
"lwip_close: had to call tcp_abort()
\n
"
);
DEBUG_printf
(
"lwip_close: had to call tcp_abort()
\n
"
);
tcp_abort
(
socket
->
pcb
.
tcp
);
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
;
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