Diff for /wikisrc/tutorials/kqueue_tutorial.mdwn between versions 1.2 and 1.4

version 1.2, 2012/02/05 07:14:36 version 1.4, 2020/01/11 06:22:57
Line 16  The kevent structure goes like this:  Line 16  The kevent structure goes like this: 
           
     struct kevent {      struct kevent {
                 uintptr_t ident;        /* identifier for this event */                  uintptr_t ident;        /* identifier for this event */
                 short     filter;       /* filter for event */                  uint32_t  filter;       /* filter for event */
                 u_short   flags;        /* action flags for kqueue */                  uint32_t  flags;        /* action flags for kqueue */
                 u_int     fflags;       /* filter flag value */                  uint32_t  fflags;       /* filter flag value */
                 intptr_t  data;         /* filter data value */                  int64_t   data;         /* filter data value */
                 void      *udata;       /* opaque user data identifier */                  void     *udata;        /* opaque user data identifier */
     };      };
           
   
Line 52  The EV_SET() macro is provided for ease  Line 52  The EV_SET() macro is provided for ease 
     EV_SET(&ev, sckfd, EVFILT_READ, EV_ADD, 0, 0, 0);      EV_SET(&ev, sckfd, EVFILT_READ, EV_ADD, 0, 0, 0);
           
   
 [![][18]][19]  
   
    [18]: /images/Kevent.png  
    [19]: /images/Kevent.png (Kevent.png)  
   
 If we liked to monitor a set of N sockets we would write something like this:   If we liked to monitor a set of N sockets we would write something like this: 
           
     kevent ev[N];      kevent ev[N];
Line 66  If we liked to monitor a set of N socket Line 61  If we liked to monitor a set of N socket
        EV_SET(&ev[i], sckfd[i], EVFILT_READ, EV_ADD, 0, 0, 0);         EV_SET(&ev[i], sckfd[i], EVFILT_READ, EV_ADD, 0, 0, 0);
           
   
 [![][20]][21]  
   
    [20]: /images/Kevent2.png  
    [21]: /images/Kevent2.png (Kevent2.png)  
   
 ##   kqueue(2)  ##   kqueue(2)
   
 The kqueue holds all the events we are interested in. Therefore, to begin with, we must create a new kqueue. We do so with the following code:   The kqueue holds all the events we are interested in. Therefore, to begin with, we must create a new kqueue. We do so with the following code: 
Line 156  The above code would turn into the follo Line 146  The above code would turn into the follo
   
 Note that if one uses a non-NULL zero timespec structure, the kevent() will return instantaneously, bringing down the performance to the levels of a plain poll method.   Note that if one uses a non-NULL zero timespec structure, the kevent() will return instantaneously, bringing down the performance to the levels of a plain poll method. 
   
 ##   Summary  
   
 To summarize, the kqueue framework works like this:   
   
 [![][22]][23]  
   
    [22]: /images/Summary.png  
    [23]: /images/Summary.png (Summary.png)  
   
 #   Examples  #   Examples
   
 ##   A timer example  ##   A timer example
Line 246  We will implement a raw tcp client using Line 227  We will implement a raw tcp client using
   1. any incoming host data in the socket     1. any incoming host data in the socket 
   2. any user data in the standard input stream     2. any user data in the standard input stream 
   
 [![][24]][25]      #include <netinet/in.h>
       
    [24]: /images/Tcpclient.png  
    [25]: /images/Tcpclient.png (Tcpclient.png)  
   
 #include <netinet/in.h>  
     #include <sys/event.h>      #include <sys/event.h>
     #include <sys/socket.h>      #include <sys/socket.h>
     #include <sys/time.h>      #include <sys/time.h>
Line 399  More kqueue examples (including the afor Line 375  More kqueue examples (including the afor
   2. [Kqueue: A generic and scalable event notification facility (pdf)](http://people.freebsd.org/~jlemon/papers/kqueue.pdf)    2. [Kqueue: A generic and scalable event notification facility (pdf)](http://people.freebsd.org/~jlemon/papers/kqueue.pdf)
   3. [kqueue slides](http://people.freebsd.org/~jlemon/kqueue_slides/)    3. [kqueue slides](http://people.freebsd.org/~jlemon/kqueue_slides/)
   4. [The Julipedia: An example of kqueue](http://julipedia.blogspot.com/2004/10/example-of-kqueue.html)    4. [The Julipedia: An example of kqueue](http://julipedia.blogspot.com/2004/10/example-of-kqueue.html)
   

Removed from v.1.2  
changed lines
  Added in v.1.4


CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb