avoid write() hang if there's no tcp connection