forked from team-unstablers/ulalaca-xrdp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SocketStream.cpp
54 lines (41 loc) · 1.18 KB
/
SocketStream.cpp
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
//
// Created by cheesekun on 2/28/22.
//
#include "SocketStream.hpp"
InputSocketStream::InputSocketStream(UnixSocketBase &socketLike):
_socket(socketLike),
_buffer()
{
}
int InputSocketStream::underflow() {
if (this->gptr() == this->egptr()) {
auto read = _socket.read(_buffer, MAX_BUFFER_SIZE);
if (read <= 0) {
// 더 이상 읽을 수 있는 데이터가 없음
return traits_type::eof();
}
this->setg(
_buffer, _buffer,
_buffer + read
);
}
// TODO: assert(this->gptr() != this->egptr());
return traits_type::to_int_type(*this->gptr());
}
OutputSocketStream::OutputSocketStream(UnixSocketBase &socketLike):
_socket(socketLike),
_buffer()
{
this->setp(_buffer, _buffer + MAX_BUFFER_SIZE);
}
void OutputSocketStream::flush() {
ptrdiff_t distance = this->pptr() - _buffer;
auto written = _socket.write(_buffer, distance);
this->setp(_buffer, _buffer + MAX_BUFFER_SIZE);
}
int OutputSocketStream::overflow(int character) {
if (this->pptr() == this->epptr()) {
this->flush();
}
return traits_type::to_int_type(character);
}