Advertisement
tarruda

Untitled

Dec 9th, 2013
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. #include <unistd.h>
  2.  
  3. int
  4. main()
  5. {
  6.     uint32_t count;
  7.     uint32_t following_msg_size;
  8.     char buf[0xffff];
  9.  
  10.     while (1) {
  11.         following_msg_size = 0;
  12.         // read the size
  13.         read(0, buf, 4);
  14.         // unpack the size
  15.         following_msg_size = buf[0] << 24;
  16.         following_msg_size += buf[1] << 16;
  17.         following_msg_size += buf[2] << 8;
  18.         following_msg_size += buf[3];
  19.  
  20.                 // read the message
  21.         count = 0;
  22.         while (count < following_msg_size)
  23.             count += read(0, buf + count, following_msg_size - count);
  24.  
  25.         // parse the buffer
  26.         parse_msg(buf, following_msg_size);
  27.         following_msg_size = 0;
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement