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.
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.
}.