bugfix: listener stops randomly

detail:
- task is running
- an OSC message is received, _pendingMessages is not yet empty
- task finishes before the OSC message is added to _pendingMessages
- no other task can be executed (_pendingMessages is never empty)
This commit is contained in:
monsieurgustav
2015-12-30 23:59:41 +01:00
parent bfe838e8a0
commit 65ee771d80
2 changed files with 9 additions and 5 deletions
@@ -165,8 +165,6 @@ static void SendBundle(TCircularQueue<std::pair<FName, TArray<FOscDataElemStruct
void UOscDispatcher::Callback(const FArrayReaderPtr& data, const FIPv4Endpoint&)
{
const auto wasEmpty = _pendingMessages.IsEmpty();
const osc::ReceivedPacket packet((const char *)data->GetData(), data->Num());
if(packet.State() != osc::SUCCESS)
{
@@ -184,9 +182,9 @@ void UOscDispatcher::Callback(const FArrayReaderPtr& data, const FIPv4Endpoint&)
}
// Set a single callback in the main thread per frame.
if(wasEmpty && !_pendingMessages.IsEmpty())
if(!_pendingMessages.IsEmpty() && !_runPendingMessagesTask)
{
FSimpleDelegateGraphTask::CreateAndDispatchWhenReady(
_runPendingMessagesTask = FSimpleDelegateGraphTask::CreateAndDispatchWhenReady(
FSimpleDelegateGraphTask::FDelegate::CreateUObject(this, &UOscDispatcher::CallbackMainThread),
TStatId(),
nullptr,
@@ -205,6 +203,11 @@ void UOscDispatcher::Callback(const FArrayReaderPtr& data, const FIPv4Endpoint&)
void UOscDispatcher::CallbackMainThread()
{
// Release before dequeue.
// If it was released after dequeue, when a message arrives after the while
// loop and before the release, it would not be processed.
_runPendingMessagesTask.SafeRelease();
FScopeLock ScopeLock(&_receiversMutex);
std::pair<FName, TArray<FOscDataElemStruct>> message;
@@ -43,13 +43,14 @@ private:
void CallbackMainThread();
void BeginDestroy() override;
private:
TArray<IOscReceiverInterface *> _receivers;
std::pair<FIPv4Address, uint32_t> _listening;
FSocket * _socket;
FUdpSocketReceiver * _socketReceiver;
TCircularQueue<std::pair<FName, TArray<FOscDataElemStruct>>> _pendingMessages;
FGraphEventRef _runPendingMessagesTask;
/// Protects _receivers
FCriticalSection _receiversMutex;