http3 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,188 @@
1
+ #include "nghttp3.h"
2
+
3
+ VALUE rb_cNghttp3Settings;
4
+
5
+ typedef struct {
6
+ nghttp3_settings settings;
7
+ } SettingsObj;
8
+
9
+ static void settings_free(void *ptr) { xfree(ptr); }
10
+
11
+ static size_t settings_memsize(const void *ptr) { return sizeof(SettingsObj); }
12
+
13
+ const rb_data_type_t settings_data_type = {
14
+ .wrap_struct_name = "nghttp3_settings_rb",
15
+ .function =
16
+ {
17
+ .dmark = NULL,
18
+ .dfree = settings_free,
19
+ .dsize = settings_memsize,
20
+ },
21
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY,
22
+ };
23
+
24
+ static VALUE settings_alloc(VALUE klass) {
25
+ SettingsObj *obj;
26
+ VALUE self =
27
+ TypedData_Make_Struct(klass, SettingsObj, &settings_data_type, obj);
28
+ memset(&obj->settings, 0, sizeof(nghttp3_settings));
29
+ return self;
30
+ }
31
+
32
+ /*
33
+ * Returns a pointer to the underlying nghttp3_settings structure.
34
+ */
35
+ nghttp3_settings *nghttp3_rb_get_settings(VALUE rb_settings) {
36
+ SettingsObj *obj;
37
+ TypedData_Get_Struct(rb_settings, SettingsObj, &settings_data_type, obj);
38
+ return &obj->settings;
39
+ }
40
+
41
+ /*
42
+ * call-seq:
43
+ * Settings.new -> Settings
44
+ *
45
+ * Creates a new Settings object with all values set to zero.
46
+ */
47
+ static VALUE rb_nghttp3_settings_initialize(VALUE self) { return self; }
48
+
49
+ /*
50
+ * call-seq:
51
+ * Settings.default -> Settings
52
+ *
53
+ * Creates a new Settings object with default values from nghttp3.
54
+ */
55
+ static VALUE rb_nghttp3_settings_default(VALUE klass) {
56
+ VALUE self = settings_alloc(klass);
57
+ SettingsObj *obj;
58
+ TypedData_Get_Struct(self, SettingsObj, &settings_data_type, obj);
59
+ nghttp3_settings_default(&obj->settings);
60
+ return self;
61
+ }
62
+
63
+ /* Settings getters */
64
+ static VALUE rb_nghttp3_settings_get_max_field_section_size(VALUE self) {
65
+ SettingsObj *obj;
66
+ TypedData_Get_Struct(self, SettingsObj, &settings_data_type, obj);
67
+ return ULL2NUM(obj->settings.max_field_section_size);
68
+ }
69
+
70
+ static VALUE rb_nghttp3_settings_get_qpack_max_dtable_capacity(VALUE self) {
71
+ SettingsObj *obj;
72
+ TypedData_Get_Struct(self, SettingsObj, &settings_data_type, obj);
73
+ return SIZET2NUM(obj->settings.qpack_max_dtable_capacity);
74
+ }
75
+
76
+ static VALUE
77
+ rb_nghttp3_settings_get_qpack_encoder_max_dtable_capacity(VALUE self) {
78
+ SettingsObj *obj;
79
+ TypedData_Get_Struct(self, SettingsObj, &settings_data_type, obj);
80
+ return SIZET2NUM(obj->settings.qpack_encoder_max_dtable_capacity);
81
+ }
82
+
83
+ static VALUE rb_nghttp3_settings_get_qpack_blocked_streams(VALUE self) {
84
+ SettingsObj *obj;
85
+ TypedData_Get_Struct(self, SettingsObj, &settings_data_type, obj);
86
+ return SIZET2NUM(obj->settings.qpack_blocked_streams);
87
+ }
88
+
89
+ static VALUE rb_nghttp3_settings_get_enable_connect_protocol(VALUE self) {
90
+ SettingsObj *obj;
91
+ TypedData_Get_Struct(self, SettingsObj, &settings_data_type, obj);
92
+ return obj->settings.enable_connect_protocol ? Qtrue : Qfalse;
93
+ }
94
+
95
+ static VALUE rb_nghttp3_settings_get_h3_datagram(VALUE self) {
96
+ SettingsObj *obj;
97
+ TypedData_Get_Struct(self, SettingsObj, &settings_data_type, obj);
98
+ return obj->settings.h3_datagram ? Qtrue : Qfalse;
99
+ }
100
+
101
+ /* Settings setters */
102
+ static VALUE rb_nghttp3_settings_set_max_field_section_size(VALUE self,
103
+ VALUE val) {
104
+ SettingsObj *obj;
105
+ TypedData_Get_Struct(self, SettingsObj, &settings_data_type, obj);
106
+ obj->settings.max_field_section_size = NUM2ULL(val);
107
+ return val;
108
+ }
109
+
110
+ static VALUE rb_nghttp3_settings_set_qpack_max_dtable_capacity(VALUE self,
111
+ VALUE val) {
112
+ SettingsObj *obj;
113
+ TypedData_Get_Struct(self, SettingsObj, &settings_data_type, obj);
114
+ obj->settings.qpack_max_dtable_capacity = NUM2SIZET(val);
115
+ return val;
116
+ }
117
+
118
+ static VALUE
119
+ rb_nghttp3_settings_set_qpack_encoder_max_dtable_capacity(VALUE self,
120
+ VALUE val) {
121
+ SettingsObj *obj;
122
+ TypedData_Get_Struct(self, SettingsObj, &settings_data_type, obj);
123
+ obj->settings.qpack_encoder_max_dtable_capacity = NUM2SIZET(val);
124
+ return val;
125
+ }
126
+
127
+ static VALUE rb_nghttp3_settings_set_qpack_blocked_streams(VALUE self,
128
+ VALUE val) {
129
+ SettingsObj *obj;
130
+ TypedData_Get_Struct(self, SettingsObj, &settings_data_type, obj);
131
+ obj->settings.qpack_blocked_streams = NUM2SIZET(val);
132
+ return val;
133
+ }
134
+
135
+ static VALUE rb_nghttp3_settings_set_enable_connect_protocol(VALUE self,
136
+ VALUE val) {
137
+ SettingsObj *obj;
138
+ TypedData_Get_Struct(self, SettingsObj, &settings_data_type, obj);
139
+ obj->settings.enable_connect_protocol = RTEST(val) ? 1 : 0;
140
+ return val;
141
+ }
142
+
143
+ static VALUE rb_nghttp3_settings_set_h3_datagram(VALUE self, VALUE val) {
144
+ SettingsObj *obj;
145
+ TypedData_Get_Struct(self, SettingsObj, &settings_data_type, obj);
146
+ obj->settings.h3_datagram = RTEST(val) ? 1 : 0;
147
+ return val;
148
+ }
149
+
150
+ void Init_nghttp3_settings(void) {
151
+ rb_cNghttp3Settings =
152
+ rb_define_class_under(rb_mNghttp3, "Settings", rb_cObject);
153
+ rb_define_alloc_func(rb_cNghttp3Settings, settings_alloc);
154
+ rb_define_method(rb_cNghttp3Settings, "initialize",
155
+ rb_nghttp3_settings_initialize, 0);
156
+ rb_define_singleton_method(rb_cNghttp3Settings, "default",
157
+ rb_nghttp3_settings_default, 0);
158
+
159
+ /* Settings getters */
160
+ rb_define_method(rb_cNghttp3Settings, "max_field_section_size",
161
+ rb_nghttp3_settings_get_max_field_section_size, 0);
162
+ rb_define_method(rb_cNghttp3Settings, "qpack_max_dtable_capacity",
163
+ rb_nghttp3_settings_get_qpack_max_dtable_capacity, 0);
164
+ rb_define_method(rb_cNghttp3Settings, "qpack_encoder_max_dtable_capacity",
165
+ rb_nghttp3_settings_get_qpack_encoder_max_dtable_capacity,
166
+ 0);
167
+ rb_define_method(rb_cNghttp3Settings, "qpack_blocked_streams",
168
+ rb_nghttp3_settings_get_qpack_blocked_streams, 0);
169
+ rb_define_method(rb_cNghttp3Settings, "enable_connect_protocol",
170
+ rb_nghttp3_settings_get_enable_connect_protocol, 0);
171
+ rb_define_method(rb_cNghttp3Settings, "h3_datagram",
172
+ rb_nghttp3_settings_get_h3_datagram, 0);
173
+
174
+ /* Settings setters */
175
+ rb_define_method(rb_cNghttp3Settings, "max_field_section_size=",
176
+ rb_nghttp3_settings_set_max_field_section_size, 1);
177
+ rb_define_method(rb_cNghttp3Settings, "qpack_max_dtable_capacity=",
178
+ rb_nghttp3_settings_set_qpack_max_dtable_capacity, 1);
179
+ rb_define_method(rb_cNghttp3Settings, "qpack_encoder_max_dtable_capacity=",
180
+ rb_nghttp3_settings_set_qpack_encoder_max_dtable_capacity,
181
+ 1);
182
+ rb_define_method(rb_cNghttp3Settings, "qpack_blocked_streams=",
183
+ rb_nghttp3_settings_set_qpack_blocked_streams, 1);
184
+ rb_define_method(rb_cNghttp3Settings, "enable_connect_protocol=",
185
+ rb_nghttp3_settings_set_enable_connect_protocol, 1);
186
+ rb_define_method(rb_cNghttp3Settings,
187
+ "h3_datagram=", rb_nghttp3_settings_set_h3_datagram, 1);
188
+ }