This is an automated email from the ASF dual-hosted git repository. masaori pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push: new 17f0e83 Cleanup Http2Stream 17f0e83 is described below commit 17f0e83620bf3ab2604e73fc7cd13d9e048513eb Author: Masaori Koshiba <masa...@apache.org> AuthorDate: Wed Feb 7 16:53:55 2018 +0900 Cleanup Http2Stream - Remove return value of Http2Stream::update_write_request(). Because return value is not used in most cases. And Http2Stream::do_io_write() can always return &write_vio where only the return value is used. - Http2Stream::update_write_request() returns immediately if there're no data to proceed - Make Http2Stream::send_response_body() private --- proxy/http2/Http2Stream.cc | 115 +++++++++++++++++++++++---------------------- proxy/http2/Http2Stream.h | 4 +- 2 files changed, 61 insertions(+), 58 deletions(-) diff --git a/proxy/http2/Http2Stream.cc b/proxy/http2/Http2Stream.cc index 7264afc..c847322 100644 --- a/proxy/http2/Http2Stream.cc +++ b/proxy/http2/Http2Stream.cc @@ -309,7 +309,10 @@ Http2Stream::do_io_write(Continuation *c, int64_t nbytes, IOBufferReader *abuffe write_vio.vc_server = this; write_vio.op = VIO::WRITE; response_reader = abuffer; - return update_write_request(abuffer, nbytes, false) ? &write_vio : nullptr; + + update_write_request(abuffer, nbytes, false); + + return &write_vio; } // Initiated from SM @@ -521,12 +524,11 @@ Http2Stream::restart_sending() this->send_response_body(true); } -bool +void Http2Stream::update_write_request(IOBufferReader *buf_reader, int64_t write_len, bool call_update) { - bool retval = true; if (!this->is_client_state_writeable() || closed || parent == nullptr || write_vio.mutex == nullptr) { - return retval; + return; } if (this->get_thread() != this_ethread()) { SCOPED_MUTEX_LOCK(stream_lock, this->mutex, this_ethread()); @@ -534,7 +536,7 @@ Http2Stream::update_write_request(IOBufferReader *buf_reader, int64_t write_len, // Send to the right thread cross_thread_event = this->get_thread()->schedule_imm(this, VC_EVENT_WRITE_READY, nullptr); } - return retval; + return; } ink_release_assert(this->get_thread() == this_ethread()); Http2ClientSession *parent = static_cast<Http2ClientSession *>(this->get_parent()); @@ -568,67 +570,68 @@ Http2Stream::update_write_request(IOBufferReader *buf_reader, int64_t write_len, ", reader.read_avail=%" PRId64, write_vio.nbytes, write_vio.ndone, write_vio.get_writer()->write_avail(), bytes_avail); - if (bytes_avail > 0 || is_done) { - // Process the new data - if (!this->response_header_done) { - // Still parsing the response_header - int bytes_used = 0; - int state = this->response_header.parse_resp(&http_parser, this->response_reader, &bytes_used, false); - // HTTPHdr::parse_resp() consumed the response_reader in above - write_vio.ndone += this->response_header.length_get(); - - switch (state) { - case PARSE_RESULT_DONE: { - this->response_header_done = true; - - // Schedule session shutdown if response header has "Connection: close" - MIMEField *field = this->response_header.field_find(MIME_FIELD_CONNECTION, MIME_LEN_CONNECTION); - if (field) { - int len; - const char *value = field->value_get(&len); - if (memcmp(HTTP_VALUE_CLOSE, value, HTTP_LEN_CLOSE) == 0) { - SCOPED_MUTEX_LOCK(lock, this->mutex, this_ethread()); - if (parent->connection_state.get_shutdown_state() == HTTP2_SHUTDOWN_NONE) { - parent->connection_state.set_shutdown_state(HTTP2_SHUTDOWN_NOT_INITIATED); - } + if (bytes_avail <= 0 && !is_done) { + return; + } + + // Process the new data + if (!this->response_header_done) { + // Still parsing the response_header + int bytes_used = 0; + int state = this->response_header.parse_resp(&http_parser, this->response_reader, &bytes_used, false); + // HTTPHdr::parse_resp() consumed the response_reader in above + write_vio.ndone += this->response_header.length_get(); + + switch (state) { + case PARSE_RESULT_DONE: { + this->response_header_done = true; + + // Schedule session shutdown if response header has "Connection: close" + MIMEField *field = this->response_header.field_find(MIME_FIELD_CONNECTION, MIME_LEN_CONNECTION); + if (field) { + int len; + const char *value = field->value_get(&len); + if (memcmp(HTTP_VALUE_CLOSE, value, HTTP_LEN_CLOSE) == 0) { + SCOPED_MUTEX_LOCK(lock, this->mutex, this_ethread()); + if (parent->connection_state.get_shutdown_state() == HTTP2_SHUTDOWN_NONE) { + parent->connection_state.set_shutdown_state(HTTP2_SHUTDOWN_NOT_INITIATED); } } + } - // Send the response header back - parent->connection_state.send_headers_frame(this); - - // See if the response is chunked. Set up the dechunking logic if it is - // Make sure to check if the chunk is complete and signal appropriately - this->response_initialize_data_handling(is_done); + // Send the response header back + parent->connection_state.send_headers_frame(this); - // If there is additional data, send it along in a data frame. Or if this was header only - // make sure to send the end of stream - if (this->response_is_data_available() || is_done) { - if ((write_vio.ntodo() + this->response_header.length_get()) == bytes_avail || is_done) { - this->mark_body_done(); - } + // See if the response is chunked. Set up the dechunking logic if it is + // Make sure to check if the chunk is complete and signal appropriately + this->response_initialize_data_handling(is_done); - this->send_response_body(call_update); + // If there is additional data, send it along in a data frame. Or if this was header only + // make sure to send the end of stream + if (this->response_is_data_available() || is_done) { + if ((write_vio.ntodo() + this->response_header.length_get()) == bytes_avail || is_done) { + this->mark_body_done(); } - break; - } - case PARSE_RESULT_CONT: - // Let it ride for next time - break; - default: - break; - } - } else { - if (write_vio.ntodo() == bytes_avail || is_done) { - this->mark_body_done(); - retval = false; - } - this->send_response_body(call_update); + this->send_response_body(call_update); + } + break; + } + case PARSE_RESULT_CONT: + // Let it ride for next time + break; + default: + break; } + } else { + if (write_vio.ntodo() == bytes_avail || is_done) { + this->mark_body_done(); + } + + this->send_response_body(call_update); } - return retval; + return; } void diff --git a/proxy/http2/Http2Stream.h b/proxy/http2/Http2Stream.h index 0fa8399..be4a12d 100644 --- a/proxy/http2/Http2Stream.h +++ b/proxy/http2/Http2Stream.h @@ -156,7 +156,7 @@ public: void terminate_if_possible(); void do_io_shutdown(ShutdownHowTo_t) override {} void update_read_request(int64_t read_len, bool send_update, bool check_eos = false); - bool update_write_request(IOBufferReader *buf_reader, int64_t write_len, bool send_update); + void update_write_request(IOBufferReader *buf_reader, int64_t write_len, bool send_update); void signal_write_event(bool call_update); void reenable(VIO *vio) override; virtual void transaction_done() override; @@ -169,7 +169,6 @@ public: } void restart_sending(); - void send_response_body(bool call_update); void push_promise(URL &url, const MIMEField *accept_encoding); // Stream level window size @@ -248,6 +247,7 @@ private: void response_process_data(bool &is_done); bool response_is_data_available() const; Event *send_tracked_event(Event *event, int send_event, VIO *vio); + void send_response_body(bool call_update); HTTPParser http_parser; ink_hrtime _start_time = 0; -- To stop receiving notification emails like this one, please contact masa...@apache.org.