From aa6e9c6ecaab15b32393053e9b01c668a4a01fbe Mon Sep 17 00:00:00 2001 From: Mikhail Gusarov Date: Fri, 24 Jun 2005 11:17:50 +0000 Subject: [PATCH] Added libssh2_channel_wait_close() --- include/libssh2.h | 1 + src/channel.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/libssh2.h b/include/libssh2.h index 3a3e4f44..f1fc8dbf 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -381,6 +381,7 @@ LIBSSH2_API int libssh2_channel_get_exit_status(LIBSSH2_CHANNEL* channel); LIBSSH2_API int libssh2_channel_send_eof(LIBSSH2_CHANNEL *channel); LIBSSH2_API int libssh2_channel_eof(LIBSSH2_CHANNEL *channel); LIBSSH2_API int libssh2_channel_close(LIBSSH2_CHANNEL *channel); +LIBSSH2_API int libssh2_channel_wait_closed(LIBSSH2_CHANNEL *channel); LIBSSH2_API int libssh2_channel_free(LIBSSH2_CHANNEL *channel); LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session, const char *path, struct stat *sb); diff --git a/src/channel.c b/src/channel.c index d244478b..e292c517 100644 --- a/src/channel.c +++ b/src/channel.c @@ -1114,6 +1114,35 @@ LIBSSH2_API int libssh2_channel_close(LIBSSH2_CHANNEL *channel) } /* }}} */ +/* {{{ libssh2_channel_wait_closed + * Awaiting channel close after EOF + */ +LIBSSH2_API int libssh2_channel_wait_closed(LIBSSH2_CHANNEL *channel) +{ + LIBSSH2_SESSION* session = channel->session; + + if (!libssh2_channel_eof(channel)) { + libssh2_error(session, LIBSSH2_ERROR_INVAL, "libssh2_channel_wait_closed() invoked when channel is not in EOF state", 0); + return -1; + } + +#ifdef LIBSSH2_DEBUG_CONNECTION + _libssh2_debug(session, LIBSSH2_DBG_CONN, "Awaiting close of channel %lu/%lu", channel->local.id, channel->remote.id); +#endif + + /* while channel is not closed, read more + * packets from the network. + * Either or channel will be closed + * or network timeout will occur + */ + while (!channel->remote.close && libssh2_packet_read(session, 1) > 0) + ; + + return 1; +} +/* }}} */ + + /* {{{ libssh2_channel_free * Make sure a channel is closed, then remove the channel from the session and free its resource(s) */