Libevent code