-
Notifications
You must be signed in to change notification settings - Fork 5
Expose connection logic to C++ FFI #20
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
Conversation
dcsctp-cxx/examples/main.cpp
Outdated
| #include <iostream> | ||
| #include <stdexcept> | ||
| #include <string> | ||
| #include <vector> |
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.
| #include <vector> |
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.
Done
| @@ -1,26 +1,102 @@ | |||
| #include "dcsctp.h" | |||
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.
| #include "dcsctp.h" | |
| #include "dcsctp.h" | |
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.
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); |
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.
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?
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.
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.
This change exposes the basic functionality required to establish a dcSCTP connection from a C++ application. It adds FFI bindings for
connect,handle_input, andpoll_event.To model this in C++,
poll_eventnow returns anEventstruct, which can be used to distinguish between different socket events such asOnConnectedandSendPacket. 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.cpphas been updated to demonstrate the explicit connection handshake between two sockets, mirroring the logic in theestablish_connectionRust test.