From: <crai...@ee.washington.edu>
Date: Thu, 10 Sep 2009 14:10:37 -0700
Local: Thurs, Sep 10 2009 5:10 pm
Subject: RE: On callbacks
> I am a bit confused about the use of callbacks. It's not a silly question at all. The implementation is non-trivial. > in particular, in the example named 'tcp-large-transfer.cc', there's a > function called 'CwndTracer': > static void > Simply, I don't get where the two parameters are taken from. Fortunately, you only have to figure this out once. It may be easier to just accept that when you trace a plain-old data type, you need to define a function that receives the old and the new value. i.e., don't ask :-) Here are the internals. Look at the connect to begin putting the pieces Config::ConnectWithoutContext ( Then take a look at the path string, reading backward. The last part of the find . -name '*.cc' | xargs grep CongestionWindow You will see, ./src/internet-stack/nsc-tcp-socket-impl.cc: .AddTraceSource It's the AddTraceSource call that you are interested in. If you are using .AddTraceSource ("CongestionWindow", Look at the MakeTraceSourceAccessor call and find that the actual traced TcpSocketImpl::m_cWnd Now, go and look in tcp-socket-impl.h for the declaration of this variable. TracedValue<uint32_t> Unless you know where this is defined you are probably stuck here. Again, If you do this you will find lots and lots of hits in ./core/traced-value.h You will find that the way these things work is to overload the operators TracedValue &operator = (const TracedValue &o) { You will find a call to Set(). There you will find: void Set (const T &v) { One thing to point out is that the trace hook will only be called if the new Anyway, the variable v is the new value and m_v is the existing (old) value, m_cb (m_v, v); This is the callback that is hit when you make the change to the variable by In the TracedValue class you can find, private: So, in the case of TracedValue<uint32_t>, the T becomes int32_t and you have int32_t v So m_cb is calling (via an overloaded operator () ) a method that takes two So, MakeCallback (&CwndTracer) Needs to hook a function that takes two uint32_t, the first being the old void CwndTracer (uint32_t oldval, uint32_t newval); Non trivial, but now you know how all TracedValue work since it is Regards, -- Craig You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||