Commit d35cd1fc authored by Niels Möller's avatar Niels Möller

Use read_data.[ch] again. The read handler has a pointer to the

corresponding channel, to do flow control properly.

Rev: src/Makefile.in:1.23
Rev: src/read_data.c:1.10
Rev: src/read_data.h:1.6
parent 04328503
......@@ -39,7 +39,7 @@ COMMON_SRCS = alist.c atoms.c bignum.c channel.c \
debug.c disconnect.c encrypt.c format.c getopt.c io.c keyexchange.c \
packet_ignore.c pad.c parse.c publickey_crypto.c \
randomness.c \
read_line.c read_packet.c service.c \
read_data.c read_line.c read_packet.c service.c \
unpad.c \
werror.c write_buffer.c xalloc.c
......
......@@ -31,62 +31,75 @@ struct read_data
{
struct read_handler super; /* Super type */
UINT32 block_size;
/* Where to send the data */
struct abstract_write *handler;
struct abstract_write *write;
/* For flow control. */
/* FIXME: Perhaps the information that is needed for flow control
* should be abstracted out from the channel struct? */
struct callback *close_callback;
struct ssh_channel *channel;
};
static int do_read_data(struct read_handler **h,
struct abstract_read *read)
{
struct read_data *closure = (struct read_data *) *h;
int to_read;
int n;
struct lsh_string *packet;
MDEBUG_SUBTYPE(closure);
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);
MDEBUG(closure);
if (!to_read)
{
/* Stop reading */
return LSH_OK | LSH_HOLD;
}
#if 0
while(1)
#endif
packet = lsh_string_alloc(to_read);
n = A_READ(read, to_read, packet->data);
switch(n)
{
struct lsh_string *packet = lsh_string_alloc(closure->block_size);
int n = A_READ(read, packet->length, packet->data);
switch(n)
{
case 0:
lsh_string_free(packet);
break;
case A_FAIL:
/* Fall through */
case A_EOF:
CALLBACK(closure->close_callback);
return LSH_OK | LSH_CLOSE;
default:
{
packet->length = n;
case 0:
lsh_string_free(packet);
return LSH_OK | LSH_GOON;
case A_FAIL:
/* Send a channel close, and prepare the channel for closing */
channel_close(closure->channel);
return LSH_FAIL | LSH_DIE;
case A_EOF:
/* Send eof (but no close). */
channel_eof(closure->channel);
return LSH_OK | LSH_DIE;
default:
packet->length = n;
return A_WRITE(closure->handler, packet);
}
}
/* FIXME: Should we consider the error code here? Probably not;
* an error here means that the fd connected to the channel will be closed.
* Cleaning up the channel itself should be taken care of later. */
return A_WRITE(closure->write, packet);
}
return LSH_OK | LSH_GOON;
}
struct read_handler *make_read_data(struct abstract_write *handler,
struct callback *close_callback,
UINT32 block_size)
struct read_handler *make_read_data(struct ssh_channel *channel,
struct abstract_write *write)
{
struct read_data *closure;
NEW(closure);
closure->super.handler = do_read_data;
closure->block_size = block_size;
closure->handler = handler;
closure->close_callback = close_callback;
closure->write = write;
return &closure->super;
}
......@@ -23,16 +23,13 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#warning read_data obsolete. See channel.c: do_read_channel()
#ifndef LSH_READ_DATA_H_INCLUDED
#define LSH_READ_DATA_H_INCLUDED
#include "abstract_io.h"
#include "channel.h"
struct read_handler *make_read_data(struct abstract_write *handler,
struct callback *close_callback,
UINT32 block_size);
struct read_handler *make_read_data(struct ssh_channel *channel,
struct abstract_write *write);
#endif /* LSH_READ_DATA_H_INCLUDED */
......
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