sk_rcvAndDispatch()

Description

The sk_rcvAndDispatch() is a replacement for sk_rcvMessage() that knows about handler functions. If you are using handler functions anywhere in your code, always call sk_rcvAndDispatch(), or the messages will not be dispatched correctly. When a message arrives, sk_rcvAndDispatch() determines if there is any handler function associated with that message. If so, it calls the handler with the appropriate arguments.

sk_rcvAndDispatch() calls the handler function with any tag received and, if this message is an acknowledgment, it also passes in a pointer to the original MsgStruct that triggered this acknowledgment. Notice that all messages passed to the handler function are already unpacked. sk_rcvAndDispatch() returns whatever integer the handler function returns. Because the main sk_rcvAndDispatch() loop checks the return values, it is important that all of the handler functions return a valid integer. Any integer may be returned. Since many SwitchKit #defines use negative integers for many error codes, for example SK_LOST_LLC is -3, you should restrict yourself to returning non-negative integers only.

If there is no associated handler function, rcvAndDispatch returns SK_NOT_HANDLED, and its buffer and size are filled in, just as if sk_rcvMessage() had been called. The application module can then unpack and handle the undispatched message.

This message is also available as sk_rcvAndDispatchOnConnection() and skts_rcvAndDispatch().

Syntax

int sk_rcvAndDispatch(char *aBuffer, int *aBufSize, double aTimeout, void **aTag);

int sk_rcvAndDispatchOnConnection(char *aBuffer, int *aBufSize, double aTimeout, void **aTag, int *aConIDPtr);

Parameters

The function parameters are shown in the table below.

Argument

Description

aBuffer

Pointer to a packed message.

aBufSize

Size of the packed message.

aTimeout

The maximum time the function should wait for a message before returning. The timeout value is a floating point number allow the application to specify a fractional portion to the timeout. For example, a timeout value of 1.5 seconds would be interpreted as a one and one-half second timeout. If no message arrives which is destined for the application in the specified time, the function should return SK_NO_MESSAGE.

aTag

 

The application-defined pointer that is only valid if the function returns SK_NOT_HANDLED. The value was set in either the original message send operation if the message is an acknowledgement or was set when the handler was defined if the message is switch-initiated.

aConIDPtr

This is used to identify from which LLC connection the message was received.