start.cpp 1018 B

123456789101112131415161718192021222324252627282930313233
  1. #include <stdlib.h>
  2. #include "start.hpp"
  3. // Once all the networking is set up, start doing whatever we were asked
  4. // to do on the command line
  5. void start(NetIO &netio, int argc, char **argv)
  6. {
  7. srand48(1);
  8. // Send a bunch of data to all peers
  9. for (size_t node_num = 0; node_num < netio.num_nodes; ++node_num) {
  10. if (node_num == netio.me) continue;
  11. NodeIO &node = netio.node(node_num);
  12. uint32_t msgsize = lrand48() % 10000000;
  13. printf("Msgsize to %lu: %u\n", node_num, msgsize);
  14. node.send_message_header(msgsize);
  15. uint8_t c = 0;
  16. while (msgsize > 0) {
  17. uint8_t* frame = node.request_frame();
  18. uint32_t chunk_size = (lrand48() % (MAXCHUNKSIZE-1)) + 1;
  19. if (chunk_size > msgsize) {
  20. chunk_size = msgsize;
  21. }
  22. memset(frame, ++c, chunk_size);
  23. node.send_chunk(frame, chunk_size);
  24. msgsize -= chunk_size;
  25. }
  26. }
  27. printf("Sleeping\n");
  28. sleep(10);
  29. }