BrainDump
  Home arrow BrainDump arrow Page 3 - Linux Files and the Event Poll Interface
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
BRAINDUMP

Linux Files and the Event Poll Interface
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 2
    2008-12-04


    Table of Contents:
  • Linux Files and the Event Poll Interface
  • Controlling Epoll
  • Waiting for Events with Epoll
  • Edge- Versus Level-Triggered Events

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Linux Files and the Event Poll Interface - Waiting for Events with Epoll
    ( Page 3 of 4 )

    The system call epoll_wait() waits for events on the file descriptors associated with the given epoll instance:

      #include <sys/epoll.h>

      int epoll_wait (int epfd,
                    
    struct epoll_event *events,
                    
    int maxevents,
                    
    int timeout);

    A call to epoll_wait() waits up to timeout milliseconds for events on the files associ ated with the epoll instance epfd . Upon success, events points to memory containing epoll_event structures describing each event, up to a maximum of maxevents events. The return value is the number of events, or -1 on error, in which case errno is set to one of the following:

    EBADF
       epfd is not a valid file descriptor.

    EFAULT 
       The process does not have write access to the
       memory pointed at by events .

    EINTR 
       The system call was interrupted by a signal before it
       could complete.

    EINVAL
     epfd is not a valid epoll instance, or maxevents is 
      equal to or less than 0 .

    If timeout is 0 , the call returns immediately, even if no events are available, in which case the call will return 0 . If the timeout is -1 , the call will not return until an event is available.

    When the call returns, the events field of the epoll_event structure describes the events that occurred. The data field contains whatever the user set it to before invocation of epoll_ctl() .

    A full epoll_wait() example looks like this:

      #define MAX_EVENTS   64

      struct epoll_event *events ;
      int nr_events, i, epfd;

      events = malloc (sizeof (struct epoll_event) * MAX_EVENTS);
      if (!events) {
             
    perror ("malloc");
             
    return 1;
     
    }

      nr_events = epoll_wait (epfd, events, MAX_EVENTS, -1);
      if (nr_events < 0) {
             
    perror ("epoll_wait");
              free (events);
             
    return 1;
      }

      for (i = 0; i < nr_events; i++) {
             
    printf ("event=%ld on fd=%d\n",
             
    events[i].events,
             
    events[i].data.fd);

              /*
              
    * We now can, per events[i].events, operate on
              
    * events[i].data.fd without blocking.
              
    */
      }

      free (events);

    We will cover the functions malloc() and free() in Chapter 8.



     
     
    >>> More BrainDump Articles          >>> More By O'Reilly Media
     

       

    BRAINDUMP ARTICLES

    - Migrating Oracle to PostgreSQL with Enterpri...
    - Demystifying SELinux on Kernel 2.6
    - Yahoo and Microsoft Create Ad Partnership
    - The Advantages of Obscure Open Source Browse...
    - Dell Announces CSI-style Digital Forensics S...
    - Milepost GCC Speeds Open-Source Development
    - Learn These 10 Programming Languages
    - Tomcat Capacity Planning
    - Internal and External Performance Tuning wit...
    - Tomcat Benchmark Procedure
    - Benchmarking Tomcat Performance
    - Tomcat Performance Tuning
    - Wubi: Windows-based Ubuntu Installer
    - Configuring and Optimizing Your I/O Scheduler
    - Linux I/O Schedulers





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek