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

Method receive_data

dlib/bsp/bsp.cpp:332–416  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

330// ----------------------------------------------------------------------------------------
331
332 bool bsp_context::
333 receive_data (
334 std::shared_ptr<std::vector<char> >& item,
335 unsigned long& sending_node_id
336 )
337 {
338 notify_control_node(impl2::IN_WAITING_STATE);
339
340 while (true)
341 {
342 // If there aren't any nodes left to give us messages then return right now.
343 // We need to check the msg_buffer size to make sure there aren't any
344 // unprocessed message there. Recall that this can happen because status
345 // messages always jump to the front of the message buffer. So we might have
346 // learned about the node terminations before processing their messages for us.
347 if (num_terminated_nodes == _cons.size() && msg_buffer.size() == 0)
348 {
349 return false;
350 }
351
352 // if all running nodes are currently blocking forever on receive_data()
353 if (node_id() == 0 && outstanding_messages == 0 && num_terminated_nodes + num_waiting_nodes == _cons.size())
354 {
355 num_waiting_nodes = 0;
356 broadcast_byte(impl2::SEE_ALL_IN_WAITING_STATE);
357
358 // Note that the reason we have this epoch counter is so we can tell if a
359 // sent message is from before or after one of these "all nodes waiting"
360 // synchronization events. If we didn't have the epoch count we would have
361 // a race condition where one node gets the SEE_ALL_IN_WAITING_STATE
362 // message before others and then sends out a message to another node
363 // before that node got the SEE_ALL_IN_WAITING_STATE message. Then that
364 // node would think the normal message came before SEE_ALL_IN_WAITING_STATE
365 // which would be bad.
366 ++current_epoch;
367 return false;
368 }
369
370 impl1::msg_data data;
371 if (!msg_buffer.pop(data, current_epoch))
372 throw dlib::socket_error("Error reading from msg_buffer in dlib::bsp_context.");
373
374
375 switch(data.msg_type)
376 {
377 case impl2::MESSAGE_HEADER: {
378 item = data.data;
379 sending_node_id = data.sender_id;
380 notify_control_node(impl2::GOT_MESSAGE);
381 return true;
382 } break;
383
384 case impl2::IN_WAITING_STATE: {
385 ++num_waiting_nodes;
386 } break;
387
388 case impl2::GOT_MESSAGE: {
389 --outstanding_messages;

Callers

nothing calls this directly

Calls 4

socket_errorClass · 0.85
data_to_stringMethod · 0.80
sizeMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected