Skip to content

Commit 4a769f1

Browse files
committed
Fix std::any OOB callback bug
1 parent 5f26cbb commit 4a769f1

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

RISTNet.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ int RISTNetReceiver::receiveOOBData(void *pArg, const rist_oob_block *pOOBBlock)
123123
if (lWeakSelf->networkOOBDataCallback) { //This is a optional callback
124124
if (lWeakSelf->mClientListReceiver.empty()) {
125125
auto lEmptyContext = std::make_shared<NetworkConnection>(); //In this case we got no connections the NetworkConnection will contain a std::any == nullptr
126+
lEmptyContext->mObject.reset();
126127
lWeakSelf->networkOOBDataCallback((const uint8_t *) pOOBBlock->payload, pOOBBlock->payload_len, lEmptyContext, pOOBBlock->peer);
127128
return 0;
128129
}
@@ -408,6 +409,7 @@ int RISTNetSender::receiveOOBData(void *pArg, const rist_oob_block *pOOBBlock) {
408409
if (lWeakSelf->networkOOBDataCallback) { //This is a optional callback
409410
if (lWeakSelf->mClientListSender.empty()) {
410411
auto lEmptyContext = std::make_shared<NetworkConnection>(); //In this case we got no connections the NetworkConnection will contain a std::any == nullptr
412+
lEmptyContext->mObject.reset();
411413
lWeakSelf->networkOOBDataCallback((const uint8_t *) pOOBBlock->payload, pOOBBlock->payload_len, lEmptyContext, pOOBBlock->peer);
412414
return 0;
413415
}

main.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,15 @@ dataFromSender(const uint8_t *buf, size_t len, std::shared_ptr<RISTNetReceiver::
7777

7878
void oobDataFromReceiver(const uint8_t *buf, size_t len, std::shared_ptr<RISTNetSender::NetworkConnection> &connection,
7979
rist_peer *pPeer) {
80-
std::cout << "Got " << unsigned(len) << " bytes of oob data from the receiver" << std::endl;
80+
81+
if (connection->mObject.has_value()) {
82+
//You are the server so the connection has a Context
83+
std::cout << "Got " << unsigned(len) << " bytes of oob data from the receiver" << std::endl;
84+
} else {
85+
//You are not the server so the connection does not have a context (meaning you connected to the server and the server sends OOB to you).
86+
std::cout << "Got " << unsigned(len) << " bytes of oob data from the receiver" << std::endl;
87+
}
88+
8189
}
8290

8391
void clientDisconnect(const std::shared_ptr<RISTNetReceiver::NetworkConnection>& connection, const rist_peer& peer) {

0 commit comments

Comments
 (0)