Line data Source code
1 : /*
2 : *
3 : * Copyright 2015, Google Inc.
4 : * All rights reserved.
5 : *
6 : * Redistribution and use in source and binary forms, with or without
7 : * modification, are permitted provided that the following conditions are
8 : * met:
9 : *
10 : * * Redistributions of source code must retain the above copyright
11 : * notice, this list of conditions and the following disclaimer.
12 : * * Redistributions in binary form must reproduce the above
13 : * copyright notice, this list of conditions and the following disclaimer
14 : * in the documentation and/or other materials provided with the
15 : * distribution.
16 : * * Neither the name of Google Inc. nor the names of its
17 : * contributors may be used to endorse or promote products derived from
18 : * this software without specific prior written permission.
19 : *
20 : * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 : * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 : * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 : * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 : * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 : * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 : * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 : * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 : * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 : * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 : * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 : *
32 : */
33 :
34 : #include "src/core/transport/byte_stream.h"
35 :
36 : #include <stdlib.h>
37 :
38 : #include <grpc/support/log.h>
39 :
40 6370293 : int grpc_byte_stream_next(grpc_exec_ctx *exec_ctx,
41 : grpc_byte_stream *byte_stream, gpr_slice *slice,
42 : size_t max_size_hint, grpc_closure *on_complete) {
43 6370293 : return byte_stream->next(exec_ctx, byte_stream, slice, max_size_hint,
44 : on_complete);
45 : }
46 :
47 3957529 : void grpc_byte_stream_destroy(grpc_byte_stream *byte_stream) {
48 3957529 : byte_stream->destroy(byte_stream);
49 3962990 : }
50 :
51 : /* slice_buffer_stream */
52 :
53 2207506 : static int slice_buffer_stream_next(grpc_exec_ctx *exec_ctx,
54 : grpc_byte_stream *byte_stream,
55 : gpr_slice *slice, size_t max_size_hint,
56 : grpc_closure *on_complete) {
57 2207382 : grpc_slice_buffer_stream *stream = (grpc_slice_buffer_stream *)byte_stream;
58 2207506 : GPR_ASSERT(stream->cursor < stream->backing_buffer->count);
59 2207506 : *slice = gpr_slice_ref(stream->backing_buffer->slices[stream->cursor]);
60 2207883 : stream->cursor++;
61 2207883 : return 1;
62 : }
63 :
64 67 : static void slice_buffer_stream_destroy(grpc_byte_stream *byte_stream) {}
65 :
66 3961458 : void grpc_slice_buffer_stream_init(grpc_slice_buffer_stream *stream,
67 : gpr_slice_buffer *slice_buffer,
68 : gpr_uint32 flags) {
69 3961458 : GPR_ASSERT(slice_buffer->length <= GPR_UINT32_MAX);
70 3961458 : stream->base.length = (gpr_uint32)slice_buffer->length;
71 3961458 : stream->base.flags = flags;
72 3961458 : stream->base.next = slice_buffer_stream_next;
73 3961458 : stream->base.destroy = slice_buffer_stream_destroy;
74 3961458 : stream->backing_buffer = slice_buffer;
75 3961458 : stream->cursor = 0;
76 3961458 : }
|