Ignore:
Timestamp:
2006-05-13T23:28:31Z (15 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
df70eafa
Parents:
0356ae3
Message:

Added a closesocket() that properly removes event handlers before closing a socket.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/events_libevent.c

    r0356ae3 r3f199fc  
    3030#include <stdlib.h>
    3131#include <string.h>
     32#include <unistd.h>
    3233#include <sys/types.h>
    3334#include "proxy.h"
     
    217218        return FALSE;
    218219}
     220
     221void closesocket( int fd )
     222{
     223        struct b_event_data *b_ev;
     224       
     225        /* Since epoll() (the main reason we use libevent) automatically removes sockets from
     226           the epoll() list when a socket gets closed and some modules have a habit of
     227           closing sockets before removing event handlers, our and libevent's administration
     228           get a little bit messed up. So this little function will remove the handlers
     229           properly before closing a socket. */
     230       
     231        if( ( b_ev = g_hash_table_lookup( read_hash, &fd ) ) || ( b_ev = g_hash_table_lookup( write_hash, &fd ) ) )
     232                b_event_remove( b_ev->id );
     233       
     234        close( fd );
     235}
Note: See TracChangeset for help on using the changeset viewer.