Lines Matching refs:buf
36 /* setup_buffer initializes |buf| with capacity |cap|, aligned such that data
39 static int setup_buffer(SSL3_BUFFER *buf, size_t header_len, size_t cap) {
40 if (buf->buf != NULL || cap > 0xffff) {
46 buf->buf = OPENSSL_malloc(cap + SSL3_ALIGN_PAYLOAD - 1);
47 if (buf->buf == NULL) {
53 buf->offset = (0 - header_len - (uintptr_t)buf->buf) &
55 buf->len = 0;
56 buf->cap = cap;
60 static void consume_buffer(SSL3_BUFFER *buf, size_t len) {
61 if (len > buf->len) {
64 buf->offset += (uint16_t)len;
65 buf->len -= (uint16_t)len;
66 buf->cap -= (uint16_t)len;
69 static void clear_buffer(SSL3_BUFFER *buf) {
70 OPENSSL_free(buf->buf);
71 OPENSSL_memset(buf, 0, sizeof(SSL3_BUFFER));
81 SSL3_BUFFER *buf = &ssl->s3->read_buffer;
83 if (buf->buf != NULL) {
95 return setup_buffer(buf, header_len, cap);
99 return ssl->s3->read_buffer.buf + ssl->s3->read_buffer.offset;
107 SSL3_BUFFER *buf = &ssl->s3->read_buffer;
109 if (buf->len > 0) {
116 /* Read a single packet from |ssl->rbio|. |buf->cap| must fit in an int. */
117 int ret = BIO_read(ssl->rbio, buf->buf + buf->offset, (int)buf->cap);
122 /* |BIO_read| was bound by |buf->cap|, so this cannot overflow. */
123 buf->len = (uint16_t)ret;
128 SSL3_BUFFER *buf = &ssl->s3->read_buffer;
130 if (len > buf->cap) {
136 while (buf->len < len) {
137 /* The amount of data to read is bounded by |buf->cap|, which must fit in an
139 int ret = BIO_read(ssl->rbio, buf->buf + buf->offset + buf->len,
140 (int)(len - buf->len));
145 /* |BIO_read| was bound by |buf->cap - buf->len|, so this cannot
147 buf->len += (uint16_t)ret;
183 SSL3_BUFFER *buf = &ssl->s3->read_buffer;
185 consume_buffer(buf, len);
192 assert(SSL_is_dtls(ssl) || len == 0 || buf->len == 0);
221 SSL3_BUFFER *buf = &ssl->s3->write_buffer;
223 if (buf->buf != NULL) {
247 if (!setup_buffer(buf, header_len, cap)) {
250 *out_ptr = buf->buf + buf->offset;
255 SSL3_BUFFER *buf = &ssl->s3->write_buffer;
257 if (len > buf->cap) {
260 buf->len = len;
264 SSL3_BUFFER *buf = &ssl->s3->write_buffer;
266 while (buf->len > 0) {
267 int ret = BIO_write(ssl->wbio, buf->buf + buf->offset, buf->len);
272 consume_buffer(buf, (size_t)ret);
279 SSL3_BUFFER *buf = &ssl->s3->write_buffer;
280 if (buf->len == 0) {
284 int ret = BIO_write(ssl->wbio, buf->buf + buf->offset, buf->len);