Branch data Line data Source code
1 : : /* 2 : : ** Copyright (C) 2022 CERN 3 : : ** 4 : : ** This software is provided 'as-is', without any express or implied 5 : : ** warranty. In no event will the authors be held liable for any damages 6 : : ** arising from the use of this software. 7 : : ** 8 : : ** Permission is granted to anyone to use this software for any purpose, 9 : : ** including commercial applications, and to alter it and redistribute it 10 : : ** freely, subject to the following restrictions: 11 : : ** 12 : : ** 1. The origin of this software must not be misrepresented; you must not 13 : : ** claim that you wrote the original software. If you use this software 14 : : ** in a product, an acknowledgment in the product documentation would be 15 : : ** appreciated but is not required. 16 : : ** 2. Altered source versions must be plainly marked as such, and must not be 17 : : ** misrepresented as being the original software. 18 : : ** 3. This notice may not be removed or altered from any source distribution. 19 : : ** 20 : : ** Created on: 2022-11-29T10:34:40 21 : : ** Author: Sylvain Fargier <sylvain.fargier@cern.ch> 22 : : */ 23 : : 24 : : #ifndef PIPE_HPP__ 25 : : #define PIPE_HPP__ 26 : : 27 : : #include <string> 28 : : 29 : : namespace ccut { 30 : : 31 : : /** 32 : : * @brief small wrapper on unix pipe objects 33 : : * @details created pipe is always non-blocking 34 : : * 35 : : */ 36 : : class Pipe 37 : : { 38 : : public: 39 : : Pipe(); 40 : : ~Pipe(); 41 : : 42 : 20 : inline int in() const { return m_fd[0]; } 43 : 2 : inline int out() const { return m_fd[1]; } 44 : : 45 : : void write(const std::string &msg); 46 : : 47 : : /** 48 : : * @brief write bytes of data 49 : : * 50 : : * @param[in] data data to write 51 : : * @param[in] size data size 52 : : * @throws ccut::Exception on read error 53 : : */ 54 : : size_t write(const void *data, size_t size); 55 : : 56 : : /** 57 : : * @brief read up to size bytes of data 58 : : * @return the number of bytes read 59 : : * @throws ccut::Exception on read error 60 : : */ 61 : : size_t read(void *data, size_t size); 62 : : 63 : : /** 64 : : * @brief flushes all buffered data 65 : : */ 66 : : void flush(); 67 : : 68 : : protected: 69 : : int m_fd[2]; 70 : : }; 71 : : 72 : : } // namespace ccut 73 : : 74 : : #endif