Advertisement
vojtarek

unix network read

Mar 12th, 2011
493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.32 KB | None | 0 0
  1.     string msg;
  2.     ssize_t n;
  3.     char buf[MAXLINE + 1];
  4.     do {
  5.         n = read(t, buf, MAXLINE);
  6.  
  7.         if (n < 0 && errno == EINTR) {
  8.             continue;
  9.         } else if (n < 0) {
  10.             // ERROR
  11.             return -1;
  12.         }
  13.         buf[n] = 0;
  14.         msg.append(buf);
  15.     } while (n != 0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement