Lines Matching refs:c
91 chan_set_istate(Channel *c, u_int next) in chan_set_istate() argument
93 if (c->istate > CHAN_INPUT_CLOSED || next > CHAN_INPUT_CLOSED) in chan_set_istate()
94 fatal("chan_set_istate: bad state %d -> %d", c->istate, next); in chan_set_istate()
95 debug2("channel %d: input %s -> %s", c->self, istates[c->istate], in chan_set_istate()
97 c->istate = next; in chan_set_istate()
100 chan_set_ostate(Channel *c, u_int next) in chan_set_ostate() argument
102 if (c->ostate > CHAN_OUTPUT_CLOSED || next > CHAN_OUTPUT_CLOSED) in chan_set_ostate()
103 fatal("chan_set_ostate: bad state %d -> %d", c->ostate, next); in chan_set_ostate()
104 debug2("channel %d: output %s -> %s", c->self, ostates[c->ostate], in chan_set_ostate()
106 c->ostate = next; in chan_set_ostate()
114 chan_rcvd_oclose1(Channel *c) in chan_rcvd_oclose1() argument
116 debug2("channel %d: rcvd oclose", c->self); in chan_rcvd_oclose1()
117 switch (c->istate) { in chan_rcvd_oclose1()
119 chan_set_istate(c, CHAN_INPUT_CLOSED); in chan_rcvd_oclose1()
122 chan_shutdown_read(c); in chan_rcvd_oclose1()
123 chan_send_ieof1(c); in chan_rcvd_oclose1()
124 chan_set_istate(c, CHAN_INPUT_CLOSED); in chan_rcvd_oclose1()
128 chan_send_ieof1(c); in chan_rcvd_oclose1()
129 chan_set_istate(c, CHAN_INPUT_CLOSED); in chan_rcvd_oclose1()
133 c->self, c->istate); in chan_rcvd_oclose1()
138 chan_read_failed(Channel *c) in chan_read_failed() argument
140 debug2("channel %d: read failed", c->self); in chan_read_failed()
141 switch (c->istate) { in chan_read_failed()
143 chan_shutdown_read(c); in chan_read_failed()
144 chan_set_istate(c, CHAN_INPUT_WAIT_DRAIN); in chan_read_failed()
148 c->self, c->istate); in chan_read_failed()
153 chan_ibuf_empty(Channel *c) in chan_ibuf_empty() argument
155 debug2("channel %d: ibuf empty", c->self); in chan_ibuf_empty()
156 if (buffer_len(&c->input)) { in chan_ibuf_empty()
158 c->self); in chan_ibuf_empty()
161 switch (c->istate) { in chan_ibuf_empty()
164 if (!(c->flags & (CHAN_CLOSE_SENT|CHAN_LOCAL))) in chan_ibuf_empty()
165 chan_send_eof2(c); in chan_ibuf_empty()
166 chan_set_istate(c, CHAN_INPUT_CLOSED); in chan_ibuf_empty()
168 chan_send_ieof1(c); in chan_ibuf_empty()
169 chan_set_istate(c, CHAN_INPUT_WAIT_OCLOSE); in chan_ibuf_empty()
174 c->self, c->istate); in chan_ibuf_empty()
179 chan_rcvd_ieof1(Channel *c) in chan_rcvd_ieof1() argument
181 debug2("channel %d: rcvd ieof", c->self); in chan_rcvd_ieof1()
182 switch (c->ostate) { in chan_rcvd_ieof1()
184 chan_set_ostate(c, CHAN_OUTPUT_WAIT_DRAIN); in chan_rcvd_ieof1()
187 chan_set_ostate(c, CHAN_OUTPUT_CLOSED); in chan_rcvd_ieof1()
191 c->self, c->ostate); in chan_rcvd_ieof1()
196 chan_write_failed1(Channel *c) in chan_write_failed1() argument
198 debug2("channel %d: write failed", c->self); in chan_write_failed1()
199 switch (c->ostate) { in chan_write_failed1()
201 chan_shutdown_write(c); in chan_write_failed1()
202 chan_send_oclose1(c); in chan_write_failed1()
203 chan_set_ostate(c, CHAN_OUTPUT_WAIT_IEOF); in chan_write_failed1()
206 chan_shutdown_write(c); in chan_write_failed1()
207 chan_send_oclose1(c); in chan_write_failed1()
208 chan_set_ostate(c, CHAN_OUTPUT_CLOSED); in chan_write_failed1()
212 c->self, c->ostate); in chan_write_failed1()
217 chan_obuf_empty(Channel *c) in chan_obuf_empty() argument
219 debug2("channel %d: obuf empty", c->self); in chan_obuf_empty()
220 if (buffer_len(&c->output)) { in chan_obuf_empty()
222 c->self); in chan_obuf_empty()
225 switch (c->ostate) { in chan_obuf_empty()
227 chan_shutdown_write(c); in chan_obuf_empty()
229 chan_send_oclose1(c); in chan_obuf_empty()
230 chan_set_ostate(c, CHAN_OUTPUT_CLOSED); in chan_obuf_empty()
234 c->self, c->ostate); in chan_obuf_empty()
239 chan_send_ieof1(Channel *c) in chan_send_ieof1() argument
241 debug2("channel %d: send ieof", c->self); in chan_send_ieof1()
242 switch (c->istate) { in chan_send_ieof1()
246 packet_put_int(c->remote_id); in chan_send_ieof1()
251 c->self, c->istate); in chan_send_ieof1()
256 chan_send_oclose1(Channel *c) in chan_send_oclose1() argument
258 debug2("channel %d: send oclose", c->self); in chan_send_oclose1()
259 switch (c->ostate) { in chan_send_oclose1()
262 buffer_clear(&c->output); in chan_send_oclose1()
264 packet_put_int(c->remote_id); in chan_send_oclose1()
269 c->self, c->ostate); in chan_send_oclose1()
278 chan_rcvd_close2(Channel *c) in chan_rcvd_close2() argument
280 debug2("channel %d: rcvd close", c->self); in chan_rcvd_close2()
281 if (!(c->flags & CHAN_LOCAL)) { in chan_rcvd_close2()
282 if (c->flags & CHAN_CLOSE_RCVD) in chan_rcvd_close2()
284 c->self); in chan_rcvd_close2()
285 c->flags |= CHAN_CLOSE_RCVD; in chan_rcvd_close2()
287 if (c->type == SSH_CHANNEL_LARVAL) { in chan_rcvd_close2()
289 chan_set_ostate(c, CHAN_OUTPUT_CLOSED); in chan_rcvd_close2()
290 chan_set_istate(c, CHAN_INPUT_CLOSED); in chan_rcvd_close2()
293 switch (c->ostate) { in chan_rcvd_close2()
299 chan_set_ostate(c, CHAN_OUTPUT_WAIT_DRAIN); in chan_rcvd_close2()
302 switch (c->istate) { in chan_rcvd_close2()
304 chan_shutdown_read(c); in chan_rcvd_close2()
305 chan_set_istate(c, CHAN_INPUT_CLOSED); in chan_rcvd_close2()
308 if (!(c->flags & CHAN_LOCAL)) in chan_rcvd_close2()
309 chan_send_eof2(c); in chan_rcvd_close2()
310 chan_set_istate(c, CHAN_INPUT_CLOSED); in chan_rcvd_close2()
316 chan_rcvd_eow(Channel *c) in chan_rcvd_eow() argument
318 debug2("channel %d: rcvd eow", c->self); in chan_rcvd_eow()
319 switch (c->istate) { in chan_rcvd_eow()
321 chan_shutdown_read(c); in chan_rcvd_eow()
322 chan_set_istate(c, CHAN_INPUT_CLOSED); in chan_rcvd_eow()
327 chan_rcvd_eof2(Channel *c) in chan_rcvd_eof2() argument
329 debug2("channel %d: rcvd eof", c->self); in chan_rcvd_eof2()
330 c->flags |= CHAN_EOF_RCVD; in chan_rcvd_eof2()
331 if (c->ostate == CHAN_OUTPUT_OPEN) in chan_rcvd_eof2()
332 chan_set_ostate(c, CHAN_OUTPUT_WAIT_DRAIN); in chan_rcvd_eof2()
335 chan_write_failed2(Channel *c) in chan_write_failed2() argument
337 debug2("channel %d: write failed", c->self); in chan_write_failed2()
338 switch (c->ostate) { in chan_write_failed2()
341 chan_shutdown_write(c); in chan_write_failed2()
342 if (strcmp(c->ctype, "session") == 0) in chan_write_failed2()
343 chan_send_eow2(c); in chan_write_failed2()
344 chan_set_ostate(c, CHAN_OUTPUT_CLOSED); in chan_write_failed2()
348 c->self, c->ostate); in chan_write_failed2()
353 chan_send_eof2(Channel *c) in chan_send_eof2() argument
355 debug2("channel %d: send eof", c->self); in chan_send_eof2()
356 switch (c->istate) { in chan_send_eof2()
359 packet_put_int(c->remote_id); in chan_send_eof2()
361 c->flags |= CHAN_EOF_SENT; in chan_send_eof2()
365 c->self, c->istate); in chan_send_eof2()
370 chan_send_close2(Channel *c) in chan_send_close2() argument
372 debug2("channel %d: send close", c->self); in chan_send_close2()
373 if (c->ostate != CHAN_OUTPUT_CLOSED || in chan_send_close2()
374 c->istate != CHAN_INPUT_CLOSED) { in chan_send_close2()
376 c->self, c->istate, c->ostate); in chan_send_close2()
377 } else if (c->flags & CHAN_CLOSE_SENT) { in chan_send_close2()
378 error("channel %d: already sent close", c->self); in chan_send_close2()
381 packet_put_int(c->remote_id); in chan_send_close2()
383 c->flags |= CHAN_CLOSE_SENT; in chan_send_close2()
387 chan_send_eow2(Channel *c) in chan_send_eow2() argument
389 debug2("channel %d: send eow", c->self); in chan_send_eow2()
390 if (c->ostate == CHAN_OUTPUT_CLOSED) { in chan_send_eow2()
392 c->self); in chan_send_eow2()
398 packet_put_int(c->remote_id); in chan_send_eow2()
407 chan_rcvd_ieof(Channel *c) in chan_rcvd_ieof() argument
410 chan_rcvd_eof2(c); in chan_rcvd_ieof()
412 chan_rcvd_ieof1(c); in chan_rcvd_ieof()
413 if (c->ostate == CHAN_OUTPUT_WAIT_DRAIN && in chan_rcvd_ieof()
414 buffer_len(&c->output) == 0 && in chan_rcvd_ieof()
415 !CHANNEL_EFD_OUTPUT_ACTIVE(c)) in chan_rcvd_ieof()
416 chan_obuf_empty(c); in chan_rcvd_ieof()
419 chan_rcvd_oclose(Channel *c) in chan_rcvd_oclose() argument
422 chan_rcvd_close2(c); in chan_rcvd_oclose()
424 chan_rcvd_oclose1(c); in chan_rcvd_oclose()
427 chan_write_failed(Channel *c) in chan_write_failed() argument
430 chan_write_failed2(c); in chan_write_failed()
432 chan_write_failed1(c); in chan_write_failed()
436 chan_mark_dead(Channel *c) in chan_mark_dead() argument
438 c->type = SSH_CHANNEL_ZOMBIE; in chan_mark_dead()
442 chan_is_dead(Channel *c, int do_send) in chan_is_dead() argument
444 if (c->type == SSH_CHANNEL_ZOMBIE) { in chan_is_dead()
445 debug2("channel %d: zombie", c->self); in chan_is_dead()
448 if (c->istate != CHAN_INPUT_CLOSED || c->ostate != CHAN_OUTPUT_CLOSED) in chan_is_dead()
451 debug2("channel %d: is dead", c->self); in chan_is_dead()
455 c->extended_usage == CHAN_EXTENDED_WRITE && in chan_is_dead()
456 c->efd != -1 && in chan_is_dead()
457 buffer_len(&c->extended) > 0) { in chan_is_dead()
459 c->self, c->efd, buffer_len(&c->extended)); in chan_is_dead()
462 if (c->flags & CHAN_LOCAL) { in chan_is_dead()
463 debug2("channel %d: is dead (local)", c->self); in chan_is_dead()
466 if (!(c->flags & CHAN_CLOSE_SENT)) { in chan_is_dead()
468 chan_send_close2(c); in chan_is_dead()
471 if (c->flags & CHAN_CLOSE_RCVD) { in chan_is_dead()
473 c->self); in chan_is_dead()
478 if ((c->flags & CHAN_CLOSE_SENT) && in chan_is_dead()
479 (c->flags & CHAN_CLOSE_RCVD)) { in chan_is_dead()
480 debug2("channel %d: is dead", c->self); in chan_is_dead()
488 chan_shutdown_write(Channel *c) in chan_shutdown_write() argument
490 buffer_clear(&c->output); in chan_shutdown_write()
491 if (compat20 && c->type == SSH_CHANNEL_LARVAL) in chan_shutdown_write()
494 debug2("channel %d: close_write", c->self); in chan_shutdown_write()
495 if (c->sock != -1) { in chan_shutdown_write()
496 if (shutdown(c->sock, SHUT_WR) < 0) in chan_shutdown_write()
499 c->self, c->sock, strerror(errno)); in chan_shutdown_write()
501 if (channel_close_fd(&c->wfd) < 0) in chan_shutdown_write()
504 c->self, c->wfd, strerror(errno)); in chan_shutdown_write()
508 chan_shutdown_read(Channel *c) in chan_shutdown_read() argument
510 if (compat20 && c->type == SSH_CHANNEL_LARVAL) in chan_shutdown_read()
512 debug2("channel %d: close_read", c->self); in chan_shutdown_read()
513 if (c->sock != -1) { in chan_shutdown_read()
519 if (shutdown(c->sock, SHUT_RD) < 0 in chan_shutdown_read()
523 c->self, c->sock, c->istate, c->ostate, in chan_shutdown_read()
526 if (channel_close_fd(&c->rfd) < 0) in chan_shutdown_read()
529 c->self, c->rfd, strerror(errno)); in chan_shutdown_read()