Networking Forums

Networking Forums > Computer Networking > Linux Networking > using epoll()

Reply
Thread Tools Display Modes

using epoll()

 
 
chsalvia@gmail.com
Guest
Posts: n/a

 
      03-24-2007, 04:10 AM
I'm trying to figure out how to use epoll() to poll a number of
sockets. Usually, I simply use poll or select to multiplex IO, but
I've read numerous times that epoll is faster, and more versatile.
However, I can't figure out how to use it, and the man page on epoll
is not very descriptive.

Firstly, all epoll examples I see assume a server/client model. I
want to use epoll to simply wait on a group of client sockets,
(connected to http servers) and fetch data from them. Is epoll()
capable of doing this?

Secondly, I don't understand the way the epoll functions are supposed
to work. The epoll_ctl function takes as arguments the epoll fd, the
client fd, and a pointer to an epoll_event struct. But the epoll
event struct also contains a file descriptor in it. It's unclear to
me what the purpose of epoll_event.fd is in relation to the client fd
passed to epoll_ctl.

Finally, how do you add multiple file descriptors? With poll() it's
simply a matter of creating an array of pollfd structs. With epoll
it's unclear how this is done. Do you make an array of epoll_event
structs? And if so, what is the relation between the file descriptors
contained in the epoll_event structs and the file descriptor passed to
epoll_ctl?

It's unclear to me whether you're supposed to pass an array of
epoll_event structures to epoll_ctl, or whether you're supposed to do
some kind of loop, adding file descriptors like:

for (int i = 0; i < NUM_FD; ++i) {
epoll_ctl(epfd, EPOLL_CTL_ADD, fd[i], &ev);
}

Any explanation on how epoll is supposed to work would be appreciated
immensely.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
promble with epoll function papamms Linux Networking 0 06-08-2007 06:13 AM
Article: Using epoll() For Asynchronous Network Programming Alexey N. Kovyrin Linux Networking 1 04-14-2006 10:54 AM
epoll, and exceeding maximum sockets hangs process? Billy Joe Linux Networking 0 09-15-2004 06:13 PM



1 2 3 4 5 6 7 8 9 10 11