beautypg.com

Apple Newton Programmer’s Newton 2.0 (for Newton 2.0) User Manual

Page 800

background image

C H A P T E R 2 2

Transport Interface

22-12

Using the Transport Interface

Handling Requests When the Transport Is Active

22

While the transport is actively sending or receiving data in the background, the user
might request another send or receive operation from the In/Out Box. One way to
handle such requests is to queue them up and append them to the current communi-
cation transaction or to start another connection when the transport is finished.

You can use the transport method

QueueRequest

to queue up requests for

sending or receiving, if the transport already has an active communication session
in progress. Call

QueueRequest

from the

SendRequest

or

ReceiveRequest

method, whichever one you receive as a result of a user request.

Depending on how you call it, you can make

QueueRequest

append the new

request to a request in progress or start another connection when the current
request is finished. To append the new request to one in progress, for the first
parameter, specify the request frame of a request already in progress. A request
frame is the frame passed to

SendRequest

or

ReceiveRequest

to begin the

request in progress. The second parameter is the new request frame.

The following is an example of a

SendRequest

method in which

QueueRequest

is called to append the new request to the one in progress.

// SendRequest method

func (newRequest)

begin

if status <> 'idle then // check if I’m active

// append to current request

:QueueRequest(currentRequest, newRequest);

else

// do a normal send here

end,

When a new request is appended to an in-progress request, items from the new
request are returned from the

ItemRequest

method after all items from the

in-progress request are exhausted. In this way, new items are sent as part of the
current communication session.

To queue a new request so that the transport finishes its current transaction before
beginning a new one, specify a symbol for the first parameter of

QueueRequest

.

The symbol should be the name of a method that you want the system to call when
the transport state returns to idle. Usually this is another

SendRequest

or

ReceiveRequest

method. The following is an example of a

SendRequest

method in which

QueueRequest

is called to defer a new request until the

transport returns to the idle state.