set the correct error number to the socket if failed