45
45
async_connect /3 ,
46
46
handshake /1 ,
47
47
handshake /2 ,
48
+ handshake /3 ,
48
49
async_handshake /1 ,
50
+ async_handshake /2 ,
49
51
accept /2 ,
50
52
accept /3 ,
51
53
async_accept /2 ,
59
61
close_connection /4 ,
60
62
async_close_connection /1 ,
61
63
async_close_connection /3 ,
64
+ probe /2 ,
62
65
accept_stream /2 ,
63
66
accept_stream /3 ,
64
67
async_accept_stream /2 ,
69
72
async_send /2 ,
70
73
async_send /3 ,
71
74
recv /2 ,
75
+ async_send_dgram /2 ,
72
76
send_dgram /2 ,
73
77
shutdown_stream /1 ,
74
78
shutdown_stream /2 ,
174
178
quicer_addr / 0 ,
175
179
176
180
% % Registraion Profiles
177
- registration_profile / 0
181
+ registration_profile / 0 ,
182
+
183
+ % % probes
184
+ probe_res / 0
178
185
]).
179
186
180
187
-type connection_opts () :: proplists :proplist () | conn_opts ().
@@ -447,14 +454,29 @@ async_connect(Host, Port, Opts) when is_map(Opts) ->
447
454
handshake (Conn ) ->
448
455
handshake (Conn , 5000 ).
449
456
457
+ -spec handshake (connection_handle (), timeout ()) ->
458
+ {ok , connection_handle ()} | {error , any ()}.
459
+ handshake (Conn , Timeout ) ->
460
+ case async_handshake (Conn ) of
461
+ {error , _ } = E ->
462
+ E ;
463
+ ok ->
464
+ receive
465
+ {quic , connected , Conn , _ } -> {ok , Conn };
466
+ {quic , closed , Conn , _Flags } -> {error , closed }
467
+ after Timeout ->
468
+ {error , timeout }
469
+ end
470
+ end .
471
+
450
472
% % @doc Complete TLS handshake after accepted a Connection
451
473
% % @see handshake/2
452
474
% % @see async_handshake/1
453
- -spec handshake (connection_handle (), timeout ()) ->
475
+ -spec handshake (connection_handle (), conn_opts (), timeout ()) ->
454
476
{ok , connection_handle ()}
455
477
| {error , any ()}.
456
- handshake (Conn , Timeout ) ->
457
- case async_handshake (Conn ) of
478
+ handshake (Conn , ConnOpts , Timeout ) ->
479
+ case async_handshake (Conn , ConnOpts ) of
458
480
{error , _ } = E ->
459
481
E ;
460
482
ok ->
@@ -467,13 +489,24 @@ handshake(Conn, Timeout) ->
467
489
end .
468
490
469
491
% % @doc Complete TLS handshake after accepted a Connection.
470
- % % Caller should expect to receive ```{quic, connected, connection_handle()}'''
471
492
% %
472
493
% % @see handshake/2
494
+ % % @see async_handshake/2
473
495
-spec async_handshake (connection_handle ()) -> ok | {error , any ()}.
474
496
async_handshake (Conn ) ->
475
497
quicer_nif :async_handshake (Conn ).
476
498
499
+ % % @doc Complete TLS handshake after accepted a Connection.
500
+ % % also set connection options which override the default listener options.
501
+ % %
502
+ % % @see handshake/2
503
+ % % @see async_handshake/1
504
+ -spec async_handshake (connection_handle (), conn_opts ()) -> ok | {error , any ()}.
505
+ async_handshake (Conn , ConnOpts ) when is_list (ConnOpts ) ->
506
+ async_handshake (Conn , maps :from_list (ConnOpts ));
507
+ async_handshake (Conn , ConnOpts ) ->
508
+ quicer_nif :async_handshake (Conn , ConnOpts ).
509
+
477
510
% % @doc Accept new Connection (Server)
478
511
% %
479
512
% % Accept new connection from listener_handle().
@@ -816,35 +849,49 @@ do_recv(Stream, Count, Buff) ->
816
849
E
817
850
end .
818
851
852
+ % % @doc Sending Unreliable Datagram.
853
+ % % Caller should handle the async signals for the send results
854
+ % %
855
+ % % ref: [https://datatracker.ietf.org/doc/html/rfc9221]
856
+ % % @see send/2 send_dgram/2
857
+ -spec async_send_dgram (connection_handle (), binary ()) ->
858
+ {ok , non_neg_integer ()}
859
+ | {error , badarg | not_enough_mem | invalid_parameter | closed }
860
+ | {error , dgram_send_error , atom_reason ()}.
861
+ async_send_dgram (Conn , Data ) ->
862
+ quicer_nif :send_dgram (Conn , Data , _IsSyncRel = 1 ).
863
+
819
864
% % @doc Sending Unreliable Datagram
865
+ % % return error only if sending could not be scheduled such as
866
+ % % not_enough_mem, connection is already closed or wrong args.
867
+ % % otherwise, it is fire and forget.
820
868
% %
821
- % % ref: [https://datatracker.ietf.org/doc/html/draft-ietf-quic-datagram ]
822
- % % @see send/2
869
+ % % %% ref: [https://datatracker.ietf.org/doc/html/rfc9221 ]
870
+ % % @see send/2, async_send_dgram/2
823
871
-spec send_dgram (connection_handle (), binary ()) ->
824
- {ok , BytesSent :: pos_integer ()}
825
- | {error , badarg | not_enough_mem | closed }
872
+ {ok , BytesSent :: non_neg_integer ()}
873
+ | {error , badarg | not_enough_mem | invalid_parameter | closed }
826
874
| {error , dgram_send_error , atom_reason ()}.
827
875
send_dgram (Conn , Data ) ->
828
876
case quicer_nif :send_dgram (Conn , Data , _IsSync = 1 ) of
829
- % % @todo we need find tuned event mask
830
877
{ok , _Len } = OK ->
831
- receive
832
- {quic , dgram_send_state , Conn , #{state := ? QUIC_DATAGRAM_SEND_SENT }} ->
833
- receive
834
- {quic , dgram_send_state , Conn , #{state := ? QUIC_DATAGRAM_SEND_ACKNOWLEDGED }} ->
835
- OK ;
836
- {quic , dgram_send_state , Conn , #{state := Other }} ->
837
- {error , dgram_send_error , Other }
838
- end ;
839
- {quic , dgram_send_state , Conn , #{state := ? QUIC_DATAGRAM_SEND_ACKNOWLEDGED }} ->
878
+ case quicer_lib :handle_dgram_send_states (Conn ) of
879
+ ok ->
840
880
OK ;
841
- {quic , dgram_send_state , Conn , #{ state : = Other } } ->
842
- {error , dgram_send_error , Other }
881
+ {error , E } ->
882
+ {error , dgram_send_error , E }
843
883
end ;
884
+ {error , E } ->
885
+ {error , E };
844
886
E ->
845
887
E
846
888
end .
847
889
890
+ % % @doc Probe conn state with 0 len dgram.
891
+ -spec probe (connection_handle (), timeout ()) -> probe_res ().
892
+ probe (Conn , Timeout ) ->
893
+ quicer_lib :probe (Conn , Timeout ).
894
+
848
895
% % @doc Shutdown stream gracefully, with infinity timeout
849
896
% %
850
897
% % @see shutdown_stream/1
0 commit comments