Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unistd.h>
- int
- main()
- {
- uint32_t count;
- uint32_t following_msg_size;
- char buf[0xffff];
- while (1) {
- following_msg_size = 0;
- // read the size
- read(0, buf, 4);
- // unpack the size
- following_msg_size = buf[0] << 24;
- following_msg_size += buf[1] << 16;
- following_msg_size += buf[2] << 8;
- following_msg_size += buf[3];
- // read the message
- count = 0;
- while (count < following_msg_size)
- count += read(0, buf + count, following_msg_size - count);
- // parse the buffer
- parse_msg(buf, following_msg_size);
- following_msg_size = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement