[channels.c channels.h nchan.c]
     remove function pointers for events, remove chan_init*; ok provos@
This commit is contained in:
Damien Miller 2002-01-22 23:28:45 +11:00
parent 472d05716a
commit 5144df9261
4 changed files with 48 additions and 72 deletions

View File

@ -176,6 +176,9 @@
- markus@cvs.openbsd.org 2002/01/14 13:41:13
[nchan.c]
remove duplicated code; ok provos@
- markus@cvs.openbsd.org 2002/01/14 13:55:55
[channels.c channels.h nchan.c]
remove function pointers for events, remove chan_init*; ok provos@
20020121
- (djm) Rework ssh-rand-helper:
@ -7323,4 +7326,4 @@
- Wrote replacements for strlcpy and mkdtemp
- Released 1.0pre1
$Id: ChangeLog,v 1.1772 2002/01/22 12:28:28 djm Exp $
$Id: ChangeLog,v 1.1773 2002/01/22 12:28:45 djm Exp $

View File

@ -39,7 +39,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: channels.c,v 1.158 2002/01/09 17:26:35 markus Exp $");
RCSID("$OpenBSD: channels.c,v 1.159 2002/01/14 13:55:55 markus Exp $");
#include "ssh.h"
#include "ssh1.h"
@ -217,7 +217,6 @@ channel_new(char *ctype, int type, int rfd, int wfd, int efd,
/* Do initial allocation if this is the first call. */
if (channels_alloc == 0) {
chan_init();
channels_alloc = 10;
channels = xmalloc(channels_alloc * sizeof(Channel *));
for (i = 0; i < channels_alloc; i++)
@ -246,7 +245,9 @@ channel_new(char *ctype, int type, int rfd, int wfd, int efd,
buffer_init(&c->input);
buffer_init(&c->output);
buffer_init(&c->extended);
chan_init_iostates(c);
c->ostate = CHAN_OUTPUT_OPEN;
c->istate = CHAN_INPUT_OPEN;
c->flags = 0;
channel_register_fds(c, rfd, wfd, efd, extusage, nonblock);
c->self = found;
c->type = type;

View File

@ -32,7 +32,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* RCSID("$OpenBSD: channels.h,v 1.57 2002/01/13 21:31:20 markus Exp $"); */
/* RCSID("$OpenBSD: channels.h,v 1.58 2002/01/14 13:55:55 markus Exp $"); */
#ifndef CHANNEL_H
#define CHANNEL_H
@ -215,19 +215,15 @@ void auth_input_open_request(int, u_int32_t, void *);
int chan_is_dead(Channel *, int);
void chan_mark_dead(Channel *);
void chan_init_iostates(Channel *);
void chan_init(void);
typedef void chan_event_fn(Channel *);
/* channel events */
/* for the input state */
extern chan_event_fn *chan_rcvd_oclose;
extern chan_event_fn *chan_read_failed;
extern chan_event_fn *chan_ibuf_empty;
void chan_rcvd_oclose(Channel *);
void chan_read_failed(Channel *);
void chan_ibuf_empty(Channel *);
/* for the output state */
extern chan_event_fn *chan_rcvd_ieof;
extern chan_event_fn *chan_write_failed;
extern chan_event_fn *chan_obuf_empty;
void chan_rcvd_ieof(Channel *);
void chan_write_failed(Channel *);
void chan_obuf_empty(Channel *);
#endif

88
nchan.c
View File

@ -23,7 +23,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: nchan.c,v 1.41 2002/01/14 13:41:13 markus Exp $");
RCSID("$OpenBSD: nchan.c,v 1.42 2002/01/14 13:55:55 markus Exp $");
#include "ssh1.h"
#include "ssh2.h"
@ -63,14 +63,6 @@ RCSID("$OpenBSD: nchan.c,v 1.41 2002/01/14 13:41:13 markus Exp $");
/*
* EVENTS update channel input/output states execute ACTIONS
*/
/* events concerning the INPUT from socket for channel (istate) */
chan_event_fn *chan_rcvd_oclose = NULL;
chan_event_fn *chan_read_failed = NULL;
chan_event_fn *chan_ibuf_empty = NULL;
/* events concerning the OUTPUT from channel for socket (ostate) */
chan_event_fn *chan_rcvd_ieof = NULL;
chan_event_fn *chan_write_failed = NULL;
chan_event_fn *chan_obuf_empty = NULL;
/*
* ACTIONS: should never update the channel states
*/
@ -133,8 +125,8 @@ chan_rcvd_oclose1(Channel *c)
return;
}
}
static void
chan_read_failed_12(Channel *c)
void
chan_read_failed(Channel *c)
{
debug("channel %d: read failed", c->self);
switch (c->istate) {
@ -148,8 +140,8 @@ chan_read_failed_12(Channel *c)
break;
}
}
static void
chan_ibuf_empty1(Channel *c)
void
chan_ibuf_empty(Channel *c)
{
debug("channel %d: ibuf empty", c->self);
if (buffer_len(&c->input)) {
@ -212,8 +204,8 @@ chan_write_failed1(Channel *c)
break;
}
}
static void
chan_obuf_empty1(Channel *c)
void
chan_obuf_empty(Channel *c)
{
debug("channel %d: obuf empty", c->self);
if (buffer_len(&c->output)) {
@ -307,11 +299,6 @@ chan_rcvd_close2(Channel *c)
}
}
static void
chan_ibuf_empty2(Channel *c)
{
chan_ibuf_empty1(c);
}
static void
chan_rcvd_eof2(Channel *c)
{
debug("channel %d: rcvd eof", c->self);
@ -335,11 +322,6 @@ chan_write_failed2(Channel *c)
}
}
static void
chan_obuf_empty2(Channel *c)
{
chan_obuf_empty1(c);
}
static void
chan_send_eof2(Channel *c)
{
debug("channel %d: send eof", c->self);
@ -375,6 +357,31 @@ chan_send_close2(Channel *c)
/* shared */
void
chan_rcvd_ieof(Channel *c)
{
if (compat20)
chan_rcvd_eof2(c);
else
chan_rcvd_ieof1(c);
}
void
chan_rcvd_oclose(Channel *c)
{
if (compat20)
chan_rcvd_close2(c);
else
chan_rcvd_oclose1(c);
}
void
chan_write_failed(Channel *c)
{
if (compat20)
chan_write_failed2(c);
else
chan_write_failed1(c);
}
void
chan_mark_dead(Channel *c)
{
@ -431,37 +438,6 @@ chan_is_dead(Channel *c, int send)
return 0;
}
void
chan_init_iostates(Channel *c)
{
c->ostate = CHAN_OUTPUT_OPEN;
c->istate = CHAN_INPUT_OPEN;
c->flags = 0;
}
/* init */
void
chan_init(void)
{
if (compat20) {
chan_rcvd_oclose = chan_rcvd_close2;
chan_read_failed = chan_read_failed_12;
chan_ibuf_empty = chan_ibuf_empty2;
chan_rcvd_ieof = chan_rcvd_eof2;
chan_write_failed = chan_write_failed2;
chan_obuf_empty = chan_obuf_empty2;
} else {
chan_rcvd_oclose = chan_rcvd_oclose1;
chan_read_failed = chan_read_failed_12;
chan_ibuf_empty = chan_ibuf_empty1;
chan_rcvd_ieof = chan_rcvd_ieof1;
chan_write_failed = chan_write_failed1;
chan_obuf_empty = chan_obuf_empty1;
}
}
/* helper */
static void
chan_shutdown_write(Channel *c)