Skip to content

Commit

Permalink
Threads-Hybrid: Process api request one by one
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Apr 26, 2021
1 parent 963a0fa commit 11aada1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
24 changes: 16 additions & 8 deletions trunk/src/app/srs_app_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1650,6 +1650,7 @@ SrsApiServer::SrsApiServer()
http_ = new SrsBufferListener(this, SrsListenerHttpApi);
https_ = new SrsBufferListener(this, SrsListenerHttpApi);
conn_manager_ = new SrsResourceManager("api");
lock_ = srs_mutex_new();
}

SrsApiServer::~SrsApiServer()
Expand All @@ -1658,6 +1659,7 @@ SrsApiServer::~SrsApiServer()
srs_freep(http_);
srs_freep(https_);
srs_freep(conn_manager_);
srs_mutex_destroy(lock_);
}

srs_error_t SrsApiServer::initialize()
Expand Down Expand Up @@ -1973,15 +1975,21 @@ srs_error_t SrsApiServer::create_session(
m.id = (uint64_t)SrsThreadMessageIDRtcCreateSession;
m.ptr = (uint64_t)&s;

// We're initiator, write to initiator, read from responder.
// TODO: FIXME: Write important logs, and error response, and timeout?
if ((err = channel->initiator()->write(&m, sizeof(m), NULL)) != srs_success) {
return srs_error_wrap(err, "write");
}
if (true) {
// Process api request one by one.
// TODO: FIXME: The lock too big? Write log and error?
SrsLocker(lock_);

// We're initiator, write to initiator, read from responder.
// TODO: FIXME: Write important logs, and error response, and timeout?
if ((err = channel->initiator()->write(&m, sizeof(m), NULL)) != srs_success) {
return srs_error_wrap(err, "write");
}

// TODO: FIXME: Write important logs, and error response, and timeout?
if ((err = channel->responder()->read(&m, sizeof(m), NULL)) != srs_success) {
return srs_error_wrap(err, "read");
// TODO: FIXME: Write important logs, and error response, and timeout?
if ((err = channel->responder()->read(&m, sizeof(m), NULL)) != srs_success) {
return srs_error_wrap(err, "read");
}
}

// Covert to output params.
Expand Down
3 changes: 3 additions & 0 deletions trunk/src/app/srs_app_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,9 @@ class SrsApiServer : public ISrsTcpMuxHandler, public ISrsResourceManager, publi
private:
// Key is stream url, value is hybrid thread entry.
std::map<std::string, SrsThreadEntry*> hybrids_;
private:
// To process api request one by one.
srs_mutex_t lock_;
public:
SrsApiServer();
virtual ~SrsApiServer();
Expand Down

0 comments on commit 11aada1

Please sign in to comment.