⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1.5.t

📁 早期freebsd实现
💻 T
字号:
.\" Copyright (c) 1983, 1993.\"	The Regents of the University of California.  All rights reserved..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\"    notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\"    notice, this list of conditions and the following disclaimer in the.\"    documentation and/or other materials provided with the distribution..\" 3. All advertising materials mentioning features or use of this software.\"    must display the following acknowledgement:.\"	This product includes software developed by the University of.\"	California, Berkeley and its contributors..\" 4. Neither the name of the University nor the names of its contributors.\"    may be used to endorse or promote products derived from this software.\"    without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION).\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF.\" SUCH DAMAGE..\".\"	@(#)1.5.t	8.1 (Berkeley) 6/8/93.\".sh Descriptors.PP.NH 3The reference table.PPEach process has access to resources through\fIdescriptors\fP.  Each descriptor is a handle allowingthe process to reference objects such as files, devicesand communications links..PPRather than allowing processes direct access to descriptors, the systemintroduces a level of indirection, so that descriptors may be sharedbetween processes.  Each process has a \fIdescriptor reference table\fP,containing pointers to the actual descriptors.  The descriptorsthemselves thus have multiple references, and are reference counted by thesystem..PPEach process has a fixed size descriptor reference table, wherethe size is returned by the \fIgetdtablesize\fP call:.DSnds = getdtablesize();result int nds;.DEand guaranteed to be at least 20.  The entries in the descriptor referencetable are referred to by small integers; for example if thereare 20 slots they are numbered 0 to 19..NH 3Descriptor properties.PPEach descriptor has a logical set of properties maintainedby the system and defined by its \fItype\fP.Each type supports a set of operations;some operations, such as reading and writing, are common to severalabstractions, while others are unique.The generic operations applying to many of these types are describedin section 2.1.  Naming contexts, files and directories are described insection 2.2.  Section 2.3 describes communications domains and sockets.Terminals and (structured and unstructured) devices are describedin section 2.4..NH 3Managing descriptor references.PPA duplicate of a descriptor reference may be made by doing.DSnew = dup(old);result int new; int old;.DEreturning a copy of descriptor reference \fIold\fP indistinguishable fromthe original.  The \fInew\fP chosen by the system will be thesmallest unused descriptor reference slot.A copy of a descriptor reference may be made in a specific slotby doing.DSdup2(old, new);int old, new;.DEThe \fIdup2\fP call causes the system to deallocate the descriptor referencecurrent occupying slot \fInew\fP, if any, replacing it with a referenceto the same descriptor as old.This deallocation is also performed by:.DSclose(old);int old;.DE.NH 3Multiplexing requests.PPThe system provides astandard way to dosynchronous and asynchronous multiplexing of operations..PPSynchronous multiplexing is performed by using the \fIselect\fP callto examine the state of multiple descriptors simultaneously,and to wait for state changes on those descriptors.Sets of descriptors of interest are specified as bit masks,as follows:.DS#include <sys/types.h>nds = select(nd, in, out, except, tvp);result int nds; int nd; result fd_set *in, *out, *except;struct timeval *tvp;FD_ZERO(&fdset);FD_SET(fd, &fdset);FD_CLR(fd, &fdset);FD_ISSET(fd, &fdset);int fs; fs_set fdset;.DEThe \fIselect\fP call examines the descriptorsspecified by thesets \fIin\fP, \fIout\fP and \fIexcept\fP, replacingthe specified bit masks by the subsets that select true for input,output, and exceptional conditions respectively (\fInd\fPindicates the number of file descriptors specified by the bit masks).If any descriptors meet the following criteria,then the number of such descriptors is returned in \fInds\fP and thebit masks are updated..if n .ds bu *.if t .ds bu \(bu.IP \*(buA descriptor selects for input if an input oriented operationsuch as \fIread\fP or \fIreceive\fP is possible, or if aconnection request may be accepted (see section 2.3.1.4)..IP \*(buA descriptor selects for output if an output oriented operationsuch as \fIwrite\fP or \fIsend\fP is possible, or if an operationthat was ``in progress'', such as connection establishment,has completed (see section 2.1.3)..IP \*(buA descriptor selects for an exceptional condition if a conditionthat would cause a SIGURG signal to be generated exists (see section 1.3.2),or other device-specific events have occurred..LPIf none of the specified conditions is true, the operationwaits for one of the conditions to arise,blocking at most the amount of time specified by \fItvp\fP.If \fItvp\fP is given as 0, the \fIselect\fP waits indefinitely..PPOptions affecting I/O on a descriptormay be read and set by the call:.DS._ddopt = fcntl(d, cmd, arg)result int dopt; int d, cmd, arg;/* interesting values for cmd */#define	F_SETFL	3	/* set descriptor options */#define	F_GETFL	4	/* get descriptor options */#define	F_SETOWN	5	/* set descriptor owner (pid/pgrp) */#define	F_GETOWN	6	/* get descriptor owner (pid/pgrp) */.DEThe F_SETFL \fIcmd\fP may be used to set a descriptor in non-blocking I/O mode and/or enable signaling when I/O ispossible.  F_SETOWN may be used to specify a process or processgroup to be signaled when using the latter mode of operationor when urgent indications arise..PPOperations on non-blocking descriptors willeither complete immediately,note an error EWOULDBLOCK,partially complete an input or output operation returning a partial count,or return an error EINPROGRESS noting that the requested operation isin progress.A descriptor which has signalling enabled will cause the specified processand/or process groupbe signaled, with a SIGIO for input, output, or in-progressoperation complete, ora SIGURG for exceptional conditions..PPFor example, when writing to a terminalusing non-blocking output,the system will accept only as much data as there is buffer space forand return; when making a connection on a \fIsocket\fP, the operation mayreturn indicating that the connection establishment is ``in progress''.The \fIselect\fP facility can be used to determine when furtheroutput is possible on the terminal, or when the connection establishmentattempt is complete..NH 3Descriptor wrapping.\(dg.PP.FS\(dg The facilities described in this section are not includedin 4.3BSD..FEA user process may build descriptors of a specified type by\fIwrapping\fP a communications channel with a system supplied protocoltranslator:.DSnew = wrap(old, proto)result int new; int old; struct dprop *proto;.DEOperations on the descriptor \fIold\fP are then translated by thesystem provided protocol translator into requests on the underlyingobject \fIold\fP in a way defined by the protocol.The protocols supported by the kernel may vary from system to systemand are described in the programmers manual..PPProtocols may be based on communications multiplexing or a rights-passingstyle of handling multiple requests made on the same object.  For instance,a protocol for implementing a file abstraction may or may not includelocally generated ``read-ahead'' requests.  A protocol that provides forread-ahead may provide higher performance but have a more difficultimplementation..PPAnother example is the terminal driving facilities.  Normally a terminalis associated with a communications line, and the terminal typeand standard terminal access protocol are wrapped around a synchronouscommunications line and given to the user.  If a virtual terminalis required, the terminal driver can be wrapped around a communicationslink, the other end of which is held by a virtual terminal protocolinterpreter.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -