]> WPIA git - cassiopeia.git/blob - src/io/slipBio.h
a2fd3c2de2dfd7836e70c663a929d86a2150d084
[cassiopeia.git] / src / io / slipBio.h
1 #pragma once
2
3 #include <memory>
4 #include <vector>
5
6 #include "io/bios.h"
7
8 class SlipBIO : public OpensslBIO {
9 private:
10     std::shared_ptr<OpensslBIO> target;
11
12     std::vector<char> buffer;
13
14     std::vector<char> header = {0, 0, 0, 0, 0, 0, 0, 0};
15     int resetCounter = -1; // -1 means waiting for start byte
16
17     unsigned int decodeTarget;
18     unsigned int decodePos;
19     unsigned int rawPos;
20
21     bool waitForConnection = true;
22     bool waitForReset = false;
23     bool packageLeft = false;
24
25     bool server = false;
26
27 private:
28     int unmask();
29
30 public:
31     SlipBIO( std::shared_ptr<OpensslBIO> target );
32     SlipBIO();
33     ~SlipBIO();
34
35     void setTarget( std::shared_ptr<OpensslBIO> target, bool server );
36
37     virtual int write( const char *buf, int num );
38     virtual int read( char *buf, int size );
39     virtual long ctrl( int cmod, long arg1, void *arg2 );
40
41     static const char *getName();
42 };