> On May 7, 2015, 5:40 p.m., Jie Yu wrote: > > src/master/master.cpp, lines 732-735 > > <https://reviews.apache.org/r/33935/diff/1/?file=952157#file952157line732> > > > > Why do you need to capture `this`? Http::log is a static function, I > > don't think you need to capture `this`. > > > > Capture `this` is in general dangeous because you want to make sure the > > callback is invoked before this object is destructured. It's not obviously > > here that this is the case. > > Ben Mahler wrote: > We need `http` which is a member variable. The last line is essentialy > `return this->http.observe(request);`. It's already being captured with the > bind approach as `http` contains the `Master*` pointer. Make sense? > Alternatives you'd prefer? > > Jie Yu wrote: > To match the previous semantics, you want to capture `http` object > (instead of `this`) by value since lambda::bind does a copy on `http` object. > I just thought capturing `this` in general is a bad practice. > > I got confused initialy because I thought the callback of `route` will be > invoked at a different context. After checking the code, seems that the > callback (even if it's just a lambda function) will be invoked at Master > Process's context. It's not documented and quite confusing because we have an > overload version of `route` which takes a `T::*method`.
For posterity, you can't capture 'http' because it is outside the "reaching scope" of the lambda since it is a member variable (only 'this' is inside the reaching scope). So I've created a local Http variable, which works since the member was only needed for the route calls. > On May 7, 2015, 5:40 p.m., Jie Yu wrote: > > src/master/master.cpp, lines 728-729 > > <https://reviews.apache.org/r/33935/diff/1/?file=952157#file952157line728> > > > > Just to be consistent, can you follow up with a patch to use lambda > > consistently here? > > Ben Mahler wrote: > Can you clarify this one? Are you saying don't use bind? Added lambdas consistently. - Ben ----------------------------------------------------------- This is an automatically generated e-mail. To reply, visit: https://reviews.apache.org/r/33935/#review82844 ----------------------------------------------------------- On May 7, 2015, 5:47 a.m., Ben Mahler wrote: > > ----------------------------------------------------------- > This is an automatically generated e-mail. To reply, visit: > https://reviews.apache.org/r/33935/ > ----------------------------------------------------------- > > (Updated May 7, 2015, 5:47 a.m.) > > > Review request for mesos, Jie Yu and Vinod Kone. > > > Bugs: MESOS-2519 > https://issues.apache.org/jira/browse/MESOS-2519 > > > Repository: mesos > > > Description > ------- > > This adds the client address, as well as user-agent and forwarding > information, if present. > > > Diffs > ----- > > src/master/http.cpp fb448256d7ced1f47ea48ccfca2ae267bc26ef94 > src/master/master.hpp 49ee050ca4d2b2c5f75ce864fcf6ae703dfdeadd > src/master/master.cpp bee842557c8397428ca51e46faa182a391584be3 > src/slave/http.cpp f678aabdccd8c16e25c18ffb5075265ed8b76a70 > src/slave/slave.hpp 654a8698be88e0d0f588190775dc3eee6b36f92e > src/slave/slave.cpp c78ee3c9e7fc38ad364e83f4abe267e86bfbbc13 > > Diff: https://reviews.apache.org/r/33935/diff/ > > > Testing > ------- > > Tested manually: > > I0507 05:41:37.386196 28393 http.cpp:233] HTTP GET for /master/state.json > from 127.0.0.1:5050 with User-Agent='curl/7.15.5 (x86_64-redhat-linux-gnu) > libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5' > > I0507 05:42:34.905570 31000 http.cpp:237] HTTP GET for /slave(1)/state.json > from 127.0.0.1:5051 with User-Agent='curl/7.15.5 (x86_64-redhat-linux-gnu) > libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5' > > > Thanks, > > Ben Mahler > >
