<commit_before>/*
 * Copyright 2014-present 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.
 */

#ifndef THRIFT_ASYNC_TASYNCTRANSPORT_H_
#define THRIFT_ASYNC_TASYNCTRANSPORT_H_ 1

#include <folly/io/async/DelayedDestruction.h>
#include <folly/io/async/EventBase.h>
#include <thrift/lib/cpp/transport/TTransportException.h>
#include <folly/io/async/AsyncSocket.h>
#include <folly/portability/SysUio.h>

#include <thrift/lib/cpp/thrift_config.h>
#include <inttypes.h>
#include <memory>

namespace folly {
class IOBuf;
class SocketAddress;
}

namespace apache { namespace thrift {

namespace async {

typedef folly::WriteFlags WriteFlags;

// Wrapper around folly::AsyncTransport, that converts read/write
// exceptions to TTransportExceptions
class TAsyncTransport : virtual public folly::AsyncTransportWrapper {
 public:
  typedef std::unique_ptr<TAsyncTransport, Destructor> UniquePtr;

  class ReadCallback : public folly::AsyncSocket::ReadCallback {
   public:
    virtual void readError(
      const transport::TTransportException& ex) noexcept = 0;
   private:
    void readErr(const folly::AsyncSocketException& ex) noexcept override {
      transport::TTransportException tex(
        transport::TTransportException::TTransportExceptionType(ex.getType()),
        ex.what(), ex.getErrno());

      readError(tex);

    }
  };

  class WriteCallback : public folly::AsyncSocket::WriteCallback {
   public:
    virtual void writeError(
      size_t bytes, const transport::TTransportException& ex) noexcept = 0;

   private:
    void writeErr(size_t bytes,
                  const folly::AsyncSocketException& ex) noexcept override {
      transport::TTransportException tex(
        transport::TTransportException::TTransportExceptionType(ex.getType()),
        ex.what(), ex.getErrno());

      writeError(bytes, tex);

    }
  };

  // Read/write methods that aren't part of folly::AsyncTransport
  virtual void setReadCallback(TAsyncTransport::ReadCallback* callback) {
    setReadCB(callback);
  }
};

}}} // apache::thrift::async

#endif // #ifndef THRIFT_ASYNC_TASYNCTRANSPORT_H_
<commit_msg>clang-format TAsyncTransport.h<commit_after>/*
 * Copyright 2014-present 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.
 */

#ifndef THRIFT_ASYNC_TASYNCTRANSPORT_H_
#define THRIFT_ASYNC_TASYNCTRANSPORT_H_ 1

#include <inttypes.h>
#include <memory>

#include <folly/io/async/AsyncSocket.h>
#include <folly/io/async/DelayedDestruction.h>
#include <folly/io/async/EventBase.h>
#include <folly/portability/SysUio.h>
#include <thrift/lib/cpp/thrift_config.h>
#include <thrift/lib/cpp/transport/TTransportException.h>

namespace folly {
class IOBuf;
class SocketAddress;
} // namespace folly

namespace apache {
namespace thrift {

namespace async {

typedef folly::WriteFlags WriteFlags;

// Wrapper around folly::AsyncTransport, that converts read/write
// exceptions to TTransportExceptions
class TAsyncTransport : virtual public folly::AsyncTransportWrapper {
 public:
  typedef std::unique_ptr<TAsyncTransport, Destructor> UniquePtr;

  class ReadCallback : public folly::AsyncSocket::ReadCallback {
   public:
    virtual void readError(
        const transport::TTransportException& ex) noexcept = 0;

   private:
    void readErr(const folly::AsyncSocketException& ex) noexcept override {
      transport::TTransportException tex(
          transport::TTransportException::TTransportExceptionType(ex.getType()),
          ex.what(),
          ex.getErrno());

      readError(tex);
    }
  };

  class WriteCallback : public folly::AsyncSocket::WriteCallback {
   public:
    virtual void writeError(
        size_t bytes,
        const transport::TTransportException& ex) noexcept = 0;

   private:
    void writeErr(
        size_t bytes,
        const folly::AsyncSocketException& ex) noexcept override {
      transport::TTransportException tex(
          transport::TTransportException::TTransportExceptionType(ex.getType()),
          ex.what(),
          ex.getErrno());

      writeError(bytes, tex);
    }
  };

  // Read/write methods that aren't part of folly::AsyncTransport
  virtual void setReadCallback(TAsyncTransport::ReadCallback* callback) {
    setReadCB(callback);
  }
};

} // namespace async
} // namespace thrift
} // namespace apache

#endif // #ifndef THRIFT_ASYNC_TASYNCTRANSPORT_H_

{'fraction_non_alphanumeric': 0.09735173442745244, 'fraction_numerical': 0.004102946661693398, 'mean_word_length': 4.166666666666667, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '2219011', 'n_tokens_mistral': 1584, 'n_tokens_neox': 1550, 'n_words': 431}