Skip to content

Instantly share code, notes, and snippets.

@kubo39
Created January 7, 2017 14:16
Show Gist options
  • Select an option

  • Save kubo39/03f4ca2a96a6355bcd7e3203a790e1d9 to your computer and use it in GitHub Desktop.

Select an option

Save kubo39/03f4ca2a96a6355bcd7e3203a790e1d9 to your computer and use it in GitHub Desktop.
import core.sys.linux.epoll;
import std.stdio;
import core.stdc.errno;
import std.exception : errnoEnforce;
void main()
{
epoll_event event;
event.events = EPOLLIN;
auto epfd = epoll_create1(EPOLL_CLOEXEC);
if (epfd < 0)
throw new Error("epfd == -1");
auto rc = epoll_ctl(epfd, EPOLL_CTL_ADD, 0, &event);
if (rc == -1)
errnoEnforce(false, "epoll_ctl(2) failed");
}
( ՞ਊ ՞) :~/dev/dlang $ cat epollsample.d
import core.sys.linux.epoll;
import std.stdio;
import core.stdc.errno;
import std.exception : errnoEnforce;
void main()
{
epoll_event event;
event.events = EPOLLIN;
auto epfd = epoll_create1(EPOLL_CLOEXEC);
if (epfd < 0)
throw new Error("epfd == -1");
auto rc = epoll_ctl(epfd, EPOLL_CTL_ADD, 0, &event);
if (rc == -1)
errnoEnforce(false, "epoll_ctl(2) failed");
}
( ՞ਊ ՞) :~/dev/dlang $ dmd epollsample.d
( ՞ਊ ՞) :~/dev/dlang $ echo foobar > /tmp/foobar
( ՞ਊ ՞) :~/dev/dlang $ ./epollsample < /tmp/foobar
[email protected](16): epoll_ctl(2) failed (Operation not permitted)
----------------
??:? @safe bool std.exception.errnoEnforce!(bool, "epollsample.d", 16uL).errnoEnforce(bool, lazy immutable(char)[]) [0x985acc95]
??:? _Dmain [0x985acc10]
??:? _D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv [0x985ad31f]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) [0x985ad24b]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll() [0x985ad2c4]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) [0x985ad24b]
??:? _d_run_main [0x985ad1af]
??:? main [0x985acd2f]
??:? __libc_start_main [0x7d75b3f0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment