-
Notifications
You must be signed in to change notification settings - Fork 2
Add close/1 #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add close/1 #50
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds a new close/1
function to ExDTLS that irreversibly closes a DTLS session and updates existing APIs to return {:error, :closed}
on further operations.
- Delegates
close/1
to the native layer with docs and a spec. - Extends Unifex specs and C code to track a
closed
flag, guard operations, and implementexd_close
. - Updates existing tests to match the new return shapes and adds tests for
close/1
.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
lib/ex_dtls.ex | Added @doc , @spec , and defdelegate close/1 to Native.exd_close |
c_src/ex_dtls/native.spec.exs | Extended specs for do_handshake , handle_timeout , write_data , handle_data , and added exd_close |
c_src/ex_dtls/native.h | Introduced int closed; flag in State struct |
c_src/ex_dtls/native.c | Initialized and checked closed , implemented exd_close with pending-data logic |
test/retransmission_test.exs | Updated pattern match for new {:ok, ...} return from do_handshake/1 |
test/integration_test.exs | Updated handshake calls and added describe "disconnect" tests for close/1 |
Comments suppressed due to low confidence (3)
lib/ex_dtls.ex:198
- [nitpick] Expand the
close/1
doc to mention that it is idempotent: subsequent calls return{:ok, []}
and that other operations will return{:error, :closed}
.
@doc """
test/integration_test.exs:66
- Add tests to verify that
write_data/1
,handle_data/1
, andhandle_timeout/1
on a closed session return{:error, :closed}
for full coverage of the closed state.
assert {:ok, []} = ExDTLS.close(dtls)
c_src/ex_dtls/native.h:16
- [nitpick] Consider renaming the
closed
field tois_closed
or using a proper boolean type (bool
) for clarity and consistency with other flags.
int closed;
Add a function that closes DTLS connection and invalidates the state i.e. most actions are no longer possible (e.g. performing handshake or writing data)
NOTE This PR introduces breaking changes in the API - some of the functions can now return
{:ok, ...} | {:error, :closed}
tuples.Related to: elixir-webrtc/ex_webrtc#218