10.6.2 The recv() and timeout() Methods

The []recv method is not defined here, as this agent represents a request function and will generally not be receiving events or packets10.1. By not defining the []recv method, the base class version of []recv (, []Connector::recv) is used. The []timeout method is used to periodically send request packets. The following []timeout method is used, along with a helper method, []sendit:

        void ECHO_Agent::timeout(int)
        {
                sendit();
                echo_timer_.resched(interval_);
        }

        void ECHO_Agent::sendit()
        {
                Packet* p = allocpkt();
                ECHOHeader *eh = ECHOHeader::access(p-\>bits());
                eh-\>timestamp() = Scheduler::instance().clock();
                send(p, 0);     // Connector::send()
        }

        void ECHO_Timer::expire(Event *e)
        {
                a_-\>timeout(0);
        }
The []timeout method simply arranges for []sendit to be executed every interval_ seconds. The []sendit method creates a new packet with most of its header fields already set up by []allocpkt. The packet is only lacks the current time stamp. The call to []access provides for a structured interface to the packet header fields, and is used to set the timestamp field. Note that this agent uses its own special header (``ECHOHeader''). The creation and use of packet headers is described in later chapterChapterchap:pformat; to send the packet to the next downstream node, []Connector::send is invoked without a handler.

Tom Henderson 2011-11-05