XNSSocketBackdoor.mesa
Copyright © 1986 by Xerox Corporation. All rights reserved.
Hal Murray, March 8, 1986 4:43:51 pm PST
Demers, June 5, 1986 11:16:57 pm PDT
This is an interface for squeezing a few more cycles out of communications code. Don't use it unless you are desperate.
DIRECTORY
XNSBuf USING [Buffer],
XNSSocket USING [Handle];
XNSSocketBackdoor: CEDAR DEFINITIONS
~ {
Buffer: TYPE = XNSBuf.Buffer;
Handle: TYPE = XNSSocket.Handle;
Sending
PutCached: PROC [handle: Handle, b: Buffer];
FlushCache: PROC [handle: Handle];
These maintain a cache of the encapsulation and routing info. PutCached uses the cached value if it's there, bypassing all the cycles needed to recompute that info. Beware: There are complicated interactions with gateways going down, learning better routes, translation caches getting confused... In general you should call FlushCache occasionally, for example, once a minute and on every clump of retransmissions. The first PutCached[...] after a FlushCache[...] does a NEW.
NB: Unlike XNSSocket.Put or XNSSocket.Send, PutCached does NOT free the buffer.
Receiving
ReceiveProc: TYPE ~ PROC [handle: Handle, b: Buffer, clientData: REF ANY]
RETURNS [Buffer];
SetDirectReceive: PROC [handle: Handle, receiveProc: ReceiveProc, clientData: REF ANY];
This avoids the process switch associated with XNSSocket.Get. The client is expected to process the packet promptly. (Hanging on an ML will probably be fatal.) Returning NIL means that the client is keeping the buffer, otherwise, the buffer will be reused by the driver. It's ok to return a different buffer as long as it's a receive buffer associated with this socket.
NormalReceive: ReceiveProc;
This is the normal receive proc. It puts the buffer on the normal socket input queue where XNSSocket.Get will find it. Use this for a buffer that requires complicated processing, for example, printing an error message. Should only be called from a client's direct receive proc, e.g. RETURN[ NormalReceive[handle, b, NIL] ];
ReturnToSender can be passed a socket of NIL to avoid freeing the buffer.
}.