Fixed many bugs in libevent, socket and pthread