[Click] What should be done when pull() is called on an empty supply element?

Paine, Thomas Asa PAINETA at uwec.edu
Mon Dec 12 18:54:39 EST 2005


	What is the expected behavior be for a downstream element
pulling its upstream element and the upstream element has nothing to
provide?  Generically, I'm referring to any PushToPull elements
behavior.  I figured reviewing the SimpleQueue element would best answer
this for me, but I'm having trouble understanding.
	
	FromDevice -> PushToPullElement (i.e. SimpleQueue) -> ToDevice

If I look at SimpleQueue's pull method, I see it simply calls its own
inline deq(), which in turn returns reference to the _head of its
Storage.

Packet *
SimpleQueue::pull(int)
{
    return deq();
}

inline Packet *
SimpleQueue::deq()
{
    if (_head != _tail) {
        Packet *p = _q[_head];
        assert(p);
        _head = next_i(_head);
        return p;
    } else
        return 0;
}


	Now, this appears to return the _head if the queue is not empty
(_head != tail), else return null.  Now if I create a push to pull
element, define the pull(int) method and always return(0), it will seg
fault in user space (obviously we won't try the kernel mod).  This
doesn't surprise me, since I am returning null references.  However,
what surprises me, after looking at SimpleQueue, is that it would seem
that SimpleQueue should produce the same seg fault, but clearly doesn't.
I know that "Queue" uses a more event driven approach via notification,
but for testing a particular element I wasn't interested in implementing
that behavior initially.    
	I did search the archives, but have not found anything that
specifically addresses this.  What am I missing or not understanding?
So again, how should pull act with nothing to provide, how is it
SimpleQueue does not cause the same seg fault when empty, and what is
taking care of the returned null reference?  



Thanks, 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
   Thomas Paine (paineta at uwec.edu) 
   University of Wisconsin - Eau Claire 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 



More information about the click mailing list