This is an automated email from the ASF dual-hosted git repository. masaori pushed a commit to branch quic-latest in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/quic-latest by this push: new 77e9012 Cleanup QUICSimpleApp 77e9012 is described below commit 77e901243ebc3a5c24e9eed88c2a6d3676c91d81 Author: Masaori Koshiba <masa...@apache.org> AuthorDate: Tue Dec 12 11:20:02 2017 +0900 Cleanup QUICSimpleApp --- iocore/net/quic/QUICApplication.cc | 37 +++++++++++++------------------------ iocore/net/quic/QUICApplication.h | 4 +--- proxy/hq/QUICSimpleApp.cc | 31 +++++++++++++++++-------------- 3 files changed, 31 insertions(+), 41 deletions(-) diff --git a/iocore/net/quic/QUICApplication.cc b/iocore/net/quic/QUICApplication.cc index 5b8f3f4..b5b191d 100644 --- a/iocore/net/quic/QUICApplication.cc +++ b/iocore/net/quic/QUICApplication.cc @@ -37,9 +37,7 @@ QUICStreamIO::QUICStreamIO(QUICApplication *app, QUICStream *stream) : _stream(s this->_read_buffer_reader = _read_buffer->alloc_reader(); this->_write_buffer_reader = _write_buffer->alloc_reader(); - this->_read_vio = stream->do_io_read(app, INT64_MAX, this->_read_buffer); - this->_read_vio->buffer.reader_for(this->_read_buffer_reader); - + this->_read_vio = stream->do_io_read(app, INT64_MAX, this->_read_buffer); this->_write_vio = stream->do_io_write(app, INT64_MAX, this->_write_buffer_reader); } @@ -49,6 +47,12 @@ QUICStreamIO::read_avail() return this->_read_buffer_reader->read_avail(); } +bool +QUICStreamIO::is_read_avail_more_than(int64_t size) +{ + return this->_read_buffer_reader->is_read_avail_more_than(size); +} + int64_t QUICStreamIO::read(uint8_t *buf, int64_t len) { @@ -123,12 +127,6 @@ QUICStreamIO::get_transaction_id() const return this->_stream->id(); } -bool -QUICStreamIO::is_vio(VIO *vio) -{ - return (this->_read_vio == vio || this->_write_vio == vio); -} - // // QUICApplication // @@ -192,23 +190,14 @@ QUICApplication::_find_stream_io(QUICStreamId id) QUICStreamIO * QUICApplication::_find_stream_io(VIO *vio) { - for (auto i : this->_stream_map) { - if (i.second->is_vio(vio)) { - return i.second; - } + if (vio == nullptr) { + return nullptr; } - return nullptr; -} - -QUICStreamId -QUICApplication::_find_stream_id(VIO *vio) -{ - for (auto i : this->_stream_map) { - if (i.second->is_vio(vio)) { - return i.first; - } + QUICStream *stream = dynamic_cast<QUICStream *>(vio->vc_server); + if (stream == nullptr) { + return nullptr; } - return 0; + return this->_find_stream_io(stream->id()); } diff --git a/iocore/net/quic/QUICApplication.h b/iocore/net/quic/QUICApplication.h index f8a37aa..0f34c56 100644 --- a/iocore/net/quic/QUICApplication.h +++ b/iocore/net/quic/QUICApplication.h @@ -40,6 +40,7 @@ public: QUICStreamIO(QUICApplication *app, QUICStream *stream); int64_t read_avail(); + bool is_read_avail_more_than(int64_t size); int64_t read(uint8_t *buf, int64_t len); int64_t write(const uint8_t *buf, int64_t len); int64_t write(IOBufferReader *r, int64_t len = INT64_MAX, int64_t offset = 0); @@ -49,7 +50,6 @@ public: IOBufferReader *get_read_buffer_reader(); void shutdown(); uint32_t get_transaction_id() const; - bool is_vio(VIO *); private: QUICStream *_stream = nullptr; @@ -81,9 +81,7 @@ public: protected: QUICStreamIO *_find_stream_io(QUICStreamId id); - // TODO: return pair QUICStreamIO *_find_stream_io(VIO *vio); - QUICStreamId _find_stream_id(VIO *vio); QUICConnection *_client_qc = nullptr; diff --git a/proxy/hq/QUICSimpleApp.cc b/proxy/hq/QUICSimpleApp.cc index 6b9583b..310a5a0 100644 --- a/proxy/hq/QUICSimpleApp.cc +++ b/proxy/hq/QUICSimpleApp.cc @@ -56,34 +56,37 @@ QUICSimpleApp::main_event_handler(int event, Event *data) { Debug(tag, "%s", QUICDebugNames::vc_event(event)); - VIO *vio = reinterpret_cast<VIO *>(data); - + VIO *vio = reinterpret_cast<VIO *>(data); QUICStreamIO *stream_io = this->_find_stream_io(vio); - QUICStreamId stream_id = this->_find_stream_id(vio); if (stream_io == nullptr) { Debug(tag, "Unknown Stream"); return -1; } + QUICStreamId stream_id = stream_io->get_transaction_id(); + HQClientTransaction *txn = this->_client_session->get_transaction(stream_id); + switch (event) { case VC_EVENT_READ_READY: case VC_EVENT_READ_COMPLETE: { - // TODO: lookup transaction if support POST request - if (stream_io->read_avail()) { - HQClientTransaction *trans = new HQClientTransaction(this->_client_session, stream_io); - SCOPED_MUTEX_LOCK(lock, trans->mutex, this_ethread()); - - trans->new_transaction(); - } else { - Debug(tag, "No MSG"); + if (stream_io->is_read_avail_more_than(0)) { + if (txn == nullptr) { + txn = new HQClientTransaction(this->_client_session, stream_io); + SCOPED_MUTEX_LOCK(lock, txn->mutex, this_ethread()); + + txn->new_transaction(); + } else { + txn->handleEvent(event); + } + break; } - break; } case VC_EVENT_WRITE_READY: case VC_EVENT_WRITE_COMPLETE: { - HQClientTransaction *trans = this->_client_session->get_transaction(stream_id); - trans->handleEvent(event); + if (txn != nullptr) { + txn->handleEvent(event); + } break; } -- To stop receiving notification emails like this one, please contact ['"commits@trafficserver.apache.org" <commits@trafficserver.apache.org>'].