Skip to content

Commit c09cd88

Browse files
committed
Fully disable quicer/h3 unless COWBOY_QUICER is set
This should avoid Dialyzer errors. A CI job testing without COWBOY_QUICER has also been added.
1 parent aadc095 commit c09cd88

File tree

4 files changed

+30
-53
lines changed

4 files changed

+30
-53
lines changed

.github/workflows/ci.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ jobs:
2121
if: ${{ !cancelled() }}
2222
uses: ninenines/ci.erlang.mk/.github/workflows/ci.yaml@master
2323

24+
dialyzer-no-quicer:
25+
name: Dialyzer (without COWBOY_QUICER)
26+
runs-on: ubuntu-latest
27+
steps:
28+
29+
- name: Checkout repository
30+
uses: actions/checkout@v4
31+
32+
- name: Install latest Erlang/OTP
33+
uses: erlef/setup-beam@v1
34+
with:
35+
otp-version: '> 0'
36+
37+
- name: Run Dialyzer (without COWBOY_QUICER)
38+
run: make dialyze COWBOY_QUICER=0
39+
2440
examples:
2541
name: Check examples
2642
runs-on: ubuntu-latest

src/cowboy.erl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@
1616

1717
-export([start_clear/3]).
1818
-export([start_tls/3]).
19-
-export([start_quic/3]).
2019
-export([stop_listener/1]).
2120
-export([get_env/2]).
2221
-export([get_env/3]).
2322
-export([set_env/3]).
2423

24+
-ifdef(COWBOY_QUICER).
25+
-export([start_quic/3]).
26+
-endif.
27+
2528
%% Internal.
2629
-export([log/2]).
2730
-export([log/4]).
2831

29-
%% Don't warn about the bad quicer specs.
30-
-dialyzer([{nowarn_function, start_quic/3}]).
31-
3232
-type opts() :: cowboy_http:opts() | cowboy_http2:opts().
3333
-export_type([opts/0]).
3434

@@ -73,6 +73,8 @@ start_tls(Ref, TransOpts0, ProtoOpts0) ->
7373
},
7474
ranch:start_listener(Ref, ranch_ssl, TransOpts, cowboy_tls, ProtoOpts).
7575

76+
-ifdef(COWBOY_QUICER).
77+
7678
%% @todo Experimental function to start a barebone QUIC listener.
7779
%% This will need to be reworked to be closer to Ranch
7880
%% listeners and provide equivalent features.
@@ -151,6 +153,8 @@ port_0() ->
151153
end,
152154
Port.
153155

156+
-endif.
157+
154158
ensure_alpn(TransOpts) ->
155159
SocketOpts = maps:get(socket_opts, TransOpts, []),
156160
TransOpts#{socket_opts => [

src/cowboy_http3.erl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
-module(cowboy_http3).
2121

22+
-ifdef(COWBOY_QUICER).
23+
2224
-export([init/4]).
2325

2426
%% Temporary callback to do sendfile over QUIC.
@@ -1303,3 +1305,5 @@ stream_linger(State=#state{lingering_streams=Lingering0}, StreamID) ->
13031305

13041306
is_lingering_stream(#state{lingering_streams=Lingering}, StreamID) ->
13051307
lists:member(StreamID, Lingering).
1308+
1309+
-endif.

src/cowboy_quicer.erl

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
-module(cowboy_quicer).
1818

19+
-ifdef(COWBOY_QUICER).
20+
1921
%% Connection.
2022
-export([peername/1]).
2123
-export([sockname/1]).
@@ -35,55 +37,6 @@
3537
%% Messages.
3638
-export([handle/1]).
3739

38-
-ifndef(COWBOY_QUICER).
39-
40-
-spec peername(_) -> no_return().
41-
peername(_) -> no_quicer().
42-
43-
-spec sockname(_) -> no_return().
44-
sockname(_) -> no_quicer().
45-
46-
-spec peercert(_) -> no_return().
47-
peercert(_) -> no_quicer().
48-
49-
-spec shutdown(_, _) -> no_return().
50-
shutdown(_, _) -> no_quicer().
51-
52-
-spec start_bidi_stream(_, _) -> no_return().
53-
start_bidi_stream(_, _) -> no_quicer().
54-
55-
-spec start_unidi_stream(_, _) -> no_return().
56-
start_unidi_stream(_, _) -> no_quicer().
57-
58-
-spec setopt(_, _, _, _) -> no_return().
59-
setopt(_, _, _, _) -> no_quicer().
60-
61-
-spec send(_, _, _) -> no_return().
62-
send(_, _, _) -> no_quicer().
63-
64-
-spec send(_, _, _, _) -> no_return().
65-
send(_, _, _, _) -> no_quicer().
66-
67-
-spec send_datagram(_, _) -> no_return().
68-
send_datagram(_, _) -> no_quicer().
69-
70-
-spec shutdown_stream(_, _) -> no_return().
71-
shutdown_stream(_, _) -> no_quicer().
72-
73-
-spec shutdown_stream(_, _, _, _) -> no_return().
74-
shutdown_stream(_, _, _, _) -> no_quicer().
75-
76-
-spec handle(_) -> no_return().
77-
handle(_) -> no_quicer().
78-
79-
no_quicer() ->
80-
error({no_quicer,
81-
"Cowboy must be compiled with environment variable COWBOY_QUICER=1 "
82-
"or with compilation flag -D COWBOY_QUICER=1 in order to enable "
83-
"QUIC support using the emqx/quic NIF"}).
84-
85-
-else.
86-
8740
%% @todo Make quicer export these types.
8841
-type quicer_connection_handle() :: reference().
8942
-export_type([quicer_connection_handle/0]).

0 commit comments

Comments
 (0)