move some libevent code to cpp