bring from stable_libevent_socket branch