Repository navigation
Wire sending into UDP listener - #4019
ryanwarfield wants to merge 6 commits into
Conversation
ef5287a to
64b9702
Compare
64b9702 to
45f94e7
Compare
This code will always be a little bit insane. Its a callback within a callback that needs to worry about lifetimes etc. But hopefuly this makes it a little more legible.
| // sockets aren't thread-safe, so the actual send needs to happen on the io_context | ||
| // thread | ||
| boost::asio::post(socket_.get_executor(), | ||
| [this, buf, destination]() { doSend(buf, destination); }); |
There was a problem hiding this comment.
is it possible for this to be null/dangling? post is executed at a later date iirc?
There was a problem hiding this comment.
Yeah, I suppose that's a risk. UdpListener holds a reference to an io_service, which is where doSend gets run. doSend uses its reference to the UdpListener to get the socket and send the message. So, destroying UdpListener first runs the risk of dangling like you said, while destroying the io_service first seems to leave a dangling pointer within the socket_ object. So, the only sane way of destruction is to first stop the io_service thread (to prevent a dangling this, then destroy the UdpListener, and then finally destroy the io_service.
This feels pretty awkward. Do you have any better ideas on how to structure this? Should I just document this order for the class?
nycrat
left a comment
There was a problem hiding this comment.
Code itself looks good, but I'm a bit worried about adding this send functionality to UdpListener. If it is possible, I would suggest moving this functionality to a different class, perhaps a child class of UdpListener?
| #include <string> | ||
|
|
||
| typedef std::function<void(const char*, const size_t&)> ReceiveCallback; | ||
| typedef std::function<void(const char*, const size_t&, |
There was a problem hiding this comment.
small nit: c++ using is preferred over typedef for some small reasons, but I think mostly readability
Lowkey I though this was gonna be really ugly, but it turned out well so I'll include it! Maybe C++ isn't so bad after all. |
instead of adding sending to the listener
Description
This PR:
3rd party AIs sending messages might expect responses to come from the same socket that they sent their message to, so using the existing udp sender wasn't sufficient.
Testing Done
Resolved Issues
Part of stacked PR
Length Justification and Key Files to Review
Review Checklist
It is the reviewers responsibility to also make sure every item here has been covered
.hfile) should have a javadoc style comment at the start of them. For examples, see the functions defined inthunderbots/software/geom. Similarly, all classes should have an associated Javadoc comment explaining the purpose of the class.TODO(or similar) statements should either be completed or associated with a github issue