daily pastebin goal
49%
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Sender Code:
  2. const sar_cfg_t cfg = {
  3.     .segmentSize = 28;
  4.     .checksum = true;
  5.     .sessionId = true;
  6.     .reordering = false;
  7.     .errCorrection = NO_ECC;
  8. };
  9. char message[128] = "Send this really really really long message!";
  10. char segments[128];
  11. char* segptrs[16];
  12. int segcount = segment(cfg,
  13.                        strlen(message), message,
  14.                        sizeof(segments)/sizeof(segments[0]), segments,
  15.                        sizeof(segptrs)/sizeof(segptrs[0]), segptrs );
  16. for (int i = 0; i < segcount; i++) {
  17.     int segLen = segptrs[i+1]-segptrs[i];
  18.     send(segLen, segptrs[i]);
  19. }
  20.  
  21. // Receiver Code:
  22. const sar_cfg_t cfg = {
  23.     .segmentSize = 28;
  24.     .checksum = true;
  25.     .sessionId = true;
  26.     .reordering = false;
  27.     .errCorrection = NO_ECC;
  28. };
  29. char output[128];
  30. char buf[128];
  31. reasm_state_t reasm_state;
  32. reasm_init(&reasm_state, cfg,
  33.            sizeof(output), output);
  34. while (!reasm_state.done) {
  35.     int msgLen = recieve(sizeof(buf), buf);
  36.     int res = reasm_update(&reasm_state, buf, msgLen);
  37. }
  38. if(reasm_state.ok) {
  39.     printf("%.*sn", reasm_state.len, output);
  40. } else {
  41.     println("Reassembly error!");
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top