www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - Epoll for D2

reply "Adil" <simplyadilb gmail.com> writes:
A thin wrapper to the linux epoll api.

https://github.com/adilbaig/Epoll-D2
Sep 08 2012
next sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
Adil:

 https://github.com/adilbaig/Epoll-D2

 ev.events = EPOLL_EVENTS.IN | EPOLL_EVENTS.HUP |    
 EPOLL_EVENTS.ERR;

In D enums are kind of (but not really) strongly typed, so writing them all in UPPERCASE is often a bad practice. So something more similar to this seems nicer: ev.events = EpollEvents.in | EpollEvents.hupxxxxx | EpollEvents.error;
 epoll.add(int file_descriptor, ev);

Is this correct D syntax? Bye, bearophile
Sep 08 2012
prev sibling next sibling parent Adil Baig <adil.baig aidezigns.com> writes:
--047d7b2e535224f86c04c9308ba6
Content-Type: text/plain; charset=ISO-8859-1

On Sat, Sep 8, 2012 at 2:49 PM, bearophile <bearophileHUGS lycos.com> wrote:

 Adil:

  https://github.com/adilbaig/**Epoll-D2<https://github.com/adilbaig/Epoll-D2>

ev.events = EPOLL_EVENTS.IN | EPOLL_EVENTS.HUP | EPOLL_EVENTS.ERR;

In D enums are kind of (but not really) strongly typed,

"are kind of (but not really) strongly typed" - I didnt know that. How?
 so writing them all in UPPERCASE is often a bad practice. So something
 more similar to this seems nicer:

 ev.events = EpollEvents.in | EpollEvents.hupxxxxx | EpollEvents.error;

library doesn't need to "double lookup" what it means. The original epoll #defines are EPOLL* (ex: EPOLLIN, EPOLLHUP, EPOLLONESHOT ..), hence the naming scheme EPOLL_EVENTS.* . But i do take your point. I'm thinking Events.* ; Events.IN, Events.HUP etc. Succinct and fairly obvious. Looks good?
  epoll.add(int file_descriptor, ev);

Is this correct D syntax? I slipped into pseudo-code there. epoll works with file descriptors

"epoll.add(listener_socket.handle(), ev)"
 Bye,
 bearophile

--047d7b2e535224f86c04c9308ba6 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <br><div class=3D"gmail_quote">On Sat, Sep 8, 2012 at 2:49 PM, bearophile <= span dir=3D"ltr">&lt;<a href=3D"mailto:bearophileHUGS lycos.com" target=3D"= _blank">bearophileHUGS lycos.com</a>&gt;</span> wrote:<br><blockquote class= =3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd= ing-left:1ex"> Adil:<br> <br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> <a href=3D"https://github.com/adilbaig/Epoll-D2" target=3D"_blank">https://= github.com/adilbaig/<u></u>Epoll-D2</a><br> </blockquote> <br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> ev.events =3D <a href=3D"http://EPOLL_EVENTS.IN" target=3D"_blank">EPOLL_EV= ENTS.IN</a> | EPOLL_EVENTS.HUP | =A0 =A0EPOLL_EVENTS.ERR;<br> </blockquote> <br> In D enums are kind of (but not really) strongly typed, </blockquote><div><= br></div><div>&quot;are kind of (but not really) strongly typed&quot; - I d= idnt know that. How?</div><div>=A0</div><blockquote class=3D"gmail_quote" s= tyle=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> so writing them all in UPPERCASE is often a bad practice. So something more= similar to this seems nicer:<br> <br> ev.events =3D EpollEvents.in | EpollEvents.hupxxxxx | EpollEvents.error;<br=

rve to a minimum so some one using this library doesn&#39;t need to &quot;d= ouble lookup&quot; what it means. The original epoll #defines are EPOLL* (e= x: EPOLLIN, EPOLLHUP, EPOLLONESHOT ..), hence the naming scheme EPOLL_EVENT= S.* . But i do take your point. I&#39;m thinking Events.* ; Events.IN, Even= ts.HUP etc.=A0Succinct=A0and fairly obvious. Looks good?=A0</div> <div>=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;= border-left:1px #ccc solid;padding-left:1ex"> <br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> epoll.add(int file_descriptor, ev);<br> </blockquote> <br> Is this correct D syntax?<br> <br></blockquote><div>I slipped into pseudo-code there. epoll works with fi= le descriptors (including its own), not just sockets, hence i didn&#39;t wr= ite &quot;epoll.add(listener_socket.handle(), ev)&quot;</div><div>=A0</div> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> Bye,<br> bearophile<br> </blockquote></div><br> --047d7b2e535224f86c04c9308ba6--
Sep 08 2012
prev sibling next sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
Adil Baig:

 "are kind of (but not really) strongly typed" - I didnt know 
 that. How?

D allows code like: enum Foo { V1 = 10 } void main() { assert(Foo.V1 == 10); } But C++11 enums are strongly typed, and similar code is a compilation error: enum class Foo { V1 = 10 }; int main() { int b = Foo::V1 == 10; } Maybe Walter thinks that in similar cases forcing the usage of cast(int) introduces some risks that are not worth, so he has designed enums half-strongly typed. D contains several other equally mysterious design decisions :-) See also: http://d.puremagic.com/issues/show_bug.cgi?id=3999
 I'm thinking
 Events.* ; Events.IN, Events.HUP etc. Succinct and fairly 
 obvious. Looks good?

What about Events.in, Events.hup, etc? :-) Bye, bearophile
Sep 08 2012
prev sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
 What about Events.in,

"in" is a keyword... sorry. Bye, bearophile
Sep 08 2012