@@ -434,9 +434,10 @@ int Invoker::isInterrupted(UInt32 RTMFPcontext) {
434
434
lock_guard<mutex> lock (_mutexConnections);
435
435
auto it = _mapConnections.find (RTMFPcontext);
436
436
if (it == _mapConnections.end ())
437
- return ERROR_CONN_INTERRUPT;
438
- if (it->second ->isInterrupted ()) {
439
- removeConnection (it, true );
437
+ return ERROR_CONN_INTERRUPT;
438
+ bool interrupted = it->second ->isInterrupted ();
439
+ if (interrupted || it->second ->status >= RTMFP::NEAR_CLOSED) {
440
+ removeConnection (it, interrupted);
440
441
return _mapConnections.empty ()? ERROR_LAST_INTERRUPT : ERROR_CONN_INTERRUPT;
441
442
}
442
443
}
@@ -717,16 +718,22 @@ int Invoker::waitForEvent(UInt32 RTMFPcontext, UInt8 mask) {
717
718
int handled = 0 ;
718
719
719
720
while (!handled) {
720
- int code (0 );
721
- if ((code = isInterrupted (RTMFPcontext)))
722
- return code;
721
+ if (!Thread::running ())
722
+ return ERROR_APP_INTERRUPT;
723
723
724
- // Event handled?
725
- _mutexConnections.lock ();
726
- auto it = _mapConnections.find (RTMFPcontext);
727
- if (it->second ->flags & mask)
728
- handled = 1 ;
729
- _mutexConnections.unlock ();
724
+ {
725
+ lock_guard<mutex> lock (_mutexConnections);
726
+ auto it = _mapConnections.find (RTMFPcontext);
727
+ if (it == _mapConnections.end ())
728
+ return ERROR_CONN_INTERRUPT;
729
+ bool interrupted = it->second ->isInterrupted ();
730
+ if (interrupted || it->second ->status >= RTMFP::NEAR_CLOSED) {
731
+ removeConnection (it, interrupted);
732
+ return _mapConnections.empty () ? ERROR_LAST_INTERRUPT : ERROR_CONN_INTERRUPT;
733
+ } else if (it->second ->flags & mask) // Event handled?
734
+ handled = 1 ;
735
+ }
736
+ return 0 ;
730
737
}
731
738
732
739
return handled;
@@ -780,17 +787,9 @@ bool Invoker::callFunction(UInt32 RTMFPcontext, const char* function, int nbArgs
780
787
781
788
int Invoker::write (unsigned int RTMFPcontext, const UInt8* data, UInt32 size) {
782
789
783
- {
784
- lock_guard<mutex> lock (_mutexConnections);
785
-
786
- auto it = _mapConnections.find (RTMFPcontext);
787
- if (it == _mapConnections.end ()) {
788
- ERROR (" Invoker::write() - Unable to find the connection " , RTMFPcontext)
789
- return -1 ;
790
- }
791
- else if (it->second ->status >= RTMFP::NEAR_CLOSED)
792
- return -1 ; // to stop the caller loop
793
- }
790
+ int code (0 );
791
+ if ((code = isInterrupted (RTMFPcontext)))
792
+ return code;
794
793
795
794
// Find the writing buffer for current session
796
795
lock_guard<mutex> lock (_mutexWrite);
0 commit comments