www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - epoll,kqueue support

reply "darkofpain" <darkofpain outlook.com> writes:
Hi Friends,

D language epoll(linux/unix), kqueue(mac/freebsd) is there 
support for API

How can I use supports

Thank You
Oct 04 2013
next sibling parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
You can call the functions with extern(C).

There's also bindings to libraries that handle both, but I've 
never used them:
http://code.dlang.org/packages/libev


Here's how to do epoll without a library:

// calling epoll directly

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.posix.sys.time;
}



Then you use epoll_create(), etc., just like you would in C. 
kqueue would be similar, though I've never done that in D.
Oct 04 2013
next sibling parent S <S S.com> writes:
On 2013-10-04 14:30:39 +0000, Adam D. Ruppe said:

 You can call the functions with extern(C).
 
 There's also bindings to libraries that handle both, but I've never used them:
 http://code.dlang.org/packages/libev
+1 on this. Use libev, or libevent2. There are bindings around for them. (I know vibe-d is using them)
Oct 04 2013
prev sibling parent "darkofpain" <darkofpain outlook.com> writes:
On Friday, 4 October 2013 at 14:30:40 UTC, Adam D. Ruppe wrote:
 You can call the functions with extern(C).

 There's also bindings to libraries that handle both, but I've 
 never used them:
 http://code.dlang.org/packages/libev


 Here's how to do epoll without a library:

 // calling epoll directly

 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.posix.sys.time;
 }



 Then you use epoll_create(), etc., just like you would in C. 
 kqueue would be similar, though I've never done that in D.
Thank You, Epoll ok. I need information about the room kqueue important to me, but do not have the source for the D language
Oct 05 2013
prev sibling parent Dejan Lekic <dejan.lekic gmail.com> writes:
On Fri, 04 Oct 2013 10:44:31 +0200, darkofpain wrote:

 Hi Friends,
 
 D language epoll(linux/unix), kqueue(mac/freebsd) is there support for
 API
 
 How can I use supports
 
 Thank You
As you probably know, epoll is in core.sys.linux.epoll.d . kqueue obviously need someone to write it and submit a pull request. D can call any C function, so using kqueue should not be a big deal...
Oct 05 2013