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
2848a613
Commit
2848a613
authored
5 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
extmod/modlwip: Free any stored incoming bufs/connections on TCP error.
parent
490e0f39
No related branches found
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
+27
-22
27 additions, 22 deletions
extmod/modlwip.c
with
27 additions
and
22 deletions
extmod/modlwip.c
+
27
−
22
View file @
2848a613
...
@@ -323,6 +323,30 @@ STATIC struct tcp_pcb *volatile *lwip_socket_incoming_array(lwip_socket_obj_t *s
...
@@ -323,6 +323,30 @@ STATIC struct tcp_pcb *volatile *lwip_socket_incoming_array(lwip_socket_obj_t *s
}
}
}
}
STATIC
void
lwip_socket_free_incoming
(
lwip_socket_obj_t
*
socket
)
{
bool
socket_is_listener
=
socket
->
type
==
MOD_NETWORK_SOCK_STREAM
&&
socket
->
pcb
.
tcp
->
state
==
LISTEN
;
if
(
!
socket_is_listener
)
{
if
(
socket
->
incoming
.
pbuf
!=
NULL
)
{
pbuf_free
(
socket
->
incoming
.
pbuf
);
socket
->
incoming
.
pbuf
=
NULL
;
}
}
else
{
uint8_t
alloc
=
socket
->
incoming
.
connection
.
alloc
;
struct
tcp_pcb
*
volatile
*
tcp_array
=
lwip_socket_incoming_array
(
socket
);
for
(
uint8_t
i
=
0
;
i
<
alloc
;
++
i
)
{
// Deregister callback and abort
if
(
tcp_array
[
i
]
!=
NULL
)
{
tcp_poll
(
tcp_array
[
i
],
NULL
,
0
);
tcp_abort
(
tcp_array
[
i
]);
tcp_array
[
i
]
=
NULL
;
}
}
}
}
/*******************************************************************************/
/*******************************************************************************/
// Callback functions for the lwIP raw API.
// Callback functions for the lwIP raw API.
...
@@ -356,6 +380,8 @@ STATIC void _lwip_udp_incoming(void *arg, struct udp_pcb *upcb, struct pbuf *p,
...
@@ -356,6 +380,8 @@ STATIC void _lwip_udp_incoming(void *arg, struct udp_pcb *upcb, struct pbuf *p,
STATIC
void
_lwip_tcp_error
(
void
*
arg
,
err_t
err
)
{
STATIC
void
_lwip_tcp_error
(
void
*
arg
,
err_t
err
)
{
lwip_socket_obj_t
*
socket
=
(
lwip_socket_obj_t
*
)
arg
;
lwip_socket_obj_t
*
socket
=
(
lwip_socket_obj_t
*
)
arg
;
// Free any incoming buffers or connections that are stored
lwip_socket_free_incoming
(
socket
);
// Pass the error code back via the connection variable.
// Pass the error code back via the connection variable.
socket
->
state
=
err
;
socket
->
state
=
err
;
// If we got here, the lwIP stack either has deallocated or will deallocate the pcb.
// If we got here, the lwIP stack either has deallocated or will deallocate the pcb.
...
@@ -1368,8 +1394,6 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
...
@@ -1368,8 +1394,6 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
}
}
}
else
if
(
request
==
MP_STREAM_CLOSE
)
{
}
else
if
(
request
==
MP_STREAM_CLOSE
)
{
bool
socket_is_listener
=
false
;
if
(
socket
->
pcb
.
tcp
==
NULL
)
{
if
(
socket
->
pcb
.
tcp
==
NULL
)
{
MICROPY_PY_LWIP_EXIT
MICROPY_PY_LWIP_EXIT
return
0
;
return
0
;
...
@@ -1380,9 +1404,6 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
...
@@ -1380,9 +1404,6 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
switch
(
socket
->
type
)
{
switch
(
socket
->
type
)
{
case
MOD_NETWORK_SOCK_STREAM
:
{
case
MOD_NETWORK_SOCK_STREAM
:
{
if
(
socket
->
pcb
.
tcp
->
state
==
LISTEN
)
{
socket_is_listener
=
true
;
}
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
);
...
@@ -1392,25 +1413,9 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
...
@@ -1392,25 +1413,9 @@ STATIC mp_uint_t lwip_socket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
case
MOD_NETWORK_SOCK_DGRAM
:
udp_remove
(
socket
->
pcb
.
udp
);
break
;
case
MOD_NETWORK_SOCK_DGRAM
:
udp_remove
(
socket
->
pcb
.
udp
);
break
;
//case MOD_NETWORK_SOCK_RAW: raw_remove(socket->pcb.raw); break;
//case MOD_NETWORK_SOCK_RAW: raw_remove(socket->pcb.raw); break;
}
}
lwip_socket_free_incoming
(
socket
);
socket
->
pcb
.
tcp
=
NULL
;
socket
->
pcb
.
tcp
=
NULL
;
socket
->
state
=
_ERR_BADF
;
socket
->
state
=
_ERR_BADF
;
if
(
!
socket_is_listener
)
{
if
(
socket
->
incoming
.
pbuf
!=
NULL
)
{
pbuf_free
(
socket
->
incoming
.
pbuf
);
socket
->
incoming
.
pbuf
=
NULL
;
}
}
else
{
uint8_t
alloc
=
socket
->
incoming
.
connection
.
alloc
;
struct
tcp_pcb
*
volatile
*
tcp_array
=
lwip_socket_incoming_array
(
socket
);
for
(
uint8_t
i
=
0
;
i
<
alloc
;
++
i
)
{
// Deregister callback and abort
if
(
tcp_array
[
i
]
!=
NULL
)
{
tcp_poll
(
tcp_array
[
i
],
NULL
,
0
);
tcp_abort
(
tcp_array
[
i
]);
tcp_array
[
i
]
=
NULL
;
}
}
}
ret
=
0
;
ret
=
0
;
}
else
{
}
else
{
...
...
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