Re: [PATCH 02/18] flag parameters: socket and socketpair

Alan Cox
2008-05-06T11:53:12Z

> > > type = flag_remap(type, &fflags, SOCK_whatever, O_whatever);
> > > type = flag_remap(type, &fflags, SOCK_whatever2, O_whatever2);
> > >
> > > ?
> >
> > I think it is better to keep it able to remap more than one flag, with a
> > single call, that is table driven.
> >
>
> The table-driven approach is slower for one and probably two bits and it is
> somewhat less readable. What do we gain in return for this?

Acute over-engineering ?

We've got lots of space for flag bits so surely we can do remap with a
shift and mask.

flags = (type >> SOCK_FLAG_SHIFT) & SOCK_FLAG_MASK;
type = type & SOCK_TYPE_MASK

For most boxes

SOCK_TYPE_MASK can easily be 0xFF
SOCK_FLAG_MASK O_CLOEXEC
SOCK_FLAG_SHIFT 0

and tweaked a bit depending what other flags we want.

In Linux we could actually just do SOCK_STREAM|O_CLOEXEC but that would be
bad news for portability to other OS where the trick might well not work.