MCPcopy Create free account
hub / github.com/davisking/dlib / sockstreambuf_custom_buffer_test

Function sockstreambuf_custom_buffer_test

dlib/test/sockstreambuf.cpp:232–319  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

230// ----------------------------------------------------------------------------------------
231
232 void sockstreambuf_custom_buffer_test (
233 )
234 {
235 listener* raw_list = 0;
236 DLIB_TEST(create_listener(raw_list, 0) == 0);
237 std::unique_ptr<listener> list(raw_list);
238
239 const string input = "abcdef";
240 const string output = "uvwxyz";
241 string received_output;
242 int accept_result = OTHER_ERROR;
243 long write_result = OTHER_ERROR;
244 long read_result = 0;
245
246 std::thread server([&]()
247 {
248 connection* raw_con = 0;
249 accept_result = list->accept(raw_con, 5000);
250 std::unique_ptr<connection> con(raw_con);
251 if (accept_result != 0)
252 return;
253
254 write_result = con->write(input.data(), input.size());
255 if (write_result != static_cast<long>(input.size()))
256 return;
257
258 while (received_output.size() < output.size())
259 {
260 char buf[10];
261 read_result = con->read(buf, output.size()-received_output.size(), 5000);
262 if (read_result <= 0)
263 return;
264 received_output.append(buf, read_result);
265 }
266 });
267
268 connection* raw_con = 0;
269 const int connect_result = create_connection(
270 raw_con,
271 list->get_listening_port(),
272 "127.0.0.1"
273 );
274 std::unique_ptr<connection> con(raw_con);
275
276 vector<sockstreambuf::int_type> read_values;
277 bool output_stream_good = false;
278 if (connect_result == 0)
279 {
280 sockstreambuf buf(con, 1, 5, 3);
281
282 read_values.push_back(buf.sbumpc()); // a
283 read_values.push_back(buf.sbumpc()); // b
284 read_values.push_back(buf.sbumpc()); // c
285 read_values.push_back(buf.sbumpc()); // d
286 read_values.push_back(buf.sgetc()); // e, and refill the input buffer
287 read_values.push_back(buf.sungetc());
288 read_values.push_back(buf.sungetc());
289 read_values.push_back(buf.sungetc());

Callers 1

perform_testMethod · 0.85

Calls 11

putMethod · 0.80
create_listenerFunction · 0.50
create_connectionFunction · 0.50
writeMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
readMethod · 0.45
appendMethod · 0.45
get_listening_portMethod · 0.45
push_backMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected