accept more TLS versions, ignore zero return
[ghsmtp.git] / iobuffer.hpp
blobd237d6687fc0e9e35a62b37431b4dcb02c242f7e
1 #ifndef IOBUFFER_DOT_HPP
2 #define IOBUFFER_DOT_HPP
4 #include "default_init_allocator.hpp"
6 #include <cstddef>
7 #include <vector>
9 template <typename ByteT = std::byte>
10 class iobuffer {
11 public:
12 using buffer_t = std::vector<ByteT, default_init_allocator<ByteT>>;
13 using size_type = typename buffer_t::size_type;
15 iobuffer() = default;
16 explicit iobuffer(size_type sz)
17 : buf_(sz)
21 auto data() { return buf_.data(); }
22 auto data() const { return buf_.data(); }
23 auto size() const { return buf_.size(); }
25 auto resize(size_type sz) { return buf_.resize(sz); }
26 void shrink_to_fit() { buf_.shrink_to_fit(); }
28 bool operator==(iobuffer const& rhs) const
30 if (this->size() == rhs.size())
31 return memcmp(this->data(), rhs.data(), this->size()) == 0;
32 return false;
35 bool operator<(iobuffer const& rhs) const
37 if (this->size() == rhs.size())
38 return memcmp(this->data(), rhs.data(), this->size()) < 0;
39 return this->size() < rhs.size();
42 private:
43 buffer_t buf_;
46 #endif // IOBUFFER_DOT_HPP