if (!c || ((int)c->remoteid) == -1) {
if (!c || c->halfopen) {
static void ssh2_msg_channel_close(Ssh ssh, struct Packet *pktin){    unsigned i = ssh_pkt_getuint32(pktin);    struct ssh_channel *c;    struct Packet *pktout;    c = find234(ssh->channels, &i, ssh_channelfind);    if (!c || ((int)c->remoteid) == -1) {	bombout(("Received CHANNEL_CLOSE for %s channel %d\n",		 c ? "half-open" : "nonexistent", i));	return;    }    /* Do pre-close processing on the channel. */    switch (c->type) {      case CHAN_MAINSESSION:	ssh->mainchan = NULL;	update_specials_menu(ssh->frontend);	break;      case CHAN_X11:	if (c->u.x11.s != NULL)	    x11_close(c->u.x11.s);	sshfwd_close(c);	break;      case CHAN_AGENT:	sshfwd_close(c);	break;      case CHAN_SOCKDATA:	if (c->u.pfd.s != NULL)	    pfd_close(c->u.pfd.s);	sshfwd_close(c);	break;    }    if (c->closes == 0) {	pktout = ssh2_pkt_init(SSH2_MSG_CHANNEL_CLOSE);	ssh2_pkt_adduint32(pktout, c->remoteid);	ssh2_pkt_send(ssh, pktout);    }    del234(ssh->channels, c);    bufchain_clear(&c->v.v2.outbuffer);    sfree(c);    /*     * See if that was the last channel left open.     * (This is only our termination condition if we're     * not running in -N mode.)     */    if (!ssh->cfg.ssh_no_shell && count234(ssh->channels) == 0) {	logevent("All channels closed. Disconnecting");#if 0	/*	 * We used to send SSH_MSG_DISCONNECT here,	 * because I'd believed that _every_ conforming	 * SSH2 connection had to end with a disconnect	 * being sent by at least one side; apparently	 * I was wrong and it's perfectly OK to	 * unceremoniously slam the connection shut	 * when you're done, and indeed OpenSSH feels	 * this is more polite than sending a	 * DISCONNECT. So now we don't.	 */	s->pktout = ssh2_pkt_init(SSH2_MSG_DISCONNECT);	ssh2_pkt_adduint32(s->pktout, SSH2_DISCONNECT_BY_APPLICATION);	ssh2_pkt_addstring(s->pktout, "All open channels closed");	ssh2_pkt_addstring(s->pktout, "en");	/* language tag */	ssh2_pkt_send_noqueue(ssh, s->pktout);#endif	ssh->close_expected = TRUE;	ssh_closing((Plug)ssh, NULL, 0, 0);    }}