next up previous contents index
Next: 32.1.4 Transmitting user data Up: 32.1 Using application-level data Previous: 32.1.2 Passing data between

32.1.3 Transmitting user data over UDP

Currently there are no supports in class Agent to transmit user data. There are two ways to transmit serialized ADU through transport agents. First, for UDP agent (and all agents derived from there), we can derive from class UDP and add a new method send(int nbytes, char *userdata) to pass user data from Application to Agent. To pass data from an Agent to an Application is somewhat trickier: each agent has a pointer to its attached application, we dynamically cast this pointer to an AppConnector and then call AppConnector::process_data().

As an example, we illustrate how class HttpInvalAgent is implemented. It is based on UDP, and is inteded to deliver web cache invalidation messages (/webcache/inval-agent.h). It is defined as:

        class HttpInvalAgent : public Agent {
        public: 
                HttpInvalAgent();

                virtual void recv(Packet *, Handler *);
                virtual void send(int realsize, AppData* data);

        protected:
                int off\_inv\_;
        };

Here recv(Packet*, Handler*) overridden to extract user data, and a new send(int, AppData*) is provided to include user data in packetes. An application (HttpApp) is attached to an HttpInvalAgent using Agent::attachApp() (a dynamic cast is needed). In send(), the following code is used to write user data from AppData to the user data area in a packet:

        Packet *pkt = allocpkt(data-\>size());
        hdr\_inval *ih = (hdr\_inval *)pkt-\>access(off\_inv\_);
        ih-\>size() = data-\>size();
        char *p = (char *)pkt-\>accessdata();
        data-\>pack(p);

In recv(), the following code is used to read user data from packet and to deliver to the attached application:

        hdr\_inval *ih = (hdr\_inval *)pkt-\>access(off\_inv\_);
        ((HttpApp*)app\_)-\>process\_data(ih-\>size(), (char *)pkt-\>accessdata());
        Packet::free(pkt);


next up previous contents index
Next: 32.1.4 Transmitting user data Up: 32.1 Using application-level data Previous: 32.1.2 Passing data between

2000-08-24