-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtypes.h
More file actions
59 lines (49 loc) · 1.66 KB
/
types.h
File metadata and controls
59 lines (49 loc) · 1.66 KB
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
/*
* StupidVNC
*
* This library is free software; you can redistribute it and/o
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#pragma once
#include <string.h>
#include "stupidvnc.h"
enum class FlushMode {
NOFLUSH,
FLUSH ,
};
struct IStupidIO {
virtual ~IStupidIO() {}
virtual void handshake() {}
virtual int read(void* dst, unsigned int len, bool block = true) = 0;
virtual void write(const void* src, unsigned int len, FlushMode flushmode) final;
virtual void close() = 0;
virtual void flush() = 0;
unsigned char _txQ[256*1024];
unsigned int _txQ_write_ptr = 0;
};
inline void IStupidIO::write(const void *src, unsigned int len, FlushMode flushmode)
{
auto csrc = (const char*)src;
while (len > 0) {
unsigned int remaining_space = sizeof(_txQ) - _txQ_write_ptr;
if (remaining_space > 0) {
auto chunk_size = std::min(remaining_space, len);
memcpy(&_txQ[_txQ_write_ptr], csrc, chunk_size);
_txQ_write_ptr += chunk_size;
len -= chunk_size;
csrc += chunk_size;
} else
flush();
}
if (flushmode == FlushMode::FLUSH)
flush();
}