Re: [rfc] epoll interface change and glibc bits ...

From: Davide Libenzi (davidel@xmailserver.org)
Date: Wed Nov 20 2002 - 20:04:41 EST


On Thu, 21 Nov 2002, Jamie Lokier wrote:

> That is a good idea, if we go for the union.

This is the include file I'm thinking to submit to Ulrich for glibc
inclusion :

#ifndef _SYS_EPOLL_H
#define _SYS_EPOLL_H 1

#include <sys/types.h>

enum EPOLL_EVENTS {
        EPOLLIN = 0x001,
#define EPOLLIN EPOLLIN

        EPOLLPRI = 0x002,
#define EPOLLPRI EPOLLPRI

        EPOLLOUT = 0x004,
#define EPOLLOUT EPOLLOUT

#ifdef __USE_XOPEN

        EPOLLRDNORM = 0x040,
#define EPOLLRDNORM EPOLLRDNORM

        EPOLLRDBAND = 0x080,
#define EPOLLRDBAND EPOLLRDBAND

        EPOLLWRNORM = 0x100,
#define EPOLLWRNORM EPOLLWRNORM

        EPOLLWRBAND = 0x200,
#define EPOLLWRBAND EPOLLWRBAND

#endif

#ifdef __USE_GNU
        EPOLLMSG = 0x400,
#define EPOLLMSG EPOLLMSG
#endif

        EPOLLERR = 0x008,
#define EPOLLERR EPOLLERR

        EPOLLHUP = 0x010
#define EPOLLHUP EPOLLHUP

};

/* Valid opcodes to issue to epoll_ctl() */
#define EPOLL_CTL_ADD 1 /* Add a file decriptor to the interface */
#define EPOLL_CTL_DEL 2 /* Remove a file decriptor from the interface */
#define EPOLL_CTL_MOD 3 /* Change file decriptor epoll_event structure */

typedef union epoll_obj {
        void *ptr;
        int fd;
        __uint32_t u32[2];
        __uint64_t u64;
} epoll_obj_t;

struct epoll_event {
        unsigned short events; /* Required events */
        unsigned short revents; /* Returned events */
        epoll_obj_t data; /* User data variable */
};

__BEGIN_DECLS

/*
 * Creates an epoll interface by suggesting the requested size in terms
 * of file descriptors that will be presumably stored inside the interface.
 * The integer returned by epoll_create() should be closed with close().
 */
extern int epoll_create(int size);

/*
 * Controller function for the epoll interface. Valid values for the "op"
 * parameter are the EPOLL_CTL_* constant defined above. The "fd" parameter
 * is the target of the operation while the "event" parameter describe which
 * events the caller is interested in and the data ( obj ) he associates
 * the the file "fd".
 */
extern int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) __THROW;

/*
 * Wait for events on the epoll interface. The function will return the number
 * of events that will be available inside the memory area pointed by "events".
 * Up to "maxevents" events will be copied. The "timeout" parameter enable the
 * caller to specify a miximum wait time in milliseconds ( -1 == infinite ).
 */
extern int epoll_wait(int epfd, struct epoll_event *events, int maxevents,
                      int timeout) __THROW;

__END_DECLS

#endif /* #ifndef _SYS_EPOLL_H */

Comments ?

- Davide

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sat Nov 23 2002 - 22:00:34 EST