DatagramSocket.mesa
Copyright Ó 1991 by Xerox Corporation. All rights reserved.
Demers, November 2, 1988 10:24:13 am PST
Carl Hauser, November 21, 1988 4:49:00 pm PST
Willie-s, August 13, 1991 4:10 pm PDT
Michael Plass, August 27, 1991 2:23 pm PDT
DIRECTORY
Arpa USING [Address],
ArpaUDP USING [nullPort, Port],
Basics USING [UnsafeBlock]
;
DatagramSocket: CEDAR DEFINITIONS ~ {
Types
Handle: TYPE ~ REF Object;
Object: TYPE;
waitForever: CARD ~ CARD.LAST;
Datagram Sockets
Create: PROC [localPort: ArpaUDP.Port ¬ ArpaUDP.nullPort] RETURNS [Handle];
Create a socket handle.
If local port is defaulted, the system will pick one that is not currently in use.
If a specified local port is already in use, behavior is SYSTEM-DEPENDENT.
On D-machines, the new handle is pushed over the previous one. The old one can still be used to send datagrams, but the new one will get all received datagrams.
In Unix, the Create call fails.
! Error[$portInUse].
GetLocal: PROC [h: Handle] RETURNS [address: Arpa.Address, port: ArpaUDP.Port];
Get the local host and port associated with a handle.
! (no errors).
GetMaxDatagramSize: PROC [h: Handle] RETURNS [maxBytes: CARD];
Return max datagram size that can be sent/received on this handle. This value is SYSTEM-DEPENDENT. It is guaranteed to be >= 1KB. It is likely, but not guaranteed, to be the same for all handles.
! (no errors).
Destroy: PROC [h: Handle];
Destroy the handle.
Dropping on the floor is safe, but may waste resources.
Send: PROC [h: Handle, toAddress: Arpa.Address, toPort: ArpaUDP.Port, b: REF TEXT, startIndex: NAT ¬ 0, count: NAT ¬ NAT.LAST];
Send a datagram to the given address and port.
The datagram comprises b[startIndex] ... b[MIN[b.length, startIndex+count]].
! Error[$unreachable, $transientError, $datagramTooShort, $datagramTooLong, $invalidBuffer].
UnsafeSend: UNSAFE PROC [h: Handle, toAddress: Arpa.Address, toPort: ArpaUDP.Port, b: Basics.UnsafeBlock];
Send the datagram described by b to the given address and port.
! Error[$unreachable, $transientError, $datagramTooShort, $datagramTooLong, $invalidBuffer].
Recv: PROC [h: Handle, b: REF TEXT, startIndex: NAT ¬ 0, count: NAT ¬ NAT.LAST, timeoutMsec: CARD ¬ waitForever] RETURNS [nBytesRead: NAT, fromAddress: Arpa.Address, fromPort: ArpaUDP.Port];
Receive a datagram, storing it in b[startIndex] .. b[startIndex+nBytesRead].
Error if (startIndex+nBytesRead) >= b.maxLength.
! Error[$timeout, $transientError, $datagramTooShort, $datagramTooLong, $invalidBuffer].
UnsafeRecv: UNSAFE PROC [h: Handle, b: Basics.UnsafeBlock, timeoutMsec: CARD ¬ CARD.LAST] RETURNS [nBytesRead: INT, fromAddress: Arpa.Address, fromPort: ArpaUDP.Port];
Receive a datagram, storing it in b.
Error if nBytesRead > b.count.
! Error[$timeout, $transientError, $datagramTooShort, $datagramTooLong, $invalidBuffer].
Kick: PROC [h: Handle];
Wakeup any process waiting for read.
Errors
Error: ERROR [code: ATOM];
$timeout => timeout on Recv
$unreachable
$transientError
$portInUse
$datagramTooShort
$datagramTooLong
$invalidBuffer
$handleDestroyed
. . .
}.