42 : _read_buffer_in_use(
false),
43 _write_buffer_in_use(
false)
51 void stcp_socket::do_key_exchange()
80 _sock.
bind(local_endpoint);
90 assert( len > 0 && (len % 16) == 0 );
96 struct check_buffer_in_use {
98 check_buffer_in_use(
bool& buffer_in_use) : _buffer_in_use(buffer_in_use) { assert(!_buffer_in_use); _buffer_in_use =
true; }
99 ~check_buffer_in_use() { assert(_buffer_in_use); _buffer_in_use =
false; }
100 } buffer_in_use_checker(_read_buffer_in_use);
103 const size_t read_buffer_length = 4096;
105 _read_buffer.reset(
new char[read_buffer_length], [](
char* p){
delete[] p; });
107 len = std::min<size_t>(read_buffer_length, len);
109 size_t s = _sock.
readsome( _read_buffer, len, 0 );
112 _sock.
read(_read_buffer, 16 - (s%16), s);
115 _recv_aes.
decode( _read_buffer.get(), s, buffer );
121 return readsome(buf.get() + offset, len);
131 assert( len > 0 && (len % 16) == 0 );
137 struct check_buffer_in_use {
138 bool& _buffer_in_use;
139 check_buffer_in_use(
bool& buffer_in_use) : _buffer_in_use(buffer_in_use) { assert(!_buffer_in_use); _buffer_in_use =
true; }
140 ~check_buffer_in_use() { assert(_buffer_in_use); _buffer_in_use =
false; }
141 } buffer_in_use_checker(_write_buffer_in_use);
144 const std::size_t write_buffer_length = 4096;
146 _write_buffer.reset(
new char[write_buffer_length], [](
char* p){
delete[] p; });
147 len = std::min<size_t>(write_buffer_length, len);
148 memset(_write_buffer.get(), 0, len);
155 uint32_t ciphertext_len = _send_aes.
encode( buffer, len, _write_buffer.get() );
156 assert(ciphertext_len == len);
157 _sock.
write( _write_buffer, ciphertext_len );
158 return ciphertext_len;
163 return writesome(buf.get() + offset, len);