From aa8bddb4e493417991ddd730e28485cb0425d467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20=C3=96hberg?= Date: Thu, 18 Feb 2021 14:54:08 +0100 Subject: [PATCH] Add minimal bug example --- CMakeLists.txt | 3 ++- bugtestmain.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 bugtestmain.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b873396..06dec27 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,4 +62,5 @@ target_link_libraries(srtnet PUBLIC srt ${OPENSSL_LIBRARIES}) add_executable(cppSRTWrapper main.cpp) target_link_libraries(cppSRTWrapper srtnet Threads::Threads) - +add_executable(srtMinimalBugTest bugtestmain.cpp) +target_link_libraries(srtMinimalBugTest srtnet Threads::Threads) diff --git a/bugtestmain.cpp b/bugtestmain.cpp new file mode 100644 index 0000000..a8eaff3 --- /dev/null +++ b/bugtestmain.cpp @@ -0,0 +1,66 @@ +// +// Created by tomas on 2021-02-18. +// + + +#include +#include +#include "SRTNet.h" + + +//This is my class managed by the network connection. +class MyClass { +}; + +//This is a class used to test the optional connection context in the validateConnection callback. +class ConnectionClass { +}; + +//********************************** +//Server part +//********************************** + +//Return a connection object. (Return nullptr if you don't want to connect to that client) +std::shared_ptr +validateConnection(struct sockaddr &rSin, SRTSOCKET lNewSocket, std::shared_ptr &rpCtx) { + auto lNetConn = std::make_shared(); + lNetConn->mObject = std::make_shared(); + return lNetConn; +} + +//Data callback. +bool +handleData(std::unique_ptr> &rContent, SRT_MSGCTRL &rMsgCtrl, std::shared_ptr& rpCtx, + SRTSOCKET lClientHandle) { + return true; +}; + + +int main() { + std::cout << "Running SRT minimal bug test" << std::endl; + { + SRTNet srt; + //Register the server callbacks + srt.clientConnected = std::bind(&validateConnection, std::placeholders::_1, std::placeholders::_2, + std::placeholders::_3); + srt.receivedData = std::bind(&handleData, std::placeholders::_1, std::placeholders::_2, + std::placeholders::_3, std::placeholders::_4); + + auto lConn1 = std::make_shared(); + lConn1->mObject = std::make_shared(); + + if (!srt.startServer("0.0.0.0", 8000, 16, 1000, 100, 1456, "Th1$_is_4_0pt10N4L_P$k", lConn1)) { + std::cout << "SRT Server failed to start." << std::endl; + return EXIT_FAILURE; + } + std::cout << "Server is up for 10 seconds" << std::endl; + std::this_thread::sleep_for(std::chrono::seconds(10)); + + srt.stop(); + } + std::cout << "Stopped and destroyed the server, now the port should be free." << std::endl; + + std::cout << "Sleeping for 20 seconds" << std::endl; + std::this_thread::sleep_for(std::chrono::seconds(20)); + std::cout << "Done" << std::endl; +}