fix fwrite if socket down