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

Added channel->sources variable, and CHANNEL_CLOSE_AT_END_OF_FILE.

Rev: src/channel.c:1.11
Rev: src/channel.h:1.13
Rev: src/read_data.c:1.12
parent b6737eea
......@@ -1049,7 +1049,7 @@ int channel_eof(struct ssh_channel *channel)
if (LSH_CLOSEDP(res))
return res;
if (channel->flags & CHANNEL_RECIEVED_EOF)
if (channel->flags & (CHANNEL_RECIEVED_EOF | CHANNEL_CLOSE_AT_END_OF_FILE))
{
/* Initiate close */
res |= channel_close(channel);
......@@ -1064,6 +1064,7 @@ void init_channel(struct ssh_channel *channel)
channel->write = NULL;
channel->flags = 0;
channel->sources = 0;
channel->request_types = NULL;
channel->recieve = NULL;
......
......@@ -30,6 +30,9 @@
#define CHANNEL_SENT_EOF 4
#define CHANNEL_RECIEVED_EOF 8
/* Means that we should send close immediately after sending eof. */
#define CHANNEL_CLOSE_AT_END_OF_FILE 0x10
struct ssh_channel
{
struct lsh_object header;
......@@ -51,12 +54,11 @@ struct ssh_channel
struct alist *request_types;
int flags;
#if 0
int recieved_close;
int sent_close;
int recieved_eof;
int sent_eof;
#endif
/* Number of files connected to this channel. For instance, stdout
* and stderr can be multiplexed on the same channel. We should not
* close the channel until we have got an EOF on both sources. */
int sources;
/* FIXME: What about return values from these functions? A channel
* may fail to process it's data. Is there some way to propagate a
......
......@@ -24,9 +24,12 @@
*/
#include "read_data.h"
#include "werror.h"
#include "xalloc.h"
#include <assert.h>
struct read_data
{
struct read_handler super; /* Super type */
......@@ -52,10 +55,12 @@ static int do_read_data(struct read_handler **h,
MDEBUG_SUBTYPE(closure);
assert(closure->channel->sources);
if (closure->channel->flags &
(CHANNEL_RECIEVED_CLOSE | CHANNEL_SENT_CLOSE | CHANNEL_SENT_EOF))
return LSH_FAIL | LSH_DIE;
to_read = MIN(closure->channel->send_max_packet,
closure->channel->send_window_size);
......@@ -78,8 +83,9 @@ static int do_read_data(struct read_handler **h,
channel_close(closure->channel);
return LSH_FAIL | LSH_DIE;
case A_EOF:
/* Send eof (but no close). */
channel_eof(closure->channel);
if (!--closure->channel->sources)
/* Send eof (but no close). */
channel_eof(closure->channel);
return LSH_OK | LSH_DIE;
default:
packet->length = n;
......@@ -102,5 +108,7 @@ struct read_handler *make_read_data(struct ssh_channel *channel,
closure->channel = channel;
closure->write = write;
channel->sources++;
return &closure->super;
}
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