Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.20 KB | None | 0 0
  1. // ---- Server code ------
  2. // Initialize shared memory
  3. struct Sync sync;
  4. struct Arguments args;
  5. args.size = 2048 // Total size of the shared memory (it's not the same as packet size)
  6. create_sync(&sync, &args); // Function comes from shm-sync-common.c
  7. // Send packet
  8. int pkt_size = 200;
  9. sync.shared_memory[0] = pkt_size; // Supose this indicates a packet size of 200 bytes
  10. memset(sync.shared_memory+1, '1', pkt_size); // write 200 bytes of character '1'
  11. sync_notify(sync.mutex); // Notify the client of the packet to transmit
  12. sync_wait(sync.mutex); // Wait client to process it
  13.  
  14.  
  15. // ---- Client code ------
  16. // Initialize shared memory
  17. struct Sync sync;
  18. struct Arguments args;
  19. args.size = 2048 // Total size of the shared memory (it's not the same as packet size)
  20. sleep(1); // wait 1 second so server can create shared memory first.
  21. create_sync(&sync, &args); // Function comes from shm-sync-common.c
  22. // Receive packet
  23. sync_wait(sync.mutex); // Wait server to send a packet
  24. int pkt_size = sync.shared_memory[0]; // get packet size (first bytes of the shared memory)
  25. memset(sync.shared_memory+1, '0', pkt_size); // write 200 bytes of character '1'
  26. sync_notify(sync.mutex); // Notify server that we are done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement