<commit_before>/*
 * Copyright 2014 Facebook, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <thrift/lib/cpp2/async/HeaderClientChannel.h>
#include <thrift/lib/cpp2/async/ResponseChannel.h>
#include <thrift/lib/cpp2/async/GssSaslClient.h>
#include <thrift/lib/cpp/EventHandlerBase.h>
#include <thrift/lib/cpp/transport/TTransportException.h>
#include <folly/io/Cursor.h>

#include <utility>

using std::unique_ptr;
using std::pair;
using folly::IOBuf;
using folly::IOBufQueue;
using folly::make_unique;
using namespace apache::thrift::transport;
using folly::EventBase;
using apache::thrift::async::TAsyncTransport;
using folly::RequestContext;
using HResClock = std::chrono::high_resolution_clock;
using Us = std::chrono::microseconds;

namespace apache { namespace thrift {

template class ChannelCallbacks::TwowayCallback<HeaderClientChannel>;

HeaderClientChannel::HeaderClientChannel(
  const std::shared_ptr<TAsyncTransport>& transport)
    : HeaderClientChannel(
        std::shared_ptr<Cpp2Channel>(
            Cpp2Channel::newChannel(transport,
                make_unique<ClientFramingHandler>(*this))))
{}

HeaderClientChannel::HeaderClientChannel(
  const std::shared_ptr<Cpp2Channel>& cpp2Channel)
    : sendSeqId_(0)
    , sendSecurityPendingSeqId_(0)
    , closeCallback_(nullptr)
    , timeout_(0)
    , timeoutSASL_(500)
    , handshakeMessagesSent_(0)
    , keepRegisteredForClose_(true)
    , saslClientCallback_(*this)
    , cpp2Channel_(cpp2Channel)
    , protocolId_(apache::thrift::protocol::T_COMPACT_PROTOCOL) {}

void HeaderClientChannel::setTimeout(uint32_t ms) {
  getTransport()->setSendTimeout(ms);
  timeout_ = ms;
}

void HeaderClientChannel::setSaslTimeout(uint32_t ms) {
  timeoutSASL_ = ms;
}

void HeaderClientChannel::closeNow() {
  saslClientCallback_.cancelTimeout();
  if (saslClient_) {
    saslClient_->detachEventBase();
  }

  cpp2Channel_->closeNow();
}

void HeaderClientChannel::destroy() {
  closeNow();
  folly::DelayedDestruction::destroy();
}
<commit_msg>Make HeaderClientChannel::closeNow() not detach saslClient<commit_after>/*
 * Copyright 2014 Facebook, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <thrift/lib/cpp2/async/HeaderClientChannel.h>
#include <thrift/lib/cpp2/async/ResponseChannel.h>
#include <thrift/lib/cpp2/async/GssSaslClient.h>
#include <thrift/lib/cpp/EventHandlerBase.h>
#include <thrift/lib/cpp/transport/TTransportException.h>
#include <folly/io/Cursor.h>

#include <utility>

using std::unique_ptr;
using std::pair;
using folly::IOBuf;
using folly::IOBufQueue;
using folly::make_unique;
using namespace apache::thrift::transport;
using folly::EventBase;
using apache::thrift::async::TAsyncTransport;
using folly::RequestContext;
using HResClock = std::chrono::high_resolution_clock;
using Us = std::chrono::microseconds;

namespace apache { namespace thrift {

template class ChannelCallbacks::TwowayCallback<HeaderClientChannel>;

HeaderClientChannel::HeaderClientChannel(
  const std::shared_ptr<TAsyncTransport>& transport)
    : HeaderClientChannel(
        std::shared_ptr<Cpp2Channel>(
            Cpp2Channel::newChannel(transport,
                make_unique<ClientFramingHandler>(*this))))
{}

HeaderClientChannel::HeaderClientChannel(
  const std::shared_ptr<Cpp2Channel>& cpp2Channel)
    : sendSeqId_(0)
    , sendSecurityPendingSeqId_(0)
    , closeCallback_(nullptr)
    , timeout_(0)
    , timeoutSASL_(500)
    , handshakeMessagesSent_(0)
    , keepRegisteredForClose_(true)
    , saslClientCallback_(*this)
    , cpp2Channel_(cpp2Channel)
    , protocolId_(apache::thrift::protocol::T_COMPACT_PROTOCOL) {}

void HeaderClientChannel::setTimeout(uint32_t ms) {
  getTransport()->setSendTimeout(ms);
  timeout_ = ms;
}

void HeaderClientChannel::setSaslTimeout(uint32_t ms) {
  timeoutSASL_ = ms;
}

void HeaderClientChannel::closeNow() {
  cpp2Channel_->closeNow();
}

void HeaderClientChannel::destroy() {
  closeNow();
  saslClientCallback_.cancelTimeout();
  if (saslClient_) {
    saslClient_->detachEventBase();
  }
  folly::DelayedDestruction::destroy();
}

{'fraction_non_alphanumeric': 0.11302307391474384, 'fraction_numerical': 0.01134141572154869, 'mean_word_length': 5.425879396984925, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4930501', 'n_tokens_mistral': 1578, 'n_tokens_neox': 1575, 'n_words': 350}