diff options
| author | Arseny Smirnov <arseny30@gmail.com> | 2018-08-15 15:41:42 +0300 |
|---|---|---|
| committer | Arseny Smirnov <arseny30@gmail.com> | 2018-08-15 15:41:42 +0300 |
| commit | ab2b1897224415f407649b2908fef46f97b35c83 (patch) | |
| tree | 16897c84a4b6592fe9f46650ad48ac9b66a2d8aa /tdnet/td/net/HttpConnectionBase.h | |
| parent | 7fc96ddff5c0e85273b3d961608a891a9fb55d19 (diff) | |
Ssl refactoring
GitOrigin-RevId: f5916787608227b6914c10520dfe7a7039522ef9
Diffstat (limited to 'tdnet/td/net/HttpConnectionBase.h')
| -rw-r--r-- | tdnet/td/net/HttpConnectionBase.h | 129 |
1 files changed, 16 insertions, 113 deletions
diff --git a/tdnet/td/net/HttpConnectionBase.h b/tdnet/td/net/HttpConnectionBase.h index 1d420a317..f5a3aae99 100644 --- a/tdnet/td/net/HttpConnectionBase.h +++ b/tdnet/td/net/HttpConnectionBase.h @@ -10,120 +10,16 @@ #include "td/net/HttpQuery.h" #include "td/net/HttpReader.h" +#include "td/net/SslStream.h" #include "td/utils/buffer.h" #include "td/utils/BufferedFd.h" -#include "td/utils/port/Fd.h" +#include "td/utils/port/SocketFd.h" #include "td/utils/Slice.h" #include "td/utils/Status.h" namespace td { -class FdInterface { - public: - FdInterface() = default; - FdInterface(const FdInterface &) = delete; - FdInterface &operator=(const FdInterface &) = delete; - FdInterface(FdInterface &&) = default; - FdInterface &operator=(FdInterface &&) = default; - virtual ~FdInterface() = default; - virtual const Fd &get_fd() const = 0; - virtual Fd &get_fd() = 0; - virtual int32 get_flags() const = 0; - virtual Status get_pending_error() TD_WARN_UNUSED_RESULT = 0; - - virtual Result<size_t> write(Slice slice) TD_WARN_UNUSED_RESULT = 0; - virtual Result<size_t> read(MutableSlice slice) TD_WARN_UNUSED_RESULT = 0; - - virtual void close() = 0; - virtual bool empty() const = 0; -}; - -template <class FdT> -class FdToInterface : public FdInterface { - public: - FdToInterface() = default; - explicit FdToInterface(FdT fd) : fd_(std::move(fd)) { - } - - const Fd &get_fd() const final { - return fd_.get_fd(); - } - Fd &get_fd() final { - return fd_.get_fd(); - } - int32 get_flags() const final { - return fd_.get_flags(); - } - Status get_pending_error() final TD_WARN_UNUSED_RESULT { - return fd_.get_pending_error(); - } - - Result<size_t> write(Slice slice) final TD_WARN_UNUSED_RESULT { - return fd_.write(slice); - } - Result<size_t> read(MutableSlice slice) final TD_WARN_UNUSED_RESULT { - return fd_.read(slice); - } - - void close() final { - fd_.close(); - } - bool empty() const final { - return fd_.empty(); - } - - private: - FdT fd_; -}; - -template <class FdT> -std::unique_ptr<FdInterface> make_fd_interface(FdT fd) { - return make_unique<FdToInterface<FdT>>(std::move(fd)); -} - -class FdProxy { - public: - FdProxy() = default; - explicit FdProxy(std::unique_ptr<FdInterface> fd) : fd_(std::move(fd)) { - } - - const Fd &get_fd() const { - return fd_->get_fd(); - } - Fd &get_fd() { - return fd_->get_fd(); - } - int32 get_flags() const { - return fd_->get_flags(); - } - Status get_pending_error() TD_WARN_UNUSED_RESULT { - return fd_->get_pending_error(); - } - - Result<size_t> write(Slice slice) TD_WARN_UNUSED_RESULT { - return fd_->write(slice); - } - Result<size_t> read(MutableSlice slice) TD_WARN_UNUSED_RESULT { - return fd_->read(slice); - } - - void close() { - fd_->close(); - } - bool empty() const { - return fd_->empty(); - } - - private: - std::unique_ptr<FdInterface> fd_; -}; - -template <class FdT> -FdProxy make_fd_proxy(FdT fd) { - return FdProxy(make_fd_interface(std::move(fd))); -} - namespace detail { class HttpConnectionBase : public Actor { public: @@ -133,16 +29,23 @@ class HttpConnectionBase : public Actor { protected: enum class State { Read, Write, Close }; - template <class FdT> - HttpConnectionBase(State state, FdT fd, size_t max_post_size, size_t max_files, int32 idle_timeout) - : HttpConnectionBase(state, make_fd_proxy(std::move(fd)), max_post_size, max_files, idle_timeout) { - } - HttpConnectionBase(State state, FdProxy fd, size_t max_post_size, size_t max_files, int32 idle_timeout); + HttpConnectionBase(State state, SocketFd fd, SslStream ssl_stream, size_t max_post_size, size_t max_files, + int32 idle_timeout); private: - using StreamConnection = BufferedFd<FdProxy>; State state_; - StreamConnection stream_connection_; + + BufferedFd<SocketFd> fd_; + SslStream ssl_stream_; + + ByteFlowSource read_source_{&fd_.input_buffer()}; + ByteFlowSink read_sink_; + + ChainBufferWriter write_buffer_; + ChainBufferReader write_buffer_reader_ = write_buffer_.extract_reader(); + ByteFlowSource write_source_{&write_buffer_reader_}; + ByteFlowMoveSink write_sink_{&fd_.output_buffer()}; + size_t max_post_size_; size_t max_files_; int32 idle_timeout_; |
