write_end_stream_(false), current_write_end_stream_(false), dispatch_buffered_data_(false),
// deletion). Hence the assert above. However, call close() here just to be completely sure that
void ConnectionImpl::addFilter(FilterSharedPtr filter) { filter_manager_.addFilter(filter); }
bool ConnectionImpl::initializeReadFilters() { return filter_manager_.initializeReadFilters(); }
ENVOY_CONN_LOG_EVENT(debug, "connection_closing", "Not closing conn, socket is not open",
closeThroughFilterManager(ConnectionCloseAction{ConnectionEvent::LocalClose, false, type});
ENVOY_CONN_LOG_EVENT(debug, "connection_closing", "closing data_to_write={} type={}", *this,
// An example of this condition manifests when a downstream connection is closed early by Envoy,
if (buffer_high_watermark_timer_ == nullptr || !buffer_high_watermark_timer_->enabled()) {
void ConnectionImpl::closeConnectionImmediately() { closeSocket(ConnectionEvent::LocalClose); }
// invalid. For this call instead of plumbing through logic that will immediately indicate that a
// connect failed, we will just ignore the noDelay() call if the socket is invalid since error is
ENVOY_CONN_LOG(trace, "readDisable: disable={} disable_count={} state={} buffer_length={}", *this,
// closed TCP connections in the sense that we assume that a remote FIN means the remote intends a
void ConnectionImpl::write(Buffer::Instance& data, bool end_stream, bool through_filter_chain) {
// end_stream with no data is harmless. This catches misuse of the API that could result in data
ENVOY_CONN_LOG(trace, "writing {} bytes, end_stream {}", *this, data.length(), end_stream);
// TODO(mattklein123): All data currently gets moved from the source buffer to the write buffer.
// ever changed, read the comment in SslSocket::doWrite() VERY carefully. That code assumes that
// we never change existing write_buffer_ chain elements between calls to SSL_write(). That code
// asynchronously, we have the option of either setting the watermarks aggressively, and regularly
// based on watermarks until 2x the data is buffered in the common case. Given these are all soft
// |limit| bytes through the socket, passing |limit| bytes to the connection and the immediately
// It's possible for a write event callback to close the socket (which will cause fd_ to be -1).
// 1) There was a call to setTransportSocketIsReadable(), for example if a raw buffer socket ceded
// Do not clear transport_wants_read_ when returning early; the early return skips the transport
// Clear transport_wants_read_ just before the call to doRead. This is the only way to ensure that
// the transport socket read resumption happens as requested; onReadReady() returns early without
int rc = socket_->getSocketOption(SOL_SOCKET, SO_PEERCRED, &ucred, &ucred_size).return_value_;
socket_->getSocketOption(SOL_SOCKET, SO_ERROR, &error, &error_size).return_value_ == 0, "");
ASSERT(!result.end_stream_read_); // The interface guarantees that only read operations set this.
// NOTE: If the delayed_close_timer_ is set, it must only trigger after a delayed_close_timeout_
ASSERT(bothSidesHalfClosed() || delayed_close_state_ == DelayedCloseState::CloseAfterFlush);
bool ConnectionImpl::setSocketOption(Network::SocketOptionName name, absl::Span<uint8_t> value) {
os << spaces << "ConnectionImpl " << this << DUMP_MEMBER(connecting_) << DUMP_MEMBER(bind_error_)
: ConnectionImpl(dispatcher, std::move(socket), std::move(transport_socket), stream_info,
stream_info_.setConnectionTerminationDetails(kTransportSocketConnectTimeoutTerminationDetails);
: ClientConnectionImpl(dispatcher, std::make_unique<ClientSocketImpl>(remote_address, options),
: ConnectionImpl(dispatcher, std::move(socket), std::move(transport_socket), stream_info_,
// destroyed. We need to write the access log here because the StreamInfo is owned by this class,
stream_info_.upstreamInfo()->upstreamTiming().onUpstreamConnectStart(dispatcher_.timeSource());
stream_info_.upstreamInfo()->upstreamTiming().onUpstreamConnectComplete(dispatcher_.timeSource());