BSD进程间通信高级编程指南,主要讲socket编程pdf.pdf
《BSD进程间通信高级编程指南,主要讲socket编程pdf.pdf》由会员分享,可在线阅读,更多相关《BSD进程间通信高级编程指南,主要讲socket编程pdf.pdf(46页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、An Advanced 4.4BSD Interprocess Communication TutorialSamuel J.LefflerRobert S.FabryWilliam N.JoyPhil LapsleyComputer Systems Research GroupDepartment of Electrical Engineering and Computer ScienceUniversity of California,BerkeleyBerkeley,California 94720Steve MillerChris TorekHeterogeneous Systems
2、LaboratoryDepartment of Computer ScienceUniversity of Maryland,College ParkCollege Park,Maryland 20742ABSTRACTThis document provides an introduction to the interprocess communication facili-ties included in the 4.4BSD release of the UNIX*system.It discusses the overall model for interprocess communi
3、cation and introduces theinterprocess communication primitives which have been added to the system.The major-ity of the document considers the use of these primitives in dev eloping applications.Thereader is expected to be familiar with the C programming language as all examples arewritten in C.*UNI
4、Xis a trademark of UNIX System Laboratories,Inc.in the US and some other countries.PSD:21-2 Advanced 4.4BSD IPC Tutorial1.INTRODUCTIONOne of the most important additions to UNIX in 4.2BSD was interprocess communication.These facilitieswere the result of more than two years of discussion and research
5、.The facilities provided in 4.2BSD incor-porated many of the ideas from current research,while trying to maintain the UNIX philosophy of simplic-ity and conciseness.The 4.3BSD release of Berkeley UNIX improved upon some of the IPC facilitieswhile providing an upward-compatible interface.4.4BSD adds
6、support for ISO protocols and IP multicast-ing.The BSD interprocess communication facilities have become a defacto standard for UNIX.UNIX has previously been very weak in the area of interprocess communication.Prior to the 4BSDfacilities,the only standard mechanism which allowed two processes to com
7、municate were pipes(the mpxfiles which were part of Version 7 were experimental).Unfortunately,pipes are very restrictive in that thetwo communicating processes must be related through a common ancestor.Further,the semantics of pipesmakes them almost impossible to maintain in a distributed environme
8、nt.Earlier attempts at extending the IPC facilities of UNIX have met with mixed reaction.The majorityof the problems have been related to the fact that these facilities have been tied to the UNIX file system,either through naming or implementation.Consequently,the IPC facilities provided in 4.2BSD w
9、eredesigned as a totally independent subsystem.The BSD IPC allows processes to rendezvous in many ways.Processes may rendezvous through a UNIX file system-like name space(a space where all names are pathnames)as well as through a network name space.In fact,new name spaces may be added at a future ti
10、mewith only minor changes visible to users.Further,the communication facilities have been extended toinclude more than the simple byte stream provided by a pipe.These extensions have resulted in a com-pletely new part of the system which users will need time to familiarize themselves with.It is like
11、ly that asmore use is made of these facilities they will be refined;only time will tell.This document provides a high-level description of the IPC facilities in 4.4BSD and their use.It isdesigned to complement the manual pages for the IPC primitives by examples of their use.The remainderof this docu
12、ment is organized in four sections.Section 2 introduces the IPC-related system calls and thebasic model of communication.Section 3 describes some of the supporting library routines users may finduseful in constructing distributed applications.Section 4 is concerned with the client/server model used
13、indeveloping applications and includes examples of the two major types of servers.Section 5 delves intoadvanced topics which sophisticated users are likely to encounter when using the IPC facilities.Advanced 4.4BSD IPC Tutorial PSD:21-32.BASICSThe basic building block for communication is the socket
14、.A socket is an endpoint of communicationto which a name may be bound.Each socket in use has a type and one or more associated processes.Sock-ets exist within communication domains.A communication domain is an abstraction introduced to bundlecommon properties of processes communicating through socke
15、ts.One such property is the scheme used toname sockets.For example,in the UNIX communication domain sockets are named with UNIX pathnames;e.g.a socket may be named/dev/foo.Sockets normally exchange data only with sockets in thesame domain(it may be possible to cross domain boundaries,but only if som
16、e translation process is per-formed).The 4.4BSD IPC facilities support four separate communication domains:the UNIX domain,foron-system communication;the Internet domain,which is used by processes which communicate using theInternet standard communication protocols;the NS domain,which is used by pro
17、cesses which communi-cate using the Xerox standard communication protocols*;and the ISO OSI protocols,which are not docu-mented in this tutorial.The underlying communication facilities provided by these domains have a signifi-cant influence on the internal system implementation as well as the interf
18、ace to socket facilities available toa user.An example of the latter is that a socket operating in the UNIX domain sees a subset of the errorconditions which are possible when operating in the Internet(or NS)domain.2.1.Socket typesSockets are typed according to the communication properties visible t
19、o a user.Processes are pre-sumed to communicate only between sockets of the same type,although there is nothing that prevents com-munication between sockets of different types should the underlying communication protocols support this.Four types of sockets currently are available to a user.A stream
20、socket provides for the bidirectional,reliable,sequenced,and unduplicated flow of data without record boundaries.Aside from the bidirectional-ity of data flow,a pair of connected stream sockets provides an interface nearly identical to that of pipes.A datagram socket supports bidirectional flow of d
21、ata which is not promised to be sequenced,reli-able,or unduplicated.That is,a process receiving messages on a datagram socket may find messagesduplicated,and,possibly,in an order different from the order in which it was sent.An important character-istic of a datagram socket is that record boundaries
22、 in data are preserved.Datagram sockets closely modelthe facilities found in many contemporary packet switched networks such as the Ethernet.A raw socket provides users access to the underlying communication protocols which support socketabstractions.These sockets are normally datagram oriented,thou
23、gh their exact characteristics are depen-dent on the interface provided by the protocol.Raw sockets are not intended for the general user;they hav ebeen provided mainly for those interested in developing new communication protocols,or for gainingaccess to some of the more esoteric facilities of an e
24、xisting protocol.The use of raw sockets is consideredin section 5.A sequenced packet socket is similar to a stream socket,with the exception that record boundaries arepreserved.This interface is provided only as part of the NS socket abstraction,and is very important inmost serious NS applications.S
25、equenced-packet sockets allow the user to manipulate the SPP or IDP head-ers on a packet or a group of packets either by writing a prototype header along with whatever data is to besent,or by specifying a default header to be used with all outgoing data,and allows the user to receive theheaders on i
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- BSD 进程 通信 高级 编程 指南 主要 socket pdf
限制150内