Add a simple QuicTransport server for testing and demo purposes.
The server currently has two modes, echo and discard. I've changed the integration test to use the simple server instead of a session with a mock visitor.
This CL also adds some of the missing APIs and fixes some of the bugs I've found while doing this.
gfe-relnote: n/a (code not used)
PiperOrigin-RevId: 278456752
Change-Id: Idf9aa654aa0d66673f300f2f5425f0716d6c3e14
diff --git a/quic/quic_transport/quic_transport_stream.cc b/quic/quic_transport/quic_transport_stream.cc
index 9546119..61f4345 100644
--- a/quic/quic_transport/quic_transport_stream.cc
+++ b/quic/quic_transport/quic_transport_stream.cc
@@ -32,7 +32,21 @@
iovec iov;
iov.iov_base = buffer;
iov.iov_len = buffer_size;
- return sequencer()->Readv(&iov, 1);
+ const size_t result = sequencer()->Readv(&iov, 1);
+ if (sequencer()->IsClosed() && visitor_ != nullptr) {
+ visitor_->OnFinRead();
+ }
+ return result;
+}
+
+size_t QuicTransportStream::Read(std::string* output) {
+ const size_t old_size = output->size();
+ const size_t bytes_to_read = ReadableBytes();
+ output->resize(old_size + bytes_to_read);
+ size_t bytes_read = Read(&(*output)[old_size], bytes_to_read);
+ DCHECK_EQ(bytes_to_read, bytes_read);
+ output->resize(old_size + bytes_read);
+ return bytes_read;
}
bool QuicTransportStream::Write(QuicStringPiece data) {
@@ -40,6 +54,7 @@
return false;
}
+ // TODO(vasilvv): use WriteMemSlices()
WriteOrBufferData(data, /*fin=*/false, nullptr);
return true;
}
@@ -66,12 +81,21 @@
}
void QuicTransportStream::OnDataAvailable() {
+ if (sequencer()->IsClosed()) {
+ if (visitor_ != nullptr) {
+ visitor_->OnFinRead();
+ }
+ OnFinRead();
+ return;
+ }
+
+ if (visitor_ == nullptr) {
+ return;
+ }
if (ReadableBytes() == 0) {
return;
}
- if (visitor_ != nullptr) {
- visitor_->OnCanRead();
- }
+ visitor_->OnCanRead();
}
void QuicTransportStream::OnCanWriteNewData() {