lat_unix.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * tcp_xact.c - simple TCP transaction latency test
  3. *
  4. * Three programs in one -
  5. * server usage: tcp_xact -s
  6. * client usage: tcp_xact hostname
  7. * shutwn: tcp_xact -hostname
  8. *
  9. * Copyright (c) 1994 Larry McVoy. Distributed under the FSF GPL with
  10. * additional restriction that results may published only if
  11. * (1) the benchmark is unmodified, and
  12. * (2) the version in the sccsid below is included in the report.
  13. * Support for this development by Sun Microsystems is gratefully acknowledged.
  14. */
  15. char *id = "$Id$\n";
  16. #include "bench.h"
  17. void client(int sock);
  18. void server(int sock);
  19. int
  20. main(int ac, char **av)
  21. {
  22. int sv[2];
  23. if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv) == -1) {
  24. perror("socketpair");
  25. }
  26. if (fork() == 0) {
  27. BENCH(client(sv[1]), MEDIUM);
  28. micro("AF_UNIX sock stream latency", get_n());
  29. kill(getppid(), SIGTERM);
  30. } else {
  31. server(sv[0]);
  32. }
  33. return(0);
  34. }
  35. void
  36. client(int sock)
  37. {
  38. char c;
  39. write(sock, &c, 1);
  40. read(sock, &c, 1);
  41. }
  42. void
  43. server(int sock)
  44. {
  45. char c;
  46. int n = 0;
  47. void exit();
  48. signal(SIGTERM, exit);
  49. while (read(sock, &c, 1) == 1) {
  50. write(sock, &c, 1);
  51. n++;
  52. }
  53. }