home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / share / doc / ps1 / 06.sysman / 2.1.t < prev    next >
Encoding:
Text File  |  1991-04-17  |  5.9 KB  |  139 lines

  1. .\" Copyright (c) 1983 The Regents of the University of California.
  2. .\" All rights reserved.
  3. .\"
  4. .\" Redistribution and use in source and binary forms, with or without
  5. .\" modification, are permitted provided that the following conditions
  6. .\" are met:
  7. .\" 1. Redistributions of source code must retain the above copyright
  8. .\"    notice, this list of conditions and the following disclaimer.
  9. .\" 2. Redistributions in binary form must reproduce the above copyright
  10. .\"    notice, this list of conditions and the following disclaimer in the
  11. .\"    documentation and/or other materials provided with the distribution.
  12. .\" 3. All advertising materials mentioning features or use of this software
  13. .\"    must display the following acknowledgement:
  14. .\"    This product includes software developed by the University of
  15. .\"    California, Berkeley and its contributors.
  16. .\" 4. Neither the name of the University nor the names of its contributors
  17. .\"    may be used to endorse or promote products derived from this software
  18. .\"    without specific prior written permission.
  19. .\"
  20. .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  21. .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23. .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  24. .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25. .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  26. .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27. .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28. .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  29. .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. .\" SUCH DAMAGE.
  31. .\"
  32. .\"    @(#)2.1.t    6.3 (Berkeley) 4/17/91
  33. .\"
  34. .sh "Generic operations
  35. .PP
  36. .PP
  37. Many system abstractions support the
  38. operations \fIread\fP, \fIwrite\fP and \fIioctl\fP.  We describe
  39. the basics of these common primitives here.
  40. Similarly, the mechanisms whereby normally synchronous operations
  41. may occur in a non-blocking or asynchronous fashion are
  42. common to all system-defined abstractions and are described here.
  43. .NH 3
  44. Read and write
  45. .PP
  46. The \fIread\fP and \fIwrite\fP system calls can be applied
  47. to communications channels, files, terminals and devices.
  48. They have the form:
  49. .DS
  50. cc = read(fd, buf, nbytes);
  51. result int cc; int fd; result caddr_t buf; int nbytes;
  52.  
  53. cc = write(fd, buf, nbytes);
  54. result int cc; int fd; caddr_t buf; int nbytes;
  55. .DE
  56. The \fIread\fP call transfers as much data as possible from the
  57. object defined by \fIfd\fP to the buffer at address \fIbuf\fP of
  58. size \fInbytes\fP.  The number of bytes transferred is
  59. returned in \fIcc\fP, which is \-1 if a return occurred before
  60. any data was transferred because of an error or use of non-blocking
  61. operations.
  62. .PP
  63. The \fIwrite\fP call transfers data from the buffer to the
  64. object defined by \fIfd\fP.  Depending on the type of \fIfd\fP,
  65. it is possible that the \fIwrite\fP call will accept some portion
  66. of the provided bytes; the user should resubmit the other bytes
  67. in a later request in this case.
  68. Error returns because of interrupted or otherwise incomplete operations
  69. are possible.
  70. .PP
  71. Scattering of data on input or gathering of data for output
  72. is also possible using an array of input/output vector descriptors.
  73. The type for the descriptors is defined in \fI<sys/uio.h>\fP as:
  74. .DS
  75. ._f
  76. struct iovec {
  77.     caddr_t    iov_msg;    /* base of a component */
  78.     int    iov_len;    /* length of a component */
  79. };
  80. .DE
  81. The calls using an array of descriptors are:
  82. .DS
  83. cc = readv(fd, iov, iovlen);
  84. result int cc; int fd; struct iovec *iov; int iovlen;
  85.  
  86. cc = writev(fd, iov, iovlen);
  87. result int cc; int fd; struct iovec *iov; int iovlen;
  88. .DE
  89. Here \fIiovlen\fP is the count of elements in the \fIiov\fP array.
  90. .NH 3
  91. Input/output control
  92. .PP
  93. Control operations on an object are performed by the \fIioctl\fP
  94. operation:
  95. .DS
  96. ioctl(fd, request, buffer);
  97. int fd, request; caddr_t buffer;
  98. .DE
  99. This operation causes the specified \fIrequest\fP to be performed
  100. on the object \fIfd\fP.  The \fIrequest\fP parameter specifies
  101. whether the argument buffer is to be read, written, read and written,
  102. or is not needed, and also the size of the buffer, as well as the
  103. request.
  104. Different descriptor types and subtypes within descriptor types
  105. may use distinct \fIioctl\fP requests.  For example,
  106. operations on terminals control flushing of input and output
  107. queues and setting of terminal parameters; operations on
  108. disks cause formatting operations to occur; operations on tapes
  109. control tape positioning.
  110. .PP
  111. The names for basic control operations are defined in \fI<sys/ioctl.h>\fP.
  112. .NH 3
  113. Non-blocking and asynchronous operations
  114. .PP
  115. A process that wishes to do non-blocking operations on one of
  116. its descriptors sets the descriptor in non-blocking mode as
  117. described in section 1.5.4.  Thereafter the \fIread\fP call will
  118. return a specific EWOULDBLOCK error indication if there is no data to be
  119. \fIread\fP.  The process may
  120. \fIselect\fP the associated descriptor to determine when a read is
  121. possible.
  122. .PP
  123. Output attempted when a descriptor can accept less than is requested
  124. will either accept some of the provided data, returning a shorter than normal
  125. length, or return an error indicating that the operation would block.
  126. More output can be performed as soon as a \fIselect\fP call indicates
  127. the object is writeable.
  128. .PP
  129. Operations other than data input or output
  130. may be performed on a descriptor in a non-blocking fashion.
  131. These operations will return with a characteristic error indicating
  132. that they are in progress
  133. if they cannot complete immediately.  The descriptor
  134. may then be \fIselect\fPed for \fIwrite\fP to find out
  135. when the operation has been completed.  When \fIselect\fP indicates
  136. the descriptor is writeable, the operation has completed.
  137. Depending on the nature of the descriptor and the operation,
  138. additional activity may be started or the new state may be tested.
  139.