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
...@@ -233,6 +233,9 @@ static int channel_process_status(struct channel_table *table, ...@@ -233,6 +233,9 @@ static int channel_process_status(struct channel_table *table,
{ {
/* Clear this bit */ /* Clear this bit */
status &= ~LSH_CHANNEL_FINISHED; status &= ~LSH_CHANNEL_FINISHED;
if (table->channels[channel]->close)
CHANNEL_CLOSE(table->channels[channel]);
dealloc_channel(table, channel); dealloc_channel(table, channel);
...@@ -653,6 +656,8 @@ static int do_channel_eof(struct packet_handler *c, ...@@ -653,6 +656,8 @@ static int do_channel_eof(struct packet_handler *c,
if (channel) if (channel)
{ {
int res = 0;
if (channel->flags & (CHANNEL_RECIEVED_EOF | CHANNEL_RECIEVED_CLOSE)) if (channel->flags & (CHANNEL_RECIEVED_EOF | CHANNEL_RECIEVED_CLOSE))
{ {
werror("Recieving EOF on channel on closed channel.\n"); werror("Recieving EOF on channel on closed channel.\n");
...@@ -660,24 +665,23 @@ static int do_channel_eof(struct packet_handler *c, ...@@ -660,24 +665,23 @@ static int do_channel_eof(struct packet_handler *c,
} }
channel->flags |= CHANNEL_RECIEVED_EOF; channel->flags |= CHANNEL_RECIEVED_EOF;
if (channel->flags & CHANNEL_SENT_CLOSE)
/* Do nothing */
return LSH_OK | LSH_GOON;
if (channel->flags & CHANNEL_SENT_EOF) if (channel->eof)
res = CHANNEL_EOF(channel);
if (!LSH_CLOSEDP(res)
&& ! (channel->flags & CHANNEL_SENT_CLOSE)
&& (channel->flags & CHANNEL_SENT_EOF))
{ {
/* Both parties have sent EOF. Initiate close, if we /* Both parties have sent EOF. Initiate close, if we
* havn't done that already. */ * havn't done that already. */
if (channel->flags & CHANNEL_SENT_CLOSE) res |= channel_close(channel);
return LSH_OK | LSH_GOON;
else
return channel_process_status(
closure->table, channel_number,
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", werror("EOF on non-existant channel %d\n",
channel_number); channel_number);
...@@ -726,6 +730,10 @@ static int do_channel_close(struct packet_handler *c, ...@@ -726,6 +730,10 @@ static int do_channel_close(struct packet_handler *c,
{ {
werror("Unexpected channel CLOSE.\n"); werror("Unexpected channel CLOSE.\n");
} }
if (! (channel->flags & (CHANNEL_RECIEVED_EOF))
&& channel->eof)
CHANNEL_EOF(channel);
return channel_process_status( return channel_process_status(
closure->table, channel_number, closure->table, channel_number,
...@@ -1049,7 +1057,7 @@ int channel_eof(struct ssh_channel *channel) ...@@ -1049,7 +1057,7 @@ int channel_eof(struct ssh_channel *channel)
if (LSH_CLOSEDP(res)) if (LSH_CLOSEDP(res))
return 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 */ /* Initiate close */
res |= channel_close(channel); res |= channel_close(channel);
...@@ -1069,10 +1077,10 @@ void init_channel(struct ssh_channel *channel) ...@@ -1069,10 +1077,10 @@ void init_channel(struct ssh_channel *channel)
channel->request_types = NULL; channel->request_types = NULL;
channel->recieve = NULL; channel->recieve = NULL;
channel->send = NULL; channel->send = NULL;
#if 0
channel->close = NULL; channel->close = NULL;
channel->eof = NULL; channel->eof = NULL;
#endif
channel->open_confirm = NULL; channel->open_confirm = NULL;
channel->open_failure = NULL; channel->open_failure = NULL;
channel->channel_success = NULL; channel->channel_success = NULL;
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#define CHANNEL_RECIEVED_EOF 8 #define CHANNEL_RECIEVED_EOF 8
/* Means that we should send close immediately after sending eof. */ /* 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 struct ssh_channel
{ {
...@@ -71,10 +71,12 @@ struct ssh_channel ...@@ -71,10 +71,12 @@ struct ssh_channel
/* Called when we are allowed to send data on the channel. */ /* Called when we are allowed to send data on the channel. */
int (*send)(struct ssh_channel *self); int (*send)(struct ssh_channel *self);
#if 0 /* Called when the channel is closed */
int (*close)(struct ssh_channel *self); 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); int (*eof)(struct ssh_channel *self);
#endif
/* Reply from SSH_MSG_CHANNEL_OPEN_REQUEST */ /* Reply from SSH_MSG_CHANNEL_OPEN_REQUEST */
int (*open_confirm)(struct ssh_channel *self); 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