Preventing send if socket is closed