lsquic_di_error.c revision 7d09751d
1/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc.  See LICENSE. */
2/*
3 * lsquic_di_error.c -- A placeholder when things go wrong
4 *
5 * This object is used in order to avoid dereferencing NULLs in stream.c
6 */
7
8
9#include <assert.h>
10#include <stddef.h>
11#include <stdint.h>
12#ifdef WIN32
13#include <vc_compat.h>
14#endif
15
16#include "lsquic_types.h"
17#include "lsquic_data_in_if.h"
18
19
20static const struct data_in *error_data_in_ptr;
21
22
23struct data_in *
24data_in_error_new (struct lsquic_conn_public *conn_pub)
25{
26    return (struct data_in *) error_data_in_ptr;
27}
28
29
30static void
31error_di_destroy (struct data_in *data_in)
32{
33}
34
35
36static enum ins_frame
37error_di_insert_frame (struct data_in *data_in,
38                        struct stream_frame *new_frame, uint64_t read_offset)
39{
40    return INS_FRAME_ERR;
41}
42
43
44static struct data_frame *
45error_di_get_frame (struct data_in *data_in, uint64_t read_offset)
46{
47    return NULL;
48}
49
50
51static void
52error_di_frame_done (struct data_in *data_in, struct data_frame *data_frame)
53{
54}
55
56
57static int
58error_di_empty (struct data_in *data_in)
59{
60    return 1;
61}
62
63
64struct data_in *
65error_di_switch_impl (struct data_in *data_in, uint64_t read_offset)
66{
67    assert(0);
68    return data_in;
69}
70
71
72static size_t
73error_di_mem_used (struct data_in *data_in)
74{
75    return 0;
76}
77
78
79static void
80error_di_dump_state (struct data_in *data_in)
81{
82}
83
84static uint64_t
85error_di_readable_bytes (struct data_in *data_in, uint64_t read_offset)
86{
87    return 0;
88}
89
90
91static const struct data_in_iface di_if_error = {
92    .di_destroy      = error_di_destroy,
93    .di_dump_state   = error_di_dump_state,
94    .di_empty        = error_di_empty,
95    .di_frame_done   = error_di_frame_done,
96    .di_get_frame    = error_di_get_frame,
97    .di_insert_frame = error_di_insert_frame,
98    .di_mem_used     = error_di_mem_used,
99    .di_own_on_ok    = 0,   /* Never returns INS_FRAME_OK, but anyway */
100    .di_readable_bytes
101                     = error_di_readable_bytes,
102    .di_switch_impl  = error_di_switch_impl,
103};
104
105
106static const struct data_in error_data_in = {
107    .di_if    = &di_if_error,
108    .di_flags = 0,
109};
110
111
112static const struct data_in *error_data_in_ptr = &error_data_in;
113