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

From: Alan Cox
Date: Tue May 06 2008 - 07:53:13 EST


> > > 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.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/