Skip to content

Commit

Permalink
net: add some assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
Chilledheart committed Sep 29, 2024
1 parent 50ac41c commit f69422c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/cli/cli_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ void CliConnection::SendIfNotProcessing() {
// cipher_visitor_interface
//
bool CliConnection::on_received_data(std::shared_ptr<IOBuf> buf) {
if (buf->empty()) {
return false;
}
downstream_.push_back(buf);
return true;
}
Expand Down Expand Up @@ -1560,6 +1563,7 @@ void CliConnection::WriteUpstreamInPipe() {
wbytes_transferred += written;
bytes_read_without_yielding += written;
if (UNLIKELY(ec == asio::error::try_again || ec == asio::error::would_block)) {
DCHECK_EQ(0u, written);
break;
}
VLOG(2) << "Connection (client) " << connection_id() << " upstream: sent request (pipe): " << written << " bytes"
Expand Down
4 changes: 4 additions & 0 deletions src/net/padding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ std::shared_ptr<net::IOBuf> RemovePadding(std::shared_ptr<net::IOBuf> buf, asio:
}
const uint8_t* p = buf->data();
size_t payload_size = (p[0] << 8) + p[1];
if (payload_size == 0) {
ec = asio::error::invalid_argument;
return nullptr;
}
size_t padding_size = p[2];
if (buf->length() < kPaddingHeaderSize + payload_size + padding_size) {
ec = asio::error::try_again;
Expand Down
6 changes: 5 additions & 1 deletion src/server/server_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ void ServerConnection::SendIfNotProcessing() {
//
bool ServerConnection::on_received_data(std::shared_ptr<IOBuf> buf) {
if (state_ == state_stream) {
if (buf->empty()) {
return false;
}
upstream_.push_back(buf);
} else if (state_ == state_handshake) {
if (handshake_) {
Expand Down Expand Up @@ -415,7 +418,7 @@ bool ServerConnection::OnDataForStream(StreamId stream_id, absl::string_view dat
if (ec) {
return true;
}
DCHECK(buf);
DCHECK(buf && buf->length());
upstream_.push_back(buf);
++num_padding_recv_;
}
Expand Down Expand Up @@ -1340,6 +1343,7 @@ void ServerConnection::WriteUpstreamInPipe() {
buf->trimStart(written);
wbytes_transferred += written;
if (ec == asio::error::try_again || ec == asio::error::would_block) {
DCHECK_EQ(0u, written);
break;
}
VLOG(2) << "Connection (server) " << connection_id() << " upstream: sent request (pipe): " << written << " bytes"
Expand Down

0 comments on commit f69422c

Please sign in to comment.