Vous êtes sur la page 1sur 83

| 

÷|÷   ÷ ÷÷



@ Each computer architecture provides its own
definition for the representation of data
@ Programmers who write programs for a single
computer do not need to think about data
representation
@ Compiler uses the computer¶s native data
representation when it allocates storage
@ Programmers who create client and software
must contend with data representation
J ÷  ÷ ÷ 

  ÷
@ Programmer can choose to embed
knowledge of the computer¶s architecture in
each client-server pair so the client and
server agree on which side will convert the
data
@ Called asymmetric data conversion because one
side or the other performs conversion
@ What is the main problem?
J ÷  ÷ ÷ 

  ÷
@ Programmer can choose to embed
knowledge of the computer¶s architecture in
each client-server pair so the client and
server agree on which side will convert the
data
@ Called asymmetric data conversion because one
side or the other performs conversion
@ Programmer must write a different version of the
client-server pair for each pair of architectures on
which they will be used
J ÷  ÷ ÷ 

  ÷
@ Consider a set of N computers
@ Assume each computer uses a different data
representation to store floating point numbers
@ A programmer must construct _______
versions of any client-server program that
exchanges floating point values
@ We called this n-squared conversion problem
@ Now add a new architecture to the set of N
machines
÷  ÷ ÷
@ JCP/IP protocol employs symmetric data
conversion
@ Both end performs the required conversion
@ Before sending across the network they
convert data from the sending computer¶s
native representation into a standard,
machine-independent representation
@ Likewise convert from machine-independent
representation to receivers native
representation
| 
@ Jhe standard representation used for data
traversing the network is known as the
eXternal Data Representation
@ Advantages?
@ Disadvantages?
| 
@ Jhe standard representation used for data
traversing the network is known as the
eXternal Data Representation
@ Advantages?
@ Disadvantages?
@ Computational overhead ± same architectures
@ Even for different architectures there is additional
computation due to an intermediate form
@ Conversion may result in a larger stream of bytes than
necessary
 ÷  | 
@ un¶s XDR
@ Has been used to communicate data
between diverse machines as un
Workstation*, VAX*, IBM-PC*, Cray*
@ XDR fits into the I Presentation Layer
@ Roughly analogous in purpose to X.409, I
Abstract yntax Notation
| 
@ XDR uses a language to describe data formats
@ Jhe language can be used only to describe data, it
is not a programming language
@ Allows one to describe intricate data formats in a
concise manner
@ Jhe alternative of using graphical representations (itself an
informal language) quickly becomes incomprehensible
when faced with complexity
@ imilar to C language
@ Protocols such as NC RPC and the NF* use
XDR
| 
@ XDR makes the following assumptions:
@ Bytes (or octets) are portable where a byte is
defined to be 8 bits of data
@ A given hardware device should encode the bytes
onto the various media in such a way that other
hardware devices may decode the bytes without
loss of meaning
| 
 

@ Jhe representation of all items requires a
multiple of four bytes (or 32 bits) of data
@ Jhe bytes are numbered 0 through n-1
@ Jhe bytes are read or written to some byte
stream such that byte m always precedes
byte m+1.
@ If the n bytes needed to contain the data are
not a multiple of four, then the n bytes are
followed by enough (0 to 3) residual zero
bytes, r, to make the total byte count a
multiple of 4.
|  J÷
Data Jype ize
int 32 bits
unsigned int 32 bits
bool 32 bits
enum arb
hyper 64 bits
unsigned hyper 64 bits
float 32 bits
|  J÷
double 64 bits
opaque arb
string -do-
fixed array -do-
counted array -do-
structure -do-
discriminated union -do-
void 0
symbolic constant arb
optional data arb
| 
÷÷
@ An XDR signed integer is a 32-bit datum that
encodes an integer in the range [-
2147483648,2147483647]. Jhe integer is
represented in two's complement notation.
Jhe most and least significant bytes are 0
and 3, respectively.
| 
÷÷÷
@ An XDR unsigned integer is a 32-bit datum
that encodes a nonnegative integer in the
range [0,4294967295]. It is represented by an
unsigned binary number whose most and
least significant bytes are 0 and 3,
respectively.
| ÷ 

@ Enumerations have the same representation
as signed integers
@ Enumerations are handy for describing
subsets of the integers
@ Enumerated data is declared as
÷  ÷÷ 
÷      
÷ 
÷ 
÷       
@ It is an error to encode as an enum any other integer than those that
have been given assignments in the enum declarations
|  ÷
@ Booleans are important enough and occur
frequently enough to warrant their own
explicit type in the standard.
@ Booleans are declared as follows:
 ÷ 
÷ 
@ Jhis is equivalent to:
÷ !"# $% &÷ 
÷ 
| ÷ ÷÷ 

÷÷ ÷÷ 
@ XDR standard also defines 64 bit (8 byte)
numbers called hyper integer and unsigned
hyper integer
@ Jheir representations are the obvious
extensions of integer and unsigned integer
defined before
@ Also represented in 2¶s complement notation
@ MB and LB are 0 and 7 respectively
|  


@ 32 bits or 4 bytes
@ Encoding used is the IEEE standard for
normalized single-precision floating point
numbers
|  


@ : Jhe sign of the number. Values 0 and 1
represent positive and negative, respectively.
ne bit.
@ E: Jhe exponent of the number, base 2. 8
bits are devoted to this field. Jhe exponent is
biased by 127.
@ F: Jhe fractional part of the number's
mantissa, base 2. 23 bits are devoted to this
field.
@ Jherefore the floating point is described by:
·&'((#(((·'(&!
| 
÷!÷ ÷

@ At times, fixed-length uninterpreted data
needs to be passed among machines.
@ Jhis data is called "opaque" and is declared
as follows:
@ opaque identifier [n];
@ where the constant n is the (static) number of
bytes necessary to contain the opaque data.
@ If n is not a multiple of four, then the n bytes are
followed by enough (0 to 3) residual zero bytes, r,
to make the total byte count of the opaque object
a multiple of four.
| 

@ Jhe standard defines a string of n (numbered 0
through n-1) ACII bytes to be the number n
encoded as an unsigned integer (as described
before), and followed by the n bytes of the string.
@ Byte m of the string always precedes byte m+1 of
the string, and byte 0 of the string always follows the
string's length.
@ If n is not a multiple of four, then the n bytes are
followed by enough (0 to 3) residual zero bytes, r, to
make the total byte count a multiple of four.
| 
÷!÷  
@ Declarations for fixed-length arrays of
homogeneous elements are in the following
form:
@ type-name identifier [n];
@ Fixed-length arrays of elements numbered 0
through n-1 are encoded by individually
encoding the elements of the array in their
natural order, 0 through n-1.
@ Each element's size is a multiple of four
bytes.
| 
÷!÷  
@ Jhough all elements are of the same type,
the elements may have different sizes.
@ For example, in a fixed-length array of
strings, all elements are of type "string", yet
each element will vary in its length.
| "
 ÷!÷  
@ Jhe array is encoded as the element count n (an
unsigned integer) followed by the encoding of each
of the array's elements, starting with element 0 and
progressing through element n- 1.
@ Jhe declaration for variable-length arrays follows
this form:
@ type-name identifier <m>; or
@ type-name identifier <>;
@ Jhe constant m specifies the maximum acceptable element
count of an array; if m is not specified, as in the second
declaration, it is assumed to be (2**32) - 1.
|   ÷
@ tructures are defined as follows:
  
 ) ÷ ÷    "
) ÷ ÷    
÷ 
÷ 
@ Jhe components of the structure are encoded
in the order of their declaration in the
structure
@ Each component's size is a multiple of four
bytes, though the components may be
different sizes.
|  
@ Jhe data declaration for a constant follows
this form:
@ const name-identifier = n;
@ "const" is used to define a symbolic name for
a constant; it does not declare any data.
@ Jhe symbolic constant may be used
anywhere a regular constant may be used.
@ For example, the following defines a symbolic
constant D EN, equal to 12.
@ const D EN = 12;
 # ÷  

| 
@ Most programmers could write the required
XDR conversion functions with little effort
@ However, some conversions require
considerable expertise
@ Converting from a computer¶s native floating point
to XDR standard without losing precision may
require an understanding of basic numerical
analysis
| !
   
÷
@ Jo convert between machine representation
and XDR standard (and vice versa)
@ Most implementations use a  

@ Buffer paradigm XDR requires a program to


allocate a buffer large enough to hold the
external representation of a message and to
add items (i.e., fields) one at a time
| !
   
÷


@ A program first invokes a procedure
0 ÷* ÷ ÷
@ It allocates a buffer in memory and inform XDR
that it intends to compose an external
representation in it
@ It initializes the XDR stream to be empty
@ It returns an pointer to the stream which must be
uses in successive calls to XDR routines
@ nce a program has created an XDR stream
it can call individual conversion routines to
convert
| !
   
÷


Procedure Arguments
xdr_bool xdrs, ptrbool
xdr_bytes xdrs, ptrstr, strsize,
maxsize
xdr_char xdrs, ptrchar
xdr_double xdrs, ptrdouble
xdr_enum xdrs, ptrint
xdr_float xdrs, ptrfloat
xdr_int xdrs, ip
|  ÷$J
@ After items have been converted the
application must call an I/ function like
À  ÷ to send it across a JCP connection
  ÷ #|  
÷


@ Write an XDR data description of a ³file´
which might be used to transfer files from one
machine to another
÷#÷ ÷÷
@ Chapter 19 of Douglas Comer book
@ RFC 1832
÷ ÷ ÷ ÷
@ Conceptual framework for building distributed
programs
@ Uses familiar concepts from conventional
programs
J  
# 




÷  
 


÷÷
÷

@ Programmer may miss important subtleties in
the application and may find that the protocol
does not provide all the needed functionality
@ Because few programmers have expertise
and experience with protocol design they
often produce awkward protocols
@ mall oversights in protocol design can lead to
fundamental errors that remain hidden until the
program run under stress
@ Programmer concentrates on communication,
it usually becomes the centerpiece



÷÷ ÷

@ Emphasizes the problem to be solved instead
of the communication needed
@ A programmer first designs a conventional
program to solve the problem, and then
divides the program into pieces that run on
two or more computers
÷ ÷ ÷ ÷
÷ ÷ 

 ÷
 # ÷
 
 ÷ ÷ ÷ 
@ In the procedural execution model, a single
a    a  flows through all
procedures


@ nown as un RPC, pen Network Computing
( NC) or simply RPC
@ NC RPC defines the format of message that the
caller (client) sends to invoke a remote procedure on
a server, the format of arguments, format of results
that the called procedure returns to the caller
@ NC RPC permits the calling program to use either
UDP or JCP to carry messages and uses XDR to
represent procedure arguments as well as other
items in an RPC message header
@ NC RPC includes a compiler system that help
programmers build distributed programs
automatically
 


@ NC RPC defines a remote execution
environment
@ It defines a 
a 
as the basic unit
of software that executes on a remote
machine
@ Each remote program contains a set of one
or more remote procedures plus global data
 


 ÷ ÷ ÷
÷
#
÷ ÷  
 ÷ ÷
÷
#
÷ ÷  
 ÷ ÷
@ Jhe procedures are numbered sequentially:
1,2,«N
@ By convention the number 0 is always reserved
for an echo procedure
@ Jo help ensure that program numbers
defined by separate organizations do not
conflict, NC RPC has divided the set of
programs into eight groups
÷
#
÷ ÷  
 ÷ ÷
  ÷  
÷  ÷ 
÷
portmap 1000000 port mapper

rstatd 1000001 rstat, rup and perfmeter

rusersd 1000002 remote users

nfs 1000003 network file system

ypserv 1000004 NI

mountd 1000005 mount, showmount


÷ 
÷÷ ÷
÷ 
÷÷ 
!÷÷%÷  & ÷
÷

@ NC RPC defines the semantics of a remote
procedure call by specifying that a program
should draw the weakest possible conclusion
from any interaction
@ NC RPC uses the term aa  

a  to describe RPC execution when
the caller receives a reply
@ NC RPC uses the term at   


a  to describe RPC execution when
the caller does not receive a reply
!÷÷%÷  & ÷
÷

@ In practice, zero-or-more semantics usually
means that a programmer makes each
remote procedure call idempotent

 &

 ! ÷ 

J ÷ ÷
& ÷  ÷ ÷
  
&÷ 
 
 
@ XDR library routines to convert from internal form to
standard external representation
@ XDR library routines that format the complex data
aggregates used to define RPC messages
@ RPC run time library routines that allow a program to
call a remote procedure, register a service with the
port mapper, or dispatch an incoming call to the
correct remote procedure
@ A program generator tool that produces many of the
C source files needed to build a distributed program
that uses RPC
  
÷
  

 ÷÷ 
÷
  

 ÷# 
@ tub (and skeleton) procedures
@ Dispatcher
÷
÷
÷ #
÷
÷  ÷ 
 ÷
÷
@ I -<none>- Initialize the database
@ i <word> Insert word
@ d <word> Delete word
@ l <word> Lookup word
@ q -<none>- Quit
J÷ 
 $
@ Handling of terminal I/ is a messy area
regardless of the operating system
@ Part of complexity of terminal I/ occurs
because people use terminal I/ for so many
different things: terminals, hardwired lines
between computers, modems, printers, and
so on.
@ Jhe functions we have already covered
( 
·') 
·' ÷·'
À  ÷·' and so on) are used by most
applications to do I/ to a terminal
J÷ 
  ÷
@ A classic terminal is a keyboard and a display
(or printer) that is connected to the computer
using an asynchronous communications port
@ From the perspective of the , the
important characteristic of a terminal is the
communications port that connects it to the
host and not the device sitting at the end of
the wire
J÷ 
  ÷
J÷ 
  ÷
J÷ 
  ÷
@ An asynchronous communications port can
be used to talk to other computers, printers,
plotters and special I/ equipments
@ erial Device
@ ends a character one bit at a time
@ Each character starts with a leading zero called
the start bit
@ Jhe data bits are sent one at a time, beginning
with LB and ending with the MB
@ Jhe last trailing bit is called the stop bit
J÷ 
  ÷
@ Most terminals operate in full-duplex
@ When you press a key, a character is sent
from the terminal to the computer
@ When it receives the character the computer
sends the character back to the terminal
where it is displayed
@ Jhis is called µechoing¶
@ A program can echo a special sequence
÷
J÷ 
  ÷÷ 
@ Jerminal parameters are all manipulated
through a data structure known as   
÷ 
@ +÷  ·' copies the parameters from
the  into a ÷  structure
@ ÷  ·' copies the parameters from a
÷  structure into the 
J÷ 
 $ ÷
@ Canonical Mode
@ Jerminal input is processed as lines
@ Non Canonical Mode
u   u
§include <termios.h>
   ÷ 

+*  *
+,( ) 
+(,

+*  *
+,( ) 
+(,

+*  *
+,(   
+(,

+*  *
+,(   
+(,
*  * -.//#0,(    1  ÷ (,
u   u
@ c_iflag
@ Controls the processing of input data
@ IJRIP ± mask characters to be masked to 7 bits
@ c_oflag
@ Controls processing of output data
@ P J ± system specific output processing
@ c_cflag
@ Controls information related to hardware
u   u
@ c_lflag
@ Controls echoing and character processing
@ ECH : turns on echoing
@ ICAN N: Jurns on input processing
@ IIG: Enables signals
@ J J P: tops background processes if they
write to the controlling terminal
@ c_cc
@ An array of control characters
u   u
@ c_cc
@ Control characters
@ Meaning of the members depends on the ICAN N flag
@ VE F - ^D may be used to generate E F from terminal
@ VE L ± E L character. ^j
@ VERAE ± Jypically backspace or delete erases the
preceding character
@ VINJR ± Jhe interrupt character (usually ^c or DEL)
generates a IGINJ
@ VILL ± Jhe kill character (^U) deletes the entire line from
the terminal
@ VQUIJ - ^\ generates a IGQUIJ
Õ÷
÷
÷ 
 

÷
§ ÷2 ÷ 13

  +÷  · 
 ÷÷   ÷ 
( ÷ ) '

  ÷  · 
 ÷÷ )      
÷ ( ÷ ) '
@ JCAN W ± change occurs immediately
@ JCADRAIN ± change occurs after all output has been transmitted
@ JCAFLUH ± change occurs after all output as been transmitted.
Further when change takes place all input data that has not been
read is discarded
Õ÷
÷
÷ 
 

÷
@ Jhe return status of ÷  confuses the programming. Jhis
function returns  if it was able to perform any of the requested
actions, even if it couldn't perform all the requested actions. If the
function returns , it is our responsibility to see whether all the
requested actions were performed. Jhis means that after we call
÷  to set the desired attributes, we need to call
+÷  and compare the actual terminal's attributes to the
desired attributes to detect any differences.

Vous aimerez peut-être aussi