Changeset 3f199fc for protocols


Ignore:
Timestamp:
2006-05-13T23:28:31Z (19 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.

Location:
protocols
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • protocols/events.h

    r0356ae3 r3f199fc  
    6161G_MODULE_EXPORT gboolean b_event_remove_by_data(gpointer data);
    6262
     63#ifdef EVENTS_LIBEVENT
     64G_MODULE_EXPORT void closesocket(int fd);
     65#endif
     66
    6367#endif /* _EVENTS_H_ */
  • 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.