Skip to content

Conversation

@boivie
Copy link
Collaborator

@boivie boivie commented Dec 1, 2025

This change exposes the basic functionality required to establish a dcSCTP connection from a C++ application. It adds FFI bindings for connect, handle_input, and poll_event.

To model this in C++, poll_event now returns an Event struct, which can be used to distinguish between different socket events such as OnConnected and SendPacket. As the cxx FFI doesn't support rich types such as std::variant, having a fat struct as interface between Rust and C++ is simple and doesn't add much overhead.

The C++ example in dcsctp-cxx/examples/main.cpp has been updated to demonstrate the explicit connection handshake between two sockets, mirroring the logic in the establish_connection Rust test.

#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include <vector>

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -1,26 +1,102 @@
#include "dcsctp.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include "dcsctp.h"
#include "dcsctp.h"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

dcsctp_cxx::delete_socket(socket);
std::cout << "Sockets are about to be deleted." << std::endl;
dcsctp_cxx::delete_socket(socket_a);
dcsctp_cxx::delete_socket(socket_z);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not the end of the world since this is example code, but is there a better strategy for making sure this is properly executed if the code throws?

Maybe it's worth providing a RAII wrapper in C++ that handles this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cxx wrapper interface is not intended to be used directly - absolutely not. The limitations on the types that cxx supports is very limited, and we absolutely want to provide a RAII wrapper that use better types (and converts back and forth). It might be that we put that wrapper inside the libwebrtc git and make it implement dcsctp::DcSctpSocketInterface, but I haven't made up my mind about that yet.

This change exposes the basic functionality required to establish a
dcSCTP connection from a C++ application. It adds FFI bindings for
`connect`, `handle_input`, and `poll_event`.

To model this in C++, `poll_event` now returns an `Event` struct, which
can be used to distinguish between different socket events such as
`OnConnected` and `SendPacket`. As the cxx FFI doesn't support rich
types such as std::variant, having a fat struct as interface between
Rust and C++ is simple and doesn't add much overhead.

The C++ example in `dcsctp-cxx/examples/main.cpp` has been updated to
demonstrate the explicit connection handshake between two sockets,
mirroring the logic in the `establish_connection` Rust test.
@boivie boivie merged commit 3ffdbec into webrtc:main Dec 2, 2025
7 checks passed
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