Conversation
dcsctp-cxx/examples/main.cpp
Outdated
| #include <iostream> | ||
| #include <stdexcept> | ||
| #include <string> | ||
| #include <vector> |
There was a problem hiding this comment.
| #include <vector> |
| @@ -1,26 +1,102 @@ | |||
| #include "dcsctp.h" | |||
There was a problem hiding this comment.
| #include "dcsctp.h" | |
| #include "dcsctp.h" | |
| 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.
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.
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.