winlin

refine code for bug #217, use recv thread to set the timeout.

@@ -96,3 +96,27 @@ int SrsRecvThread::cycle() @@ -96,3 +96,27 @@ int SrsRecvThread::cycle()
96 return ret; 96 return ret;
97 } 97 }
98 98
  99 +void SrsRecvThread::on_thread_start()
  100 +{
  101 + // the multiple messages writev improve performance large,
  102 + // but the timeout recv will cause 33% sys call performance,
  103 + // to use isolate thread to recv, can improve about 33% performance.
  104 + // @see https://github.com/winlinvip/simple-rtmp-server/issues/194
  105 + // @see: https://github.com/winlinvip/simple-rtmp-server/issues/217
  106 + rtmp->set_recv_timeout(ST_UTIME_NO_TIMEOUT);
  107 +
  108 + // disable the protocol auto response,
  109 + // for the isolate recv thread should never send any messages.
  110 + rtmp->set_auto_response(false);
  111 +}
  112 +
  113 +void SrsRecvThread::on_thread_stop()
  114 +{
  115 + // enable the protocol auto response,
  116 + // for the isolate recv thread terminated.
  117 + rtmp->set_auto_response(true);
  118 +
  119 + // reset the timeout to pulse mode.
  120 + rtmp->set_recv_timeout(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US);
  121 +}
  122 +
@@ -59,6 +59,9 @@ public: @@ -59,6 +59,9 @@ public:
59 virtual int start(); 59 virtual int start();
60 virtual void stop(); 60 virtual void stop();
61 virtual int cycle(); 61 virtual int cycle();
  62 +public:
  63 + virtual void on_thread_start();
  64 + virtual void on_thread_stop();
62 }; 65 };
63 66
64 #endif 67 #endif
@@ -498,21 +498,11 @@ int SrsRtmpConn::playing(SrsSource* source) @@ -498,21 +498,11 @@ int SrsRtmpConn::playing(SrsSource* source)
498 { 498 {
499 int ret = ERROR_SUCCESS; 499 int ret = ERROR_SUCCESS;
500 500
501 - // the multiple messages writev improve performance large,  
502 - // but the timeout recv will cause 33% sys call performance,  
503 - // to use isolate thread to recv, can improve about 33% performance.  
504 - // @see https://github.com/winlinvip/simple-rtmp-server/issues/194 501 + // use isolate thread to recv,
505 // @see: https://github.com/winlinvip/simple-rtmp-server/issues/217 502 // @see: https://github.com/winlinvip/simple-rtmp-server/issues/217
506 - //rtmp->set_recv_timeout(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US);  
507 - rtmp->set_recv_timeout(ST_UTIME_NO_TIMEOUT);  
508 -  
509 - // disable the protocol auto response,  
510 - // for the isolate recv thread should never send any messages.  
511 - rtmp->set_auto_response(false); 503 + SrsRecvThread trd(rtmp);
512 504
513 - // use isolate thread to recv,  
514 // start isolate recv thread. 505 // start isolate recv thread.
515 - SrsRecvThread trd(rtmp);  
516 if ((ret = trd.start()) != ERROR_SUCCESS) { 506 if ((ret = trd.start()) != ERROR_SUCCESS) {
517 srs_error("start isolate recv thread failed. ret=%d", ret); 507 srs_error("start isolate recv thread failed. ret=%d", ret);
518 return ret; 508 return ret;
@@ -524,10 +514,6 @@ int SrsRtmpConn::playing(SrsSource* source) @@ -524,10 +514,6 @@ int SrsRtmpConn::playing(SrsSource* source)
524 // stop isolate recv thread 514 // stop isolate recv thread
525 trd.stop(); 515 trd.stop();
526 516
527 - // enable the protocol auto response,  
528 - // for the isolate recv thread terminated.  
529 - rtmp->set_auto_response(true);  
530 -  
531 return ret; 517 return ret;
532 } 518 }
533 519