-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem-stream.h
67 lines (52 loc) · 1.62 KB
/
system-stream.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* \author: Rafal Banas
*/
#ifndef TELNET_SERVER_SYSTEM_STREAM_H
#define TELNET_SERVER_SYSTEM_STREAM_H
#include "byte-stream.h"
#include "errors.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <vector>
#include <stdexcept>
/// Abstract byte stream class for handling system input and output working on file descriptors.
class SystemStream: public ByteStream {
protected:
int in_fd;
int out_fd;
size_type buffer_size;
size_type buffer_cursor;
public:
uint8_t *output_buffer;
/**
* @param in_fd - file descriptor for input
* @param out_fd - file descriptor for ouput
* @param buffer_size - size of output buffer
*/
SystemStream(int in_fd, int out_fd, size_type buffer_size)
: in_fd(in_fd),
out_fd(out_fd),
buffer_size(buffer_size),
buffer_cursor(0),
output_buffer(new uint8_t[buffer_size]) {};
SystemStream(SystemStream &&stream)
: in_fd(stream.in_fd),
out_fd(stream.out_fd),
buffer_size(stream.buffer_size),
buffer_cursor(stream.buffer_cursor),
output_buffer(stream.output_buffer) {
stream.output_buffer = nullptr;
}
public:
series_t readBytes(size_t size_limit) override;
uint8_t readByte() override;
void writeBytes(const series_t &series) override;
void writeByte(uint8_t byte) override;
void flushOutput() override;
/**
* Class does not own file descriptors, so they will not be closed in destructor
*/
virtual ~SystemStream();
};
#endif //TELNET_SERVER_SYSTEM_STREAM_H