lsquic_di_error.c revision 10c492f0
1/* Copyright (c) 2017 - 2018 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_data_in_if.h"
17
18
19static const struct data_in *error_data_in_ptr;
20
21
22struct data_in *
23data_in_error_new (struct lsquic_conn_public *conn_pub)
24{
25    return (struct data_in *) error_data_in_ptr;
26}
27
28
29static void
30error_di_destroy (struct data_in *data_in)
31{
32}
33
34
35static enum ins_frame
36error_di_insert_frame (struct data_in *data_in,
37                        struct stream_frame *new_frame, uint64_t read_offset)
38{
39    return INS_FRAME_ERR;
40}
41
42
43static struct data_frame *
44error_di_get_frame (struct data_in *data_in, uint64_t read_offset)
45{
46    return NULL;
47}
48
49
50static void
51error_di_frame_done (struct data_in *data_in, struct data_frame *data_frame)
52{
53}
54
55
56static int
57error_di_empty (struct data_in *data_in)
58{
59    return 1;
60}
61
62
63struct data_in *
64error_di_switch_impl (struct data_in *data_in, uint64_t read_offset)
65{
66    assert(0);
67    return data_in;
68}
69
70
71static size_t
72error_di_mem_used (struct data_in *data_in)
73{
74    return 0;
75}
76
77
78static const struct data_in_iface di_if_error = {
79    .di_destroy      = error_di_destroy,
80    .di_empty        = error_di_empty,
81    .di_frame_done   = error_di_frame_done,
82    .di_get_frame    = error_di_get_frame,
83    .di_insert_frame = error_di_insert_frame,
84    .di_mem_used     = error_di_mem_used,
85    .di_switch_impl  = error_di_switch_impl,
86};
87
88
89static const struct data_in error_data_in = {
90    .di_if    = &di_if_error,
91    .di_flags = 0,
92};
93
94
95static const struct data_in *error_data_in_ptr = &error_data_in;
96