This repository has been archived on 2020-05-25. You can view files and clone it, but cannot push or open issues or pull requests.
tdlib-fork/td/mtproto/IStreamTransport.h
levlam 28bfa4c4a6 Fix some MSVC Analyzer warnings.
GitOrigin-RevId: f62e8173ae9a5b78818f6575548ce22d4aa5c51d
2018-10-26 17:11:20 +03:00

45 lines
1.5 KiB
C++

//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once
#include "td/utils/buffer.h"
#include "td/utils/port/detail/PollableFd.h"
#include "td/utils/Status.h"
namespace td {
namespace mtproto {
struct TransportType {
enum Type { Tcp, ObfuscatedTcp, Http } type;
int16 dc_id;
string secret;
TransportType() : type(Tcp), dc_id(0), secret() {
}
TransportType(Type type, int16 dc_id, string secret) : type(type), dc_id(dc_id), secret(std::move(secret)) {
}
};
class IStreamTransport {
public:
IStreamTransport() = default;
IStreamTransport(const IStreamTransport &) = delete;
IStreamTransport &operator=(const IStreamTransport &) = delete;
virtual ~IStreamTransport() = default;
virtual Result<size_t> read_next(BufferSlice *message, uint32 *quick_ack) = 0;
virtual bool support_quick_ack() const = 0;
virtual void write(BufferWriter &&message, bool quick_ack) = 0;
virtual bool can_read() const = 0;
virtual bool can_write() const = 0;
virtual void init(ChainBufferReader *input, ChainBufferWriter *output) = 0;
virtual size_t max_prepend_size() const = 0;
virtual size_t max_append_size() const = 0;
virtual TransportType get_type() const = 0;
};
unique_ptr<IStreamTransport> create_transport(TransportType type);
} // namespace mtproto
} // namespace td