Skip to content

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

Merged
merged 3 commits into from
Jun 11, 2025
Merged

Add close/1 #50

merged 3 commits into from
Jun 11, 2025

Conversation

mickel8
Copy link
Member

@mickel8 mickel8 commented Jun 2, 2025

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

@mickel8 mickel8 changed the title Add disconnect Add close/1 Jun 9, 2025
@mickel8 mickel8 requested review from Karolk99 and PiotrWodecki June 9, 2025 13:11
@PiotrWodecki PiotrWodecki requested a review from Copilot June 10, 2025 08:41
Copy link

@Copilot Copilot AI left a 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 implement exd_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, and handle_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 to is_closed or using a proper boolean type (bool) for clarity and consistency with other flags.
int closed;

@PiotrWodecki PiotrWodecki removed their request for review June 10, 2025 10:20
@mickel8 mickel8 enabled auto-merge (squash) June 11, 2025 14:16
@mickel8 mickel8 disabled auto-merge June 11, 2025 14:16
@mickel8 mickel8 merged commit 2773c01 into master Jun 11, 2025
2 checks passed
@mickel8 mickel8 deleted the disconnect branch June 11, 2025 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants