AF_UNIX status report

Ken Brown kbrown@cornell.edu
Tue Nov 3 15:43:29 GMT 2020


On 10/30/2020 5:20 AM, Corinna Vinschen wrote:
> On Oct 29 14:53, Joe Lowe wrote:
>> On 2020-10-29 13:19, Ken Brown via Cygwin-developers wrote:
>>> On 10/27/2020 5:43 AM, Corinna Vinschen wrote:
>>>> On Oct 26 18:04, Ken Brown via Cygwin-developers wrote:
>>>>> I've made at least rudimentary implementations of all the
>>>>> fhandler_socket_unix functions (including those in select.cc) for which
>>>>> there were previously only placeholders.
>>>>>
>>>>> I've pushed everything to topic/af_unix, including a merge with
>>>>> master as of
>>>>> a couple days ago.
>>>>>
>>>>> I've cobbled together a few test programs and put them in
>>>>> winsup/cygwin/socket_tests on the topic/af_unix branch.  I
>>>>> haven't taken the
>>>>> time to automate the tests, so they all have to be run
>>>>> interactively.  There
>>>>> is a Makefile to build the test programs and a README.txt that
>>>>> shows how to
>>>>> run them.
>>>>>
>>>>> One thing I haven't yet done is to think about (or systematically test)
>>>>> datagram sockets.  I'm sure there's quite a bit of code that
>>>>> won't work for
>>>>> them.
>>>>>
>>>>> Aside from datagram sockets, there are still a few things that
>>>>> I'm working
>>>>> on, but I'm close to the point where I could use some input:
>>>>>
>>>>> 1. I've littered the code in fhandler_socket_unix.cc and select.cc with
>>>>> FIXME comments on which I'd like advice.
>>>>
>>>> I'll look into it.
>>>>
>>>>> 2. I haven't given any thought at all as to how to implement SCM_RIGHTS
>>>>> ancillary data.  I could definitely use suggestions on that
>>>>> before I start
>>>>> thrashing around.
>>>>
>>>> I have only vague ideas at that point.  Assuming we can replace the
>>>> socket implemantation with the pipe implementation, what we have is a
>>>> pipe which can impersonate the peer at least from the server side, and
>>>> it knows the client process.  This in turn can be used to duplicate
>>>> handles.  So what we could do is to define fhandler methods which create
>>>> a matching serialization  and deserialization of the fhandler data, plus
>>>> duplicating the handles for the other process, sent over the pipe as
>>>> admin package.  This must work in either direction, regardless if the
>>>> server or the client sends the SCM_RIGHTS block.
>>>
>>> This sounds reasonable.
>>>
>>> I have no experience with serialization.  Do you happen to know of a
>>> good example that I could look at?
> 
> Unfortunately not.  Probably we can just send the entire fhandler and
> the recipient fiddles the content in a per-class way, kind of like
> fhandler::dup.

I'm working on implementing this, and I've bumped into an elementary C++ 
question.  In order to send the fhandler in an admin packet, I need to determine 
its size dynamically, given an (fhandler_base *) pointer to it.  AFAICS, this 
requires something like the following.

In the definition of class fhandler_base, put a virtual function

   virtual size_t size () const { return sizeof *this; }

and then repeat this essentially verbatim in every derived class:

   size_t size () const { return sizeof *this; }

Does this seem right?  I did an internet search and didn't find anything 
substantially different, although there were several suggestions to use 
templates in various ways.  I'm not convinced that using templates would 
actually improve the code, but I can do it if you think it's better.  See, for 
example,

 
https://stackoverflow.com/questions/7642614/find-size-of-derived-class-object-using-base-class-pointer

Ken


More information about the Cygwin-developers mailing list