ssh2_set_window checks whether the channel is being closed, so there's no