dgecholoop2.c 483 B

1234567891011121314151617181920212223242526272829303132
  1. #include "unp.h"
  2. static void recvfrom_int(int);
  3. static int count;
  4. void
  5. dg_echo(int sockfd, SA *pcliaddr, socklen_t clilen)
  6. {
  7. int n;
  8. socklen_t len;
  9. char mesg[MAXLINE];
  10. Signal(SIGINT, recvfrom_int);
  11. n = 220 * 1024;
  12. Setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &n, sizeof(n));
  13. for ( ; ; ) {
  14. len = clilen;
  15. Recvfrom(sockfd, mesg, MAXLINE, 0, pcliaddr, &len);
  16. count++;
  17. }
  18. }
  19. static void
  20. recvfrom_int(int signo)
  21. {
  22. printf("\nreceived %d datagrams\n", count);
  23. exit(0);
  24. }