str_echo09.c 326 B

12345678910111213141516171819
  1. #include "unp.h"
  2. #include "sum.h"
  3. void
  4. str_echo(int sockfd)
  5. {
  6. ssize_t n;
  7. struct args args;
  8. struct result result;
  9. for ( ; ; ) {
  10. if ( (n = Readn(sockfd, &args, sizeof(args))) == 0)
  11. return; /* connection closed by other end */
  12. result.sum = args.arg1 + args.arg2;
  13. Writen(sockfd, &result, sizeof(result));
  14. }
  15. }