tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: fcntl & cmsg



On Sep 19, 2014, at 12:38 PM, James K. Lowden 
<jklowden%schemamania.org@localhost> wrote:

>            "The received descriptor is a duplicate of the sender's
> descriptor, as if it were created with a call to dup(2).  Per-process
> descriptor flags, set with fcntl(2), are not passed to a receiver."

is the descriptor sharing the its reference with another descriptor (which 
happens with dup(2)/dup(2)) or did get a separate reference via a open or 
socket call?

if you have a dup'ed file descriptor, setting an attribute on it affects all 
the other descriptors dup'ed from it..  If you open a file multiple times, each 
descriptor is a separate reference and setting an attribute on one doesn't 
affect the others.

There are two levels of reference involved.  A descriptor indexes into a table 
of file structure pointers.  dup/dup2 simply duplicates file struct pointer for 
one descriptor into a new slot increasing its reference count by one.

socket/open/creat allocate a new file structure and insert a pointer to the new 
file structure into the table.  It's this file structure which keep attribute 
of a file descriptor.


Home | Main Index | Thread Index | Old Index