Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
88ae2eca
Commit
88ae2eca
authored
Dec 28, 2017
by
Dmitry Frank
Committed by
Cesanta Bot
Dec 29, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Drain rx_chain before closing the connection
PUBLISHED_FROM=08eee4052dd9bbc364875a577409cb78665dee30
parent
85d19dad
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
16 deletions
+44
-16
mongoose.c
mongoose.c
+44
-16
No files found.
mongoose.c
View file @
88ae2eca
...
...
@@ -14792,7 +14792,9 @@ struct mg_lwip_conn_state {
/* Last SSL write size, for retries. */
int
last_ssl_write_size
;
/* Whether MG_SIG_RECV is already pending for this connection */
int
recv_pending
;
int
recv_pending
:
1
;
/* Whether the connection is about to close, just `rx_chain` needs to drain */
int
draining_rx_chain
:
1
;
};
enum
mg_sig_type
{
...
...
@@ -14951,7 +14953,16 @@ static err_t mg_lwip_tcp_recv_cb(void *arg, struct tcp_pcb *tpcb,
DBG
((
"%p %p %u %d"
,
nc
,
tpcb
,
(
p
!=
NULL
?
p
->
tot_len
:
0
),
err
));
if
(
p
==
NULL
)
{
if
(
nc
!=
NULL
&&
!
(
nc
->
flags
&
MG_F_CLOSE_IMMEDIATELY
))
{
struct
mg_lwip_conn_state
*
cs
=
(
struct
mg_lwip_conn_state
*
)
nc
->
sock
;
if
(
cs
->
rx_chain
!=
NULL
)
{
/*
* rx_chain still contains non-consumed data, don't close the
* connection
*/
cs
->
draining_rx_chain
=
1
;
}
else
{
mg_lwip_post_signal
(
MG_SIG_CLOSE_CONN
,
nc
);
}
}
else
{
/* Tombstoned connection, do nothing. */
}
...
...
@@ -14988,23 +14999,12 @@ static err_t mg_lwip_tcp_recv_cb(void *arg, struct tcp_pcb *tpcb,
return
ERR_OK
;
}
static
void
mg_lwip_
handle_recv
_tcp
(
struct
mg_connection
*
nc
)
{
static
void
mg_lwip_
consume_rx_chain
_tcp
(
struct
mg_connection
*
nc
)
{
struct
mg_lwip_conn_state
*
cs
=
(
struct
mg_lwip_conn_state
*
)
nc
->
sock
;
#if MG_ENABLE_SSL
if
(
nc
->
flags
&
MG_F_SSL
)
{
if
(
nc
->
flags
&
MG_F_SSL_HANDSHAKE_DONE
)
{
mg_lwip_ssl_recv
(
nc
);
}
else
{
mg_lwip_ssl_do_hs
(
nc
);
}
return
;
}
#endif
mgos_lock
();
while
(
cs
->
rx_chain
!=
NULL
&&
nc
->
recv_mbuf
.
len
<
nc
->
recv_mbuf_limit
)
{
struct
pbuf
*
seg
=
cs
->
rx_chain
;
size_t
seg_len
=
(
seg
->
len
-
cs
->
rx_offset
);
size_t
buf_avail
=
(
nc
->
recv_mbuf_limit
-
nc
->
recv_mbuf
.
len
);
size_t
len
=
MIN
(
seg_len
,
buf_avail
);
...
...
@@ -15027,6 +15027,21 @@ static void mg_lwip_handle_recv_tcp(struct mg_connection *nc) {
mgos_lock
();
}
mgos_unlock
();
}
static
void
mg_lwip_handle_recv_tcp
(
struct
mg_connection
*
nc
)
{
#if MG_ENABLE_SSL
if
(
nc
->
flags
&
MG_F_SSL
)
{
if
(
nc
->
flags
&
MG_F_SSL_HANDSHAKE_DONE
)
{
mg_lwip_ssl_recv
(
nc
);
}
else
{
mg_lwip_ssl_do_hs
(
nc
);
}
return
;
}
#endif
mg_lwip_consume_rx_chain_tcp
(
nc
);
if
(
nc
->
send_mbuf
.
len
>
0
)
{
mg_lwip_mgr_schedule_poll
(
nc
->
mgr
);
...
...
@@ -15647,7 +15662,7 @@ void mg_ev_mgr_lwip_process_signals(struct mg_mgr *mgr) {
break
;
}
case
MG_SIG_CLOSE_CONN
:
{
nc
->
flags
|=
MG_F_
CLOSE_IMMEDIATELY
;
nc
->
flags
|=
MG_F_
SEND_AND_CLOSE
;
mg_close_conn
(
nc
);
break
;
}
...
...
@@ -15758,6 +15773,19 @@ time_t mg_lwip_if_poll(struct mg_iface *iface, int timeout_ms) {
}
num_timers
++
;
}
if
(
nc
->
sock
!=
INVALID_SOCKET
)
{
/* Try to consume data from cs->rx_chain */
mg_lwip_consume_rx_chain_tcp
(
nc
);
/*
* If the connection is about to close, and rx_chain is finally empty,
* send the MG_SIG_CLOSE_CONN signal
*/
if
(
cs
->
draining_rx_chain
&&
cs
->
rx_chain
==
NULL
)
{
mg_lwip_post_signal
(
MG_SIG_CLOSE_CONN
,
nc
);
}
}
}
#if 0
DBG(("end poll @%u, %d conns, %d timers (min %u), next in %d ms",
...
...
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