Date: 2017-02-16 11:27 am (UTC)
simont: A picture of me in 2016 (Default)
From: [personal profile] simont
For Socket, we require than member functions are Socket are only called from member functions of Plug (which is what we expected in the first place, but hadn't previously had a way of guaranteeing). And then the "parent" pointer comes from the "this" pointer of the calling function.

Hmmm. But precisely the reason why I needed back-and-forth pointers between Socket and Plug in the first place is that sometimes you do get into this system by calling a member function on the Socket.

In PuTTY, one of the side effects of creating a Socket is that it inserts itself into whatever machinery in the main event loop causes the socket to be monitored for incoming data. So the event loop (in whatever form it takes for a given app and platform, which comes to more forms than you might expect!) wants to loop over an undifferentiated list of Sockets doing things like inserting their fds into Unix select(2) calls, and when data comes in, it will call socket->got_incoming_data(some_buffer) (spelling/syntax adjusted for expository purposes) for the socket in question, and that in turn must be able to find the socket's owning Plug without having been invoked from the Plug.

So that's why, in my situation, the Socket and the Plug each has to hold a pointer to the other, with the Plug's pointer allowed to be NULL in cases where no socket is currently active, but with the invariants that if a Plug does have a non-null Socket pointer then that Socket must contain a reciprocal link back to the same Plug, and conversely, any Socket must always contain a valid pointer to a Plug which owns that same Socket.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org

Active Recent Entries