1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
3 #include "base/networkstream.hpp"
5 using namespace icinga;
7 NetworkStream::NetworkStream(Socket::Ptr socket)
8 : m_Socket(std::move(socket)), m_Eof(false)
11 void NetworkStream::Close()
19 * Reads data from the stream.
21 * @param buffer The buffer where data should be stored. May be nullptr if you're
22 * not actually interested in the data.
23 * @param count The number of bytes to read from the queue.
24 * @returns The number of bytes actually read.
26 size_t NetworkStream::Read(void *buffer, size_t count, bool allow_partial)
30 ASSERT(allow_partial);
33 BOOST_THROW_EXCEPTION(std::invalid_argument("Tried to read from closed socket."));
36 rc = m_Socket->Read(buffer, count);
50 * Writes data to the stream.
52 * @param buffer The data that is to be written.
53 * @param count The number of bytes to write.
54 * @returns The number of bytes written
56 void NetworkStream::Write(const void *buffer, size_t count)
61 BOOST_THROW_EXCEPTION(std::invalid_argument("Tried to write to closed socket."));
64 rc = m_Socket->Write(buffer, count);
74 BOOST_THROW_EXCEPTION(std::runtime_error("Short write for socket."));
78 bool NetworkStream::IsEof() const