From 37b4f3a6444c25ad5c5eab89c9c00651c7e798c5 Mon Sep 17 00:00:00 2001 From: Lu Qiuwen Date: Tue, 16 Oct 2018 20:01:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E7=94=B1=E4=BA=8EHTTP?= =?UTF-8?q?=E6=B5=81=E5=BC=8F=E6=9E=84=E5=BB=BA=E5=BA=94=E7=AD=94=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E7=94=B1=E4=BA=8E=E7=9C=9F=E5=AE=9E=E5=BA=94=E7=AD=94?= =?UTF-8?q?=E6=99=9A=E4=BA=8E=E6=9E=84=E5=BB=BA=E5=BA=94=E7=AD=94=E5=88=B0?= =?UTF-8?q?=E8=BE=BE=E8=A7=A6=E5=8F=91=E7=9A=84=E9=97=AE=E9=A2=98=20*=20?= =?UTF-8?q?=E5=8E=9F=E5=AE=9E=E7=8E=B0=E5=9C=A8=E7=9C=9F=E5=AE=9E=E5=BA=94?= =?UTF-8?q?=E7=AD=94=E6=99=9A=E4=BA=8E=E6=9E=84=E5=BB=BA=E5=BA=94=E7=AD=94?= =?UTF-8?q?=E5=88=B0=E8=BE=BE=E6=97=B6=EF=BC=8C=E4=BB=8D=E7=84=B6=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E6=B5=81=E5=BC=8FTCP=E5=86=99=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=EF=BC=9B=20*=20=E7=8E=B0=E4=BF=AE=E6=AD=A3=E4=B8=BA=E8=AF=A5?= =?UTF-8?q?=E6=83=85=E5=86=B5=E6=97=B6=EF=BC=8C=E7=9B=B4=E6=8E=A5=E5=8F=91?= =?UTF-8?q?=E9=80=81=E5=AE=8C=E6=95=B4=E7=9A=84=E6=9E=84=E5=BB=BA=E5=BA=94?= =?UTF-8?q?=E7=AD=94=E8=80=8C=E4=B8=8D=E6=98=AF=E6=B5=81=E5=BC=8F=E5=86=99?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platform/src/tcp_stream.cpp | 1 + plugin/protocol/http/src/http_entry.cpp | 12 +++++++++--- plugin/protocol/http/src/http_half.cpp | 3 +++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/platform/src/tcp_stream.cpp b/platform/src/tcp_stream.cpp index 986dab3..b115476 100644 --- a/platform/src/tcp_stream.cpp +++ b/platform/src/tcp_stream.cpp @@ -155,6 +155,7 @@ struct tfe_stream_write_ctx * tfe_stream_write_frag_start(const struct tfe_strea { return NULL; } + this_conn->w_ctx.dir = dir; this_conn->w_ctx._stream = _stream; this_conn->on_writing = 1; diff --git a/plugin/protocol/http/src/http_entry.cpp b/plugin/protocol/http/src/http_entry.cpp index aa9c82e..6769875 100644 --- a/plugin/protocol/http/src/http_entry.cpp +++ b/plugin/protocol/http/src/http_entry.cpp @@ -87,9 +87,15 @@ static int __write_http_half_to_line(const struct tfe_stream * stream, * and has been call body_begin, construct the header */ if (hf_private->evbuf_body != NULL && hf_private->write_ctx == NULL) { - /* Alloc stream write ctx */ - hf_private->write_ctx = tfe_stream_write_frag_start(stream, dir); - if (unlikely(hf_private->write_ctx == NULL)) return -1; + printf("frag write start, stream = %p, hf_private = %p\n", stream, hf_private); + + /* Still need to send data(not call body_end()), need to write frag start + * Otherwise, means the body is ready, send out directly without frag */ + if(hf_private->message_status < STATUS_COMPLETE) + { + hf_private->write_ctx = tfe_stream_write_frag_start(stream, dir); + assert(hf_private->write_ctx != NULL); + } ret = __write_http_half(hf_private, stream, dir); if (unlikely(ret < 0)) return ret; diff --git a/plugin/protocol/http/src/http_half.cpp b/plugin/protocol/http/src/http_half.cpp index af3a836..d208c64 100644 --- a/plugin/protocol/http/src/http_half.cpp +++ b/plugin/protocol/http/src/http_half.cpp @@ -656,6 +656,8 @@ int hf_ops_body_end(struct tfe_http_half * half) hf_private->body_status = STATUS_COMPLETE; hf_private->message_status = STATUS_COMPLETE; + + printf("frag write end, stream = %p, hf_private = %p\n", hf_private->session->hc_private->stream, hf_private); return 0; } @@ -853,6 +855,7 @@ void hs_ops_response_set(struct tfe_http_session * session, struct tfe_http_half assert(hs_private->hf_private_resp_user == NULL); hs_private->hf_private_resp_user = hf_private; + hf_private->session = hs_private; } struct tfe_http_half * hs_ops_request_create(struct tfe_http_session * session,