MSG_WAITALL for Sockets

Jonathan M Davis jmdavisProg at gmx.com
Wed Nov 20 11:31:59 PST 2013


On Wednesday, November 20, 2013 17:26:27 Jeroen Bollen wrote:
> On Tuesday, 19 November 2013 at 23:36:57 UTC, Rob T wrote:
> > On Tuesday, 19 November 2013 at 18:35:08 UTC, Jeroen Bollen
> > 
> > wrote:
> >> Is there a way I can call a receive method on a socket with
> >> MSG_WAITALL as a flag? There doesn't seem to be an enum for
> >> that.
> > 
> > module core.sys.posix.sys.socket;
> > 
> > enum : uint
> > {
> > 
> > MSG_CTRUNC = 0x08,
> > MSG_DONTROUTE = 0x04,
> > MSG_EOR = 0x80,
> > MSG_OOB = 0x01,
> > MSG_PEEK = 0x02,
> > MSG_TRUNC = 0x20,
> > MSG_WAITALL = 0x100
> > 
> > }
> > 
> > Use SocketFlags to set the flag.
> > 
> > If using Windows, you can set up your own enum, as I don't
> > think one is pre-defined.
> > 
> > --rt
> 
> Thanks! I don't really get how this is working though, isn't the
> point of using an enum as a type, preventing any values that's
> not listed in the enum definition?

SocketFlags in std.socket is used incorrectly. It's used as a parameter type 
for &ed values rather than just a list of the flags that you can & together, 
and unfortunately, the language does not currently prevent that. You can do 
stuff like.

enum Foo : string { a = "bar" }

auto b = Foo.a;
b ~= " stool";

with impunity. It's just that the compiler will prevent something like

Foo f = "hello";

So, the type protection on enums is currently quite poor. IMHO, the compiler 
should prevent an enum from ever having an invalid enum value when no casts 
are used, but that's just not the way that it is right now. Pretty much all it 
protects against are direct assignments. And I have no idea whether that will 
ever be fixed or not. Hopefully it will be though.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list