Ignore:
Timestamp:
2007-11-28T23:24:26Z (16 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
9ff5737
Parents:
221a273
Message:

Fixed the epoll+ForkDaemon combination. The libevent event handling
didn't work very well on Linux 2.6 (and possibly others) in ForkDaemon
mode.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/events_libevent.c

    r221a273 rb6a2373  
    3737#include <event.h>
    3838
    39 static guint id_next;
     39static void b_main_restart();
     40
     41static guint id_next = 1;
    4042static GHashTable *id_hash;
    4143static int quitting = 0;
     
    4850static GHashTable *write_hash;
    4951
     52struct event_base *leh;
     53struct event_base *old_leh;
     54
    5055struct b_event_data
    5156{
     
    5964void b_main_init()
    6065{
    61         event_init();
    62        
    63         id_next = 1;
     66        if( leh != NULL )
     67        {
     68                /* Clean up the hash tables? */
     69               
     70                b_main_restart();
     71                old_leh = leh;
     72        }
     73       
     74        leh = event_init();
     75       
    6476        id_hash = g_hash_table_new( g_int_hash, g_int_equal );
    6577        read_hash = g_hash_table_new( g_int_hash, g_int_equal );
     
    6981void b_main_run()
    7082{
    71         event_dispatch();
     83        /* This while loop is necessary to exit the event loop and start a
     84           different one (necessary for ForkDaemon mode). */
     85        while( event_base_dispatch( leh ) == 0 && !quitting )
     86        {
     87                if( old_leh != NULL )
     88                {
     89                        /* For some reason this just isn't allowed...
     90                           Possibly a bug in older versions, will see later.
     91                        event_base_free( old_leh ); */
     92                        old_leh = NULL;
     93                }
     94               
     95                printf( "New event loop.\n" );
     96        }
     97}
     98
     99static void b_main_restart()
     100{
     101        struct timeval tv;
     102       
     103        memset( &tv, 0, sizeof( struct timeval ) );
     104        event_base_loopexit( leh, &tv );
     105       
     106        printf( "b_main_restart()\n" );
    72107}
    73108
    74109void b_main_quit()
    75110{
    76         struct timeval tv;
    77        
    78         /* libevent sometimes generates events before really quitting,
     111        /* Tell b_main_run() that it shouldn't restart the loop. Also,
     112           libevent sometimes generates events before really quitting,
    79113           we want to stop them. */
    80114        quitting = 1;
    81115       
    82         memset( &tv, 0, sizeof( struct timeval ) );
    83         event_loopexit( &tv );
     116        b_main_restart();
    84117}
    85118
Note: See TracChangeset for help on using the changeset viewer.