View | Details | Raw Unified | Return to bug 1131 | Differences between
and this patch

Collapse All | Expand All

(-)buffer.c (-13 / +33 lines)
Lines 18-23 Link Here
18
#include "buffer.h"
18
#include "buffer.h"
19
#include "log.h"
19
#include "log.h"
20
20
21
#define	BUFFER_MAX_CHUNK	0x100000
22
#define	BUFFER_MAX_LEN		0xa00000
23
#define	BUFFER_ALLOC_INCREMENT	0x008000
24
21
/* Initializes the buffer structure. */
25
/* Initializes the buffer structure. */
22
26
23
void
27
void
Lines 66-71 buffer_append(Buffer *buffer, const void Link Here
66
	memcpy(p, data, len);
70
	memcpy(p, data, len);
67
}
71
}
68
72
73
static void
74
buffer_compact(Buffer *buffer)
75
{
76
	/*
77
	 * If the buffer is quite empty, but all data is at the end, move the
78
	 * data to the beginning.
79
	 */
80
	if (buffer->offset > MIN(buffer->alloc, BUFFER_MAX_CHUNK)) {
81
		memmove(buffer->buf, buffer->buf + buffer->offset,
82
			buffer->end - buffer->offset);
83
		buffer->end -= buffer->offset;
84
		buffer->offset = 0;
85
	}
86
}
87
69
/*
88
/*
70
 * Appends space to the buffer, expanding the buffer if necessary. This does
89
 * Appends space to the buffer, expanding the buffer if necessary. This does
71
 * not actually copy the data into the buffer, but instead returns a pointer
90
 * not actually copy the data into the buffer, but instead returns a pointer
Lines 93-112 restart: Link Here
93
		buffer->end += len;
112
		buffer->end += len;
94
		return p;
113
		return p;
95
	}
114
	}
96
	/*
97
	 * If the buffer is quite empty, but all data is at the end, move the
98
	 * data to the beginning and retry.
99
	 */
100
	if (buffer->offset > MIN(buffer->alloc, BUFFER_MAX_CHUNK)) {
101
		memmove(buffer->buf, buffer->buf + buffer->offset,
102
			buffer->end - buffer->offset);
103
		buffer->end -= buffer->offset;
104
		buffer->offset = 0;
105
		goto restart;
106
	}
107
	/* Increase the size of the buffer and retry. */
108
115
109
	newlen = buffer->alloc + len + 32768;
116
	/* Compact data back to the start of the buffer if necessary */
117
	buffer_compact(buffer);
118
119
	/* Increase the size of the buffer and retry. */
120
	newlen = roundup(buffer->alloc + len, BUFFER_ALLOC_INCREMENT);
110
	if (newlen > BUFFER_MAX_LEN)
121
	if (newlen > BUFFER_MAX_LEN)
111
		fatal("buffer_append_space: alloc %u not supported",
122
		fatal("buffer_append_space: alloc %u not supported",
112
		    newlen);
123
		    newlen);
Lines 114-119 restart: Link Here
114
	buffer->alloc = newlen;
125
	buffer->alloc = newlen;
115
	goto restart;
126
	goto restart;
116
	/* NOTREACHED */
127
	/* NOTREACHED */
128
}
129
130
/* Check whether an allocation of 'len' will fit in the buffer */
131
int
132
buffer_check_alloc(Buffer *buffer, u_int len)
133
{
134
	buffer_compact(buffer);
135
	return (roundup(buffer->alloc + len, BUFFER_ALLOC_INCREMENT) <=
136
	    BUFFER_MAX_LEN);
117
}
137
}
118
138
119
/* Returns the number of bytes of data in the buffer. */
139
/* Returns the number of bytes of data in the buffer. */
(-)buffer.h (-3 / +2 lines)
Lines 23-31 typedef struct { Link Here
23
	u_int	 end;		/* Offset of last byte containing data. */
23
	u_int	 end;		/* Offset of last byte containing data. */
24
}       Buffer;
24
}       Buffer;
25
25
26
#define	BUFFER_MAX_CHUNK	0x100000
27
#define	BUFFER_MAX_LEN		0xa00000
28
29
void	 buffer_init(Buffer *);
26
void	 buffer_init(Buffer *);
30
void	 buffer_clear(Buffer *);
27
void	 buffer_clear(Buffer *);
31
void	 buffer_free(Buffer *);
28
void	 buffer_free(Buffer *);
Lines 35-40 void *buffer_ptr(Buffer *); Link Here
35
32
36
void	 buffer_append(Buffer *, const void *, u_int);
33
void	 buffer_append(Buffer *, const void *, u_int);
37
void	*buffer_append_space(Buffer *, u_int);
34
void	*buffer_append_space(Buffer *, u_int);
35
36
int	 buffer_check_alloc(Buffer *, u_int);
38
37
39
void	 buffer_get(Buffer *, void *, u_int);
38
void	 buffer_get(Buffer *, void *, u_int);
40
39
(-)channels.c (-4 / +2 lines)
Lines 747-758 channel_pre_open(Channel *c, fd_set *rea Link Here
747
{
747
{
748
	u_int limit = compat20 ? c->remote_window : packet_get_maxsize();
748
	u_int limit = compat20 ? c->remote_window : packet_get_maxsize();
749
749
750
	/* check buffer limits */
751
	limit = MIN(limit, (BUFFER_MAX_LEN - BUFFER_MAX_CHUNK - CHAN_RBUF));
752
753
	if (c->istate == CHAN_INPUT_OPEN &&
750
	if (c->istate == CHAN_INPUT_OPEN &&
754
	    limit > 0 &&
751
	    limit > 0 &&
755
	    buffer_len(&c->input) < limit)
752
	    buffer_len(&c->input) < limit &&
753
	    buffer_check_alloc(&c->input, CHAN_RBUF))
756
		FD_SET(c->rfd, readset);
754
		FD_SET(c->rfd, readset);
757
	if (c->ostate == CHAN_OUTPUT_OPEN ||
755
	if (c->ostate == CHAN_OUTPUT_OPEN ||
758
	    c->ostate == CHAN_OUTPUT_WAIT_DRAIN) {
756
	    c->ostate == CHAN_OUTPUT_WAIT_DRAIN) {

Return to bug 1131