srv 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. .TH SRV 3
  2. .SH NAME
  3. srv \- server registry
  4. .SH SYNOPSIS
  5. .nf
  6. .B bind #s /srv
  7. .BI #s/ service1
  8. .BI #s/ service2
  9. ...
  10. .fi
  11. .SH DESCRIPTION
  12. The
  13. .I srv
  14. device provides a one-level directory holding
  15. already-open channels to services.
  16. In effect,
  17. .I srv
  18. is a bulletin board on which processes may post open file descriptors
  19. to make them available to other processes.
  20. .PP
  21. To install a channel, create
  22. a new file such as
  23. .B /srv/myserv
  24. and then write a text string (suitable for
  25. .IR strtoul ;
  26. see
  27. .IR atof (2))
  28. giving the file descriptor number of an open file.
  29. Any process may then open
  30. .B /srv/myserv
  31. to acquire another reference to the open file that was registered.
  32. .PP
  33. An entry in
  34. .I srv
  35. holds a reference to the associated file even if no process has the
  36. file open. Removing the file from
  37. .B /srv
  38. releases that reference.
  39. .PP
  40. It is an error to write more than one number into a server file,
  41. or to create a file with a name that is already being used.
  42. .SH EXAMPLE
  43. To drop one end of a pipe into
  44. .BR /srv ,
  45. that is, to create a named pipe:
  46. .IP
  47. .EX
  48. int fd, p[2];
  49. char buf[32];
  50. pipe(p);
  51. fd = create("/srv/namedpipe", OWRITE, 0666);
  52. fprint(fd, "%d", p[0]);
  53. close(fd);
  54. close(p[0]);
  55. fprint(p[1], "hello");
  56. .EE
  57. .PP
  58. At this point, any process may open and read
  59. .B /srv/namedpipe
  60. to receive the
  61. .B hello
  62. string. Data written to
  63. .B /srv/namedpipe
  64. can be received by executing
  65. .IP
  66. .EX
  67. read(p[1], buf, sizeof buf);
  68. .EE
  69. .PP
  70. in the above process.
  71. .SH SOURCE
  72. .B /sys/src/9/port/devsrv.c