mirror of https://github.com/adamdruppe/arsd.git
use druntime module now that it exists for epoll
This commit is contained in:
parent
1260bbcc76
commit
773fc20999
65
eventloop.d
65
eventloop.d
|
@ -462,7 +462,7 @@ version(linux) {
|
|||
// cause an infinite loop. So when an event comes, you MUST starve
|
||||
// the read to get all your info in a timely fashion. Gonna document this.
|
||||
if(edgeTriggered)
|
||||
ev.events = EPOLL_EVENTS.EPOLLET; // edge triggered
|
||||
ev.events = EPOLLET; // edge triggered
|
||||
|
||||
// Oh I think I know why I did this: if it is level triggered
|
||||
// and the data is not actually handled, it infinite loops
|
||||
|
@ -483,9 +483,9 @@ version(linux) {
|
|||
// best of it. Also watch your CPU usage for infinite loops!
|
||||
|
||||
if(events & FileEvents.read)
|
||||
ev.events |= EPOLL_EVENTS.EPOLLIN;
|
||||
ev.events |= EPOLLIN;
|
||||
if(events & FileEvents.write)
|
||||
ev.events |= EPOLL_EVENTS.EPOLLOUT;
|
||||
ev.events |= EPOLLOUT;
|
||||
ev.data.fd = fd;
|
||||
epoll_ctl(epoll, EPOLL_CTL_ADD, fd, &ev);
|
||||
}
|
||||
|
@ -550,18 +550,18 @@ version(linux) {
|
|||
} else {
|
||||
auto flags = events[n].events;
|
||||
import core.stdc.stdio;
|
||||
if(flags & EPOLL_EVENTS.EPOLLIN) {
|
||||
if(flags & EPOLLIN) {
|
||||
sendSync(FileReadyToRead(fd));
|
||||
}
|
||||
if(flags & EPOLL_EVENTS.EPOLLOUT) {
|
||||
if(flags & EPOLLOUT) {
|
||||
sendSync(FileReadyToWrite(fd));
|
||||
}
|
||||
if((flags & EPOLL_EVENTS.EPOLLERR)) {
|
||||
if((flags & EPOLLERR)) {
|
||||
//import core.stdc.stdio; printf("ERROR on fd from epoll %d\n", fd);
|
||||
sendSync(FileError(fd));
|
||||
break outer_loop;
|
||||
}
|
||||
if((flags & EPOLL_EVENTS.EPOLLHUP)) {
|
||||
if((flags & EPOLLHUP)) {
|
||||
//import core.stdc.stdio; printf("HUP on fd from epoll %d\n", fd);
|
||||
sendSync(FileHup(fd));
|
||||
}
|
||||
|
@ -770,56 +770,7 @@ struct FileHup {
|
|||
// epoll
|
||||
|
||||
version(linux) {
|
||||
extern(C):
|
||||
|
||||
alias int c_int;
|
||||
|
||||
alias uint uint32_t;
|
||||
alias ulong uint64_t;
|
||||
|
||||
union epoll_data {
|
||||
void *ptr;
|
||||
int fd;
|
||||
uint32_t u32;
|
||||
uint64_t u64;
|
||||
}
|
||||
|
||||
struct epoll_event {
|
||||
uint32_t events; /* Epoll events */
|
||||
epoll_data data; /* User data variable */
|
||||
}
|
||||
|
||||
enum EPOLL_CTL_ADD = 1;
|
||||
enum EPOLL_CTL_DEL = 2;
|
||||
enum EPOLL_CTL_MOD = 3;
|
||||
|
||||
|
||||
import std.conv : octal;
|
||||
enum {
|
||||
EPOLL_CLOEXEC = octal!"2000000",
|
||||
EPOLL_NONBLOCK = octal!"4000"
|
||||
}
|
||||
|
||||
enum EPOLL_EVENTS {
|
||||
EPOLLIN = 0x001,
|
||||
EPOLLPRI = 0x002,
|
||||
EPOLLOUT = 0x004,
|
||||
EPOLLRDNORM = 0x040,
|
||||
EPOLLRDBAND = 0x080,
|
||||
EPOLLWRNORM = 0x100,
|
||||
EPOLLWRBAND = 0x200,
|
||||
EPOLLMSG = 0x400,
|
||||
EPOLLERR = 0x008,
|
||||
EPOLLHUP = 0x010,
|
||||
EPOLLRDHUP = 0x2000,
|
||||
EPOLLONESHOT = (1 << 30),
|
||||
EPOLLET = (1 << 31)
|
||||
}
|
||||
|
||||
int epoll_create1(int flags);
|
||||
int epoll_ctl(int epfd, int op, int fd, epoll_event* event);
|
||||
int epoll_wait(int epfd, epoll_event* events, int maxevents, int timeout);
|
||||
|
||||
import core.sys.linux.epoll;
|
||||
import core.sys.posix.sys.time;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue