next up previous contents
Next: Control Operations Up: Example Protocol Previous: Demultiplexing Incoming Messages

Sending and Receiving Messages

We now turn our attention to the ASP-specific implementation of xPush and xPop--- aspPush and aspPop---the two routines that embody the semantics of ASP. Because of its simple nature, aspPush simply prepends a copy of the header stored in the session state onto the outgoing message, and passes the resulting message to the IP session beneath it. The header template found in the session state already contains the appropriate local and remote ASP ports, since these will not change in the lifetime of a session. However, the message length must be calculated and inserted into the appropriate header field. Subroutine aspHdrStore, as defined in the previous subsection, converts this header template from host byte order to network byte order.

static XkHandle 
aspPush(Sessn self, Msg *msg)
{
    SessnState *sstate = (SessnState *)self->state;
    ASPhdr     hdr;
    char       *buf;

    /* create a header by inserting length into header template */
    hdr = sstate->hdr;
    hdr.ulen = msgLength(msg) + HLEN;

    /* attach header to message and pass it on down the stack */
    buf = msgPush(msg, HLEN);
    aspHdrStore(&hdr, buf, HLEN);
    return xPush(xGetSessnDown(self, 0), msg);
}

Again because of its simplicity, the only work that aspPop performs is to check the length field in the message header, and truncate the message, if necessary. Notice that the last thing aspPop does is invoke xDemux on the high-level protocol that had earlier opened the session.

static XkReturn
aspPop(Sessn self, Sessn lls, Msg *msg, void *hdr)
{
    ASPhdr *h = (ASPhdr *)hdr;

    /* truncate message to length shown in header */
    if (h->ulen - HLEN < msgLength(msg))
        msgTruncate(msg, (int)h->ulen);

    /* pass the message to the next protocol up the stack */
    return xDemux(xGetUp(self), self, msg);
}



Larry Peterson
Wed Feb 21 13:58:06 MST 1996