Skip to content

Commit 540bf58

Browse files
committed
[connection] move some connection finished handling to shared code
Change-Id: I2bcaf503d38cd5d0d9baf4150cd1f3982a559048
1 parent a147553 commit 540bf58

File tree

4 files changed

+23
-47
lines changed

4 files changed

+23
-47
lines changed

src/main/connection.c

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,25 @@
44

55
#define LI_CONNECTION_DEFAULT_CHUNKQUEUE_LIMIT (256*1024)
66

7-
static void con_iostream_close(liConnection *con) { /* force close */
8-
if (con->con_sock.callbacks) {
9-
con->info.aborted = TRUE;
10-
con->con_sock.callbacks->finish(con, TRUE);
11-
}
12-
LI_FORCE_ASSERT(NULL == con->con_sock.data);
13-
}
14-
static void con_iostream_shutdown(liConnection *con) { /* (try) regular shutdown */
15-
if (NULL != con->con_sock.raw_out) {
16-
con->con_sock.raw_out->out->is_closed = TRUE;
17-
li_stream_notify(con->con_sock.raw_out);
7+
static void con_iostream_close(liConnection *con, gboolean abort) {
8+
if (!abort) {
9+
/* proper close notification */
10+
if (NULL != con->con_sock.raw_out) {
11+
con->con_sock.raw_out->out->is_closed = TRUE;
12+
li_stream_notify(con->con_sock.raw_out);
13+
}
1814
}
1915

16+
con->info.aborted = abort;
17+
2018
if (con->con_sock.callbacks) {
21-
con->con_sock.callbacks->finish(con, FALSE);
19+
con->con_sock.callbacks->finish(con, abort);
2220
}
2321
LI_FORCE_ASSERT(NULL == con->con_sock.data);
22+
LI_FORCE_ASSERT(NULL == con->con_sock.callbacks);
23+
24+
li_stream_safe_reset_and_release(&con->con_sock.raw_out);
25+
li_stream_safe_reset_and_release(&con->con_sock.raw_in);
2426
}
2527

2628
static void connection_close(liConnection *con);
@@ -412,7 +414,7 @@ void li_connection_request_done(liConnection *con) {
412414
li_connection_reset_keep_alive(con);
413415
} else {
414416
con->state = LI_CON_STATE_CLOSE;
415-
con_iostream_shutdown(con);
417+
con_iostream_close(con, FALSE);
416418
li_connection_reset(con);
417419
}
418420
}
@@ -429,7 +431,7 @@ static void connection_close(liConnection *con) {
429431

430432
con->state = LI_CON_STATE_CLOSE;
431433

432-
con_iostream_close(con);
434+
con_iostream_close(con, TRUE);
433435

434436
li_plugins_handle_close(con);
435437

@@ -447,7 +449,7 @@ void li_connection_error(liConnection *con) {
447449

448450
con->state = LI_CON_STATE_CLOSE;
449451

450-
con_iostream_close(con);
452+
con_iostream_close(con, TRUE);
451453

452454
li_plugins_handle_close(con);
453455

@@ -565,7 +567,7 @@ void li_connection_reset(liConnection *con) {
565567
if (LI_CON_STATE_DEAD != con->state) {
566568
con->state = LI_CON_STATE_DEAD;
567569

568-
con_iostream_close(con);
570+
con_iostream_close(con, TRUE);
569571
li_stream_reset(&con->in);
570572
li_stream_reset(&con->out);
571573

@@ -593,7 +595,7 @@ static void li_connection_reset2(liConnection *con) {
593595
con->expect_100_cont = FALSE;
594596
con->out_has_all_data = FALSE;
595597

596-
con_iostream_close(con);
598+
con_iostream_close(con, TRUE);
597599

598600
li_server_socket_release(con->srv_sock);
599601
con->srv_sock = NULL;
@@ -653,7 +655,7 @@ static void li_connection_reset_keep_alive(liConnection *con) {
653655
con->keep_alive_data.max_idle = CORE_OPTION(LI_CORE_OPTION_MAX_KEEP_ALIVE_IDLE).number;
654656
if (con->keep_alive_data.max_idle == 0) {
655657
con->state = LI_CON_STATE_CLOSE;
656-
con_iostream_shutdown(con);
658+
con_iostream_close(con, FALSE);
657659
li_connection_reset(con);
658660
return;
659661
}

src/main/connection_http.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,14 @@ static void simple_tcp_io_cb(liIOStream *stream, liIOStreamEvent event) {
3838

3939
static void simple_tcp_finished(liConnection *con, gboolean aborted) {
4040
simple_tcp_connection *data = con->con_sock.data;
41-
liIOStream *stream;
4241
if (NULL == data) return;
4342

4443
data->con = NULL;
4544
con->con_sock.data = NULL;
4645
con->con_sock.callbacks = NULL;
4746

48-
stream = data->sock_stream;
49-
data->sock_stream = NULL;
50-
51-
li_stream_simple_socket_close(stream, aborted);
52-
li_iostream_release(stream);
53-
54-
{
55-
liStream *raw_out = con->con_sock.raw_out, *raw_in = con->con_sock.raw_in;
56-
con->con_sock.raw_out = con->con_sock.raw_in = NULL;
57-
if (NULL != raw_out) { li_stream_reset(raw_out); li_stream_release(raw_out); }
58-
if (NULL != raw_in) { li_stream_reset(raw_in); li_stream_release(raw_in); }
59-
}
47+
li_stream_simple_socket_close(data->sock_stream, aborted);
48+
li_iostream_safe_release(&data->sock_stream);
6049
}
6150

6251
static liThrottleState* simple_tcp_throttle_out(liConnection *con) {

src/modules/mod_gnutls.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -472,21 +472,13 @@ static void gnutls_tcp_finished(liConnection *con, gboolean aborted) {
472472
mod_connection_ctx *conctx = con->con_sock.data;
473473
UNUSED(aborted);
474474

475-
con->info.is_ssl = FALSE;
476475
con->con_sock.callbacks = NULL;
477476

478477
if (NULL != conctx) {
479478
LI_FORCE_ASSERT(con == conctx->con);
480479
close_cb(conctx->tls_filter, conctx);
481480
LI_FORCE_ASSERT(NULL == con->con_sock.data);
482481
}
483-
484-
{
485-
liStream *raw_out = con->con_sock.raw_out, *raw_in = con->con_sock.raw_in;
486-
con->con_sock.raw_out = con->con_sock.raw_in = NULL;
487-
if (NULL != raw_out) { li_stream_reset(raw_out); li_stream_release(raw_out); }
488-
if (NULL != raw_in) { li_stream_reset(raw_in); li_stream_release(raw_in); }
489-
}
490482
}
491483

492484
static liThrottleState* gnutls_tcp_throttle_out(liConnection *con) {

src/modules/mod_openssl.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,19 +163,12 @@ static void openssl_tcp_finished(liConnection *con, gboolean aborted) {
163163
openssl_connection_ctx *conctx = con->con_sock.data;
164164
UNUSED(aborted);
165165

166-
con->info.is_ssl = FALSE;
167166
con->con_sock.callbacks = NULL;
168167

169168
if (NULL != conctx) {
170169
LI_FORCE_ASSERT(con == conctx->con);
171170
close_cb(conctx->ssl_filter, conctx);
172-
}
173-
174-
{
175-
liStream *raw_out = con->con_sock.raw_out, *raw_in = con->con_sock.raw_in;
176-
con->con_sock.raw_out = con->con_sock.raw_in = NULL;
177-
if (NULL != raw_out) { li_stream_reset(raw_out); li_stream_release(raw_out); }
178-
if (NULL != raw_in) { li_stream_reset(raw_in); li_stream_release(raw_in); }
171+
LI_FORCE_ASSERT(NULL == con->con_sock.data);
179172
}
180173
}
181174

0 commit comments

Comments
 (0)