RTC: Use isolate cid for UDP mux listener

pull/1908/head
winlin 5 years ago
parent d2984ea49c
commit 03105c96c2

@ -416,6 +416,7 @@ SrsUdpMuxListener::SrsUdpMuxListener(ISrsUdpMuxHandler* h, std::string i, int p)
buf = new char[nb_buf]; buf = new char[nb_buf];
trd = new SrsDummyCoroutine(); trd = new SrsDummyCoroutine();
cid = _srs_context->generate_id();
} }
SrsUdpMuxListener::~SrsUdpMuxListener() SrsUdpMuxListener::~SrsUdpMuxListener()
@ -443,10 +444,8 @@ srs_error_t SrsUdpMuxListener::listen()
return srs_error_wrap(err, "listen %s:%d", ip.c_str(), port); return srs_error_wrap(err, "listen %s:%d", ip.c_str(), port);
} }
set_socket_buffer();
srs_freep(trd); srs_freep(trd);
trd = new SrsSTCoroutine("udp", this); trd = new SrsSTCoroutine("udp", this, cid);
if ((err = trd->start()) != srs_success) { if ((err = trd->start()) != srs_success) {
return srs_error_wrap(err, "start thread"); return srs_error_wrap(err, "start thread");
} }
@ -507,6 +506,8 @@ srs_error_t SrsUdpMuxListener::cycle()
uint64_t nn_loop = 0; uint64_t nn_loop = 0;
srs_utime_t time_last = srs_get_system_time(); srs_utime_t time_last = srs_get_system_time();
set_socket_buffer();
while (true) { while (true) {
if ((err = trd->pull()) != srs_success) { if ((err = trd->pull()) != srs_success) {
return srs_error_wrap(err, "udp listener"); return srs_error_wrap(err, "udp listener");
@ -532,7 +533,12 @@ srs_error_t SrsUdpMuxListener::cycle()
nn_msgs++; nn_msgs++;
nn_msgs_stage++; nn_msgs_stage++;
if ((err = handler->on_udp_packet(&skt)) != srs_success) { // Restore context when packets processed.
if (true) {
SrsContextRestore(cid);
err = handler->on_udp_packet(&skt);
}
if (err != srs_success) {
// remux udp never return // remux udp never return
srs_warn("udp packet handler error:%s", srs_error_desc(err).c_str()); srs_warn("udp packet handler error:%s", srs_error_desc(err).c_str());
srs_error_reset(err); srs_error_reset(err);

@ -163,13 +163,14 @@ public:
class SrsUdpMuxListener : public ISrsCoroutineHandler class SrsUdpMuxListener : public ISrsCoroutineHandler
{ {
protected: private:
srs_netfd_t lfd; srs_netfd_t lfd;
SrsCoroutine* trd; SrsCoroutine* trd;
protected: SrsContextId cid;
private:
char* buf; char* buf;
int nb_buf; int nb_buf;
protected: private:
ISrsUdpMuxHandler* handler; ISrsUdpMuxHandler* handler;
std::string ip; std::string ip;
int port; int port;

Loading…
Cancel
Save