13 constexpr
size_t max_copy_length = 65536;
14 constexpr
size_t buffer_size = 1048576;
21 bool _outbound_shutdown{
false};
22 bool _inbound_shutdown{
false};
24 socket.set_blocking(
false);
25 _input.set_blocking(
false);
26 _output.set_blocking(
false);
33 _outbound.write(_input.read(_outbound.remaining_capacity()));
35 _outbound.end_input();
38 [&] {
return (not _outbound.error()) and (_outbound.remaining_capacity() > 0) and (not _inbound.error()); },
39 [&] { _outbound.end_input(); });
42 _eventloop.add_rule(socket,
45 const size_t bytes_to_write =
min(max_copy_length, _outbound.buffer_size());
46 const size_t bytes_written = socket.write(_outbound.peek_output(bytes_to_write),
false);
47 _outbound.pop_output(bytes_written);
48 if (_outbound.eof()) {
49 socket.shutdown(SHUT_WR);
50 _outbound_shutdown =
true;
53 [&] {
return (not _outbound.buffer_empty()) or (_outbound.eof() and not _outbound_shutdown); },
54 [&] { _outbound.set_error(); });
61 _inbound.write(socket.read(_inbound.remaining_capacity()));
66 [&] {
return (not _inbound.error()) and (_inbound.remaining_capacity() > 0) and (not _outbound.error()); },
67 [&] { _inbound.end_input(); });
70 _eventloop.add_rule(_output,
73 const size_t bytes_to_write =
min(max_copy_length, _inbound.buffer_size());
74 const size_t bytes_written = _output.write(_inbound.peek_output(bytes_to_write),
false);
75 _inbound.pop_output(bytes_written);
79 _inbound_shutdown =
true;
82 [&] {
return (not _inbound.buffer_empty()) or (_inbound.eof() and not _inbound_shutdown); },
83 [&] { _inbound.set_error(); });