Commit 2cfcc789 authored by Niels Möller's avatar Niels Möller
Browse files

Added eof and close callbacks to channels.

Rev: src/channel.c:1.12
Rev: src/channel.h:1.14
parent 6f57ea82
......@@ -234,6 +234,9 @@ static int channel_process_status(struct channel_table *table,
/* Clear this bit */
status &= ~LSH_CHANNEL_FINISHED;
if (table->channels[channel]->close)
CHANNEL_CLOSE(table->channels[channel]);
dealloc_channel(table, channel);
/* If this was the last channel, close connection */
......@@ -653,6 +656,8 @@ static int do_channel_eof(struct packet_handler *c,
if (channel)
{
int res = 0;
if (channel->flags & (CHANNEL_RECIEVED_EOF | CHANNEL_RECIEVED_CLOSE))
{
werror("Recieving EOF on channel on closed channel.\n");
......@@ -661,23 +666,22 @@ static int do_channel_eof(struct packet_handler *c,
channel->flags |= CHANNEL_RECIEVED_EOF;
if (channel->flags & CHANNEL_SENT_CLOSE)
/* Do nothing */
return LSH_OK | LSH_GOON;
if (channel->eof)
res = CHANNEL_EOF(channel);
if (channel->flags & CHANNEL_SENT_EOF)
if (!LSH_CLOSEDP(res)
&& ! (channel->flags & CHANNEL_SENT_CLOSE)
&& (channel->flags & CHANNEL_SENT_EOF))
{
/* Both parties have sent EOF. Initiate close, if we
* havn't done that already. */
if (channel->flags & CHANNEL_SENT_CLOSE)
return LSH_OK | LSH_GOON;
else
return channel_process_status(
closure->table, channel_number,
channel_close(channel));
res |= channel_close(channel);
}
return LSH_OK | LSH_GOON;
return channel_process_status(closure->table, channel_number,
res);
}
werror("EOF on non-existant channel %d\n",
channel_number);
......@@ -727,6 +731,10 @@ static int do_channel_close(struct packet_handler *c,
werror("Unexpected channel CLOSE.\n");
}
if (! (channel->flags & (CHANNEL_RECIEVED_EOF))
&& channel->eof)
CHANNEL_EOF(channel);
return channel_process_status(
closure->table, channel_number,
( (channel->flags & (CHANNEL_SENT_CLOSE))
......@@ -1049,7 +1057,7 @@ int channel_eof(struct ssh_channel *channel)
if (LSH_CLOSEDP(res))
return res;
if (channel->flags & (CHANNEL_RECIEVED_EOF | CHANNEL_CLOSE_AT_END_OF_FILE))
if (channel->flags & (CHANNEL_RECIEVED_EOF | CHANNEL_CLOSE_AT_EOF))
{
/* Initiate close */
res |= channel_close(channel);
......@@ -1069,10 +1077,10 @@ void init_channel(struct ssh_channel *channel)
channel->request_types = NULL;
channel->recieve = NULL;
channel->send = NULL;
#if 0
channel->close = NULL;
channel->eof = NULL;
#endif
channel->open_confirm = NULL;
channel->open_failure = NULL;
channel->channel_success = NULL;
......
......@@ -31,7 +31,7 @@
#define CHANNEL_RECIEVED_EOF 8
/* Means that we should send close immediately after sending eof. */
#define CHANNEL_CLOSE_AT_END_OF_FILE 0x10
#define CHANNEL_CLOSE_AT_EOF 0x10
struct ssh_channel
{
......@@ -71,10 +71,12 @@ struct ssh_channel
/* Called when we are allowed to send data on the channel. */
int (*send)(struct ssh_channel *self);
#if 0
int (*close)(struct ssh_channel *self);
/* Called when the channel is closed */
void (*close)(struct ssh_channel *self);
/* Called when eof is recieved on the channel (or when it is closed,
* whatever happens first). */
int (*eof)(struct ssh_channel *self);
#endif
/* Reply from SSH_MSG_CHANNEL_OPEN_REQUEST */
int (*open_confirm)(struct ssh_channel *self);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment