Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/events_libevent.c

    r04026d4 r9ff5737  
    3232#include <unistd.h>
    3333#include <sys/types.h>
    34 #include "proxy.h"
    35 
    3634#include <sys/time.h>
    3735#include <event.h>
    38 
    39 static guint id_next;
     36#include "proxy.h"
     37
     38static void b_main_restart();
     39static guint id_next = 1;
    4040static GHashTable *id_hash;
    4141static int quitting = 0;
     
    4848static GHashTable *write_hash;
    4949
     50struct event_base *leh;
     51struct event_base *old_leh;
     52
    5053struct b_event_data
    5154{
     
    5962void b_main_init()
    6063{
    61         event_init();
    62        
    63         id_next = 1;
     64        if( leh != NULL )
     65        {
     66                /* Clean up the hash tables? */
     67               
     68                b_main_restart();
     69                old_leh = leh;
     70        }
     71       
     72        leh = event_init();
     73       
    6474        id_hash = g_hash_table_new( g_int_hash, g_int_equal );
    6575        read_hash = g_hash_table_new( g_int_hash, g_int_equal );
     
    6979void b_main_run()
    7080{
    71         event_dispatch();
     81        /* This while loop is necessary to exit the event loop and start a
     82           different one (necessary for ForkDaemon mode). */
     83        while( event_base_dispatch( leh ) == 0 && !quitting )
     84        {
     85                if( old_leh != NULL )
     86                {
     87                        /* For some reason this just isn't allowed...
     88                           Possibly a bug in older versions, will see later.
     89                        event_base_free( old_leh ); */
     90                        old_leh = NULL;
     91                }
     92               
     93                event_debug( "New event loop.\n" );
     94        }
     95}
     96
     97static void b_main_restart()
     98{
     99        struct timeval tv;
     100       
     101        memset( &tv, 0, sizeof( struct timeval ) );
     102        event_base_loopexit( leh, &tv );
     103       
     104        event_debug( "b_main_restart()\n" );
    72105}
    73106
    74107void b_main_quit()
    75108{
    76         struct timeval tv;
    77        
    78         /* libevent sometimes generates events before really quitting,
     109        /* Tell b_main_run() that it shouldn't restart the loop. Also,
     110           libevent sometimes generates events before really quitting,
    79111           we want to stop them. */
    80112        quitting = 1;
    81113       
    82         memset( &tv, 0, sizeof( struct timeval ) );
    83         event_loopexit( &tv );
     114        b_main_restart();
    84115}
    85116
Note: See TracChangeset for help on using the changeset viewer.