]> git.stg.codes - stg.git/blob - stglibs/common.lib/include/stg/blockio.h
Merge branch 'stg-2.409-radius'
[stg.git] / stglibs / common.lib / include / stg / blockio.h
1 #ifndef __STG_STGLIBS_BLOCK_IO_H__
2 #define __STG_STGLIBS_BLOCK_IO_H__
3
4 #include <vector>
5
6 #include <sys/uio.h>
7
8 namespace STG
9 {
10
11 typedef std::vector<iovec> IOVec;
12
13 class BlockReader
14 {
15     public:
16         BlockReader(const IOVec& ioVec);
17
18         bool read(int socket);
19         bool done() const { return m_remainder == 0; }
20         size_t remainder() const { return m_remainder; }
21
22     private:
23         IOVec m_dest;
24         size_t m_remainder;
25 };
26
27 class BlockWriter
28 {
29     public:
30         BlockWriter(const IOVec& ioVec);
31
32         bool write(int socket);
33         bool done() const { return m_remainder == 0; }
34         size_t remainder() const { return m_remainder; }
35
36     private:
37         IOVec m_source;
38         size_t m_remainder;
39 };
40
41 } // namespace STG
42
43 #endif