virthttp  0.0
libvirt http interface
Stream.hpp
Go to the documentation of this file.
1 #pragma once
2 #include "../Stream.hpp"
3 #include "Connection.hpp"
4 
5 namespace virt {
6 constexpr Stream::Stream(virStreamPtr ptr) noexcept : underlying(ptr) {}
7 inline Stream::Stream(const Connection& conn, Flag flags) noexcept : underlying(virStreamNew(conn.underlying, to_integral(flags))) {}
8 inline Stream::Stream(const Stream& oth) noexcept : underlying(oth.underlying) {
9  if (underlying)
10  virStreamRef(underlying);
11 }
12 constexpr Stream::Stream(Stream&& from) noexcept : underlying(from.underlying) { from.underlying = nullptr; }
13 inline Stream::~Stream() noexcept {
14  if (underlying)
15  virStreamFree(underlying);
16 }
17 inline Stream& Stream::operator=(const Stream& oth) noexcept {
18  this->~Stream();
19  if ((underlying = oth.underlying))
20  virStreamRef(underlying);
21  return *this;
22 }
23 constexpr Stream& Stream::operator=(Stream&& from) noexcept {
24  underlying = from.underlying;
25  from.underlying = nullptr;
26  return *this;
27 }
28 
29 inline bool Stream::abort() noexcept { return virStreamAbort(underlying) >= 0; }
30 
31 inline bool Stream::finish() noexcept { return virStreamFinish(underlying) >= 0; }
32 inline int Stream::recv(gsl::span<char> span) noexcept { return recv(span.data(), span.size()); }
33 inline int Stream::recv(char* buf, size_t buflen) noexcept { return virStreamRecv(underlying, buf, buflen); }
34 inline int Stream::recv(gsl::span<char> span, RecvFlag flags) noexcept { return recv(span.data(), span.size(), flags); }
35 inline int Stream::recv(char* buf, size_t buflen, RecvFlag flags) noexcept { return virStreamRecvFlags(underlying, buf, buflen, to_integral(flags)); }
36 inline std::optional<long long> Stream::recvHole() {
37  std::optional<long long> ret;
38  long long& v = ret.emplace();
39  return virStreamRecvHole(underlying, &v, 0) >= 0 ? ret : std::nullopt;
40 }
41 inline int Stream::send(gsl::span<const char> span) noexcept { return send(span.data(), span.size()); }
42 inline int Stream::send(const char* buf, size_t buflen) noexcept { return virStreamSend(underlying, buf, buflen); }
43 inline bool Stream::sendHole(long long len) noexcept { return virStreamSendHole(underlying, len, 0) >= 0; }
44 }
Definition: Stream.hpp:10
~Stream() noexcept
Definition: Stream.hpp:13
int send(gsl::span< const char >) noexcept
Definition: Stream.hpp:41
constexpr auto to_integral(E e) noexcept
Definition: Base.hpp:32
int recv(gsl::span< char >) noexcept
Definition: Stream.hpp:32
Definition: Connection.hpp:47
bool abort() noexcept
Definition: Stream.hpp:29
Definition: AdminConnection.hpp:11
Definition: Flag.hpp:8
bool sendHole(long long) noexcept
Definition: Stream.hpp:43
Stream & operator=(const Stream &) noexcept
Definition: Stream.hpp:17
std::optional< long long > recvHole()
Definition: Stream.hpp:36
bool finish() noexcept
Definition: Stream.hpp:31
Definition: RecvFlag.hpp:8