Skip to content

Commit 311698a

Browse files
committed
- Update of isInterrupted to remove also connections which are closed
- Improvement of waitForEvent speed - Function write now use isInterrupted
1 parent 99261cf commit 311698a

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

include/RTMFP.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ along with Librtmfp. If not, see <http://www.gnu.org/licenses/>.
3535
#include "Base/Logs.h"
3636
#include <map>
3737

38-
#define RTMFP_LIB_VERSION 0x020E0001 // (2.14.1)
38+
#define RTMFP_LIB_VERSION 0x020E0002 // (2.14.2)
3939

4040
#define RTMFP_DEFAULT_KEY (Base::UInt8*)"Adobe Systems 02"
4141
#define RTMFP_KEY_SIZE 0x10

sources/Invoker.cpp

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,10 @@ int Invoker::isInterrupted(UInt32 RTMFPcontext) {
434434
lock_guard<mutex> lock(_mutexConnections);
435435
auto it = _mapConnections.find(RTMFPcontext);
436436
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);
440441
return _mapConnections.empty()? ERROR_LAST_INTERRUPT : ERROR_CONN_INTERRUPT;
441442
}
442443
}
@@ -717,16 +718,22 @@ int Invoker::waitForEvent(UInt32 RTMFPcontext, UInt8 mask) {
717718
int handled = 0;
718719

719720
while (!handled) {
720-
int code(0);
721-
if ((code = isInterrupted(RTMFPcontext)))
722-
return code;
721+
if (!Thread::running())
722+
return ERROR_APP_INTERRUPT;
723723

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;
730737
}
731738

732739
return handled;
@@ -780,17 +787,9 @@ bool Invoker::callFunction(UInt32 RTMFPcontext, const char* function, int nbArgs
780787

781788
int Invoker::write(unsigned int RTMFPcontext, const UInt8* data, UInt32 size) {
782789

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;
794793

795794
// Find the writing buffer for current session
796795
lock_guard<mutex> lock(_mutexWrite);

0 commit comments

Comments
 (0)