Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ---- Server code ------
- // Initialize shared memory
- struct Sync sync;
- struct Arguments args;
- args.size = 2048 // Total size of the shared memory (it's not the same as packet size)
- create_sync(&sync, &args); // Function comes from shm-sync-common.c
- // Send packet
- int pkt_size = 200;
- sync.shared_memory[0] = pkt_size; // Supose this indicates a packet size of 200 bytes
- memset(sync.shared_memory+1, '1', pkt_size); // write 200 bytes of character '1'
- sync_notify(sync.mutex); // Notify the client of the packet to transmit
- sync_wait(sync.mutex); // Wait client to process it
- // ---- Client code ------
- // Initialize shared memory
- struct Sync sync;
- struct Arguments args;
- args.size = 2048 // Total size of the shared memory (it's not the same as packet size)
- sleep(1); // wait 1 second so server can create shared memory first.
- create_sync(&sync, &args); // Function comes from shm-sync-common.c
- // Receive packet
- sync_wait(sync.mutex); // Wait server to send a packet
- int pkt_size = sync.shared_memory[0]; // get packet size (first bytes of the shared memory)
- memset(sync.shared_memory+1, '0', pkt_size); // write 200 bytes of character '1'
- sync_notify(sync.mutex); // Notify server that we are done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement