for bug #237, refine the thread loop for publish thread. 2.0.47
正在显示
2 个修改的文件
包含
30 行增加
和
32 行删除
| @@ -66,29 +66,35 @@ int SrsRecvThread::cycle() | @@ -66,29 +66,35 @@ int SrsRecvThread::cycle() | ||
| 66 | { | 66 | { |
| 67 | int ret = ERROR_SUCCESS; | 67 | int ret = ERROR_SUCCESS; |
| 68 | 68 | ||
| 69 | - if (!handler->can_handle()) { | ||
| 70 | - st_usleep(timeout * 1000); | ||
| 71 | - return ret; | ||
| 72 | - } | ||
| 73 | - | ||
| 74 | - SrsMessage* msg = NULL; | ||
| 75 | - | ||
| 76 | - if ((ret = rtmp->recv_message(&msg)) != ERROR_SUCCESS) { | ||
| 77 | - if (!srs_is_client_gracefully_close(ret)) { | ||
| 78 | - srs_error("recv client control message failed. ret=%d", ret); | 69 | + while (trd->can_loop()) { |
| 70 | + if (!handler->can_handle()) { | ||
| 71 | + st_usleep(timeout * 1000); | ||
| 72 | + continue; | ||
| 79 | } | 73 | } |
| 80 | - | ||
| 81 | - // we use no timeout to recv, should never got any error. | ||
| 82 | - trd->stop_loop(); | 74 | + |
| 75 | + SrsMessage* msg = NULL; | ||
| 83 | 76 | ||
| 84 | - // notice the handler got a recv error. | ||
| 85 | - handler->on_recv_error(ret); | ||
| 86 | - | ||
| 87 | - return ret; | 77 | + // recv and handle message |
| 78 | + ret = rtmp->recv_message(&msg); | ||
| 79 | + if (ret == ERROR_SUCCESS) { | ||
| 80 | + ret = handler->handle(msg); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + if (ret != ERROR_SUCCESS) { | ||
| 84 | + if (!srs_is_client_gracefully_close(ret)) { | ||
| 85 | + srs_error("thread process message failed. ret=%d", ret); | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + // we use no timeout to recv, should never got any error. | ||
| 89 | + trd->stop_loop(); | ||
| 90 | + | ||
| 91 | + // notice the handler got a recv error. | ||
| 92 | + handler->on_recv_error(ret); | ||
| 93 | + | ||
| 94 | + return ret; | ||
| 95 | + } | ||
| 96 | + srs_verbose("thread loop recv message. ret=%d", ret); | ||
| 88 | } | 97 | } |
| 89 | - srs_verbose("play loop recv message. ret=%d", ret); | ||
| 90 | - | ||
| 91 | - handler->handle(msg); | ||
| 92 | 98 | ||
| 93 | return ret; | 99 | return ret; |
| 94 | } | 100 | } |
| @@ -263,21 +269,13 @@ int SrsPublishRecvThread::handle(SrsMessage* msg) | @@ -263,21 +269,13 @@ int SrsPublishRecvThread::handle(SrsMessage* msg) | ||
| 263 | 269 | ||
| 264 | _nb_msgs++; | 270 | _nb_msgs++; |
| 265 | 271 | ||
| 266 | - // the rtmp connection will handle this message, | ||
| 267 | - // quit the thread loop when error. | ||
| 268 | - recv_error_code = ret = _conn->handle_publish_message(_source, msg, _is_fmle, _is_edge); | ||
| 269 | - | ||
| 270 | - // when error, use stop loop to terminate the thread normally, | ||
| 271 | - // for we are in the thread loop now, and should never use stop() to terminate it. | ||
| 272 | - if (ret != ERROR_SUCCESS) { | ||
| 273 | - trd.stop_loop(); | ||
| 274 | - } | 272 | + // the rtmp connection will handle this message |
| 273 | + ret = _conn->handle_publish_message(_source, msg, _is_fmle, _is_edge); | ||
| 275 | 274 | ||
| 276 | // must always free it, | 275 | // must always free it, |
| 277 | // the source will copy it if need to use. | 276 | // the source will copy it if need to use. |
| 278 | srs_freep(msg); | 277 | srs_freep(msg); |
| 279 | - | ||
| 280 | - // TODO: FIXME: implements it. | 278 | + |
| 281 | return ret; | 279 | return ret; |
| 282 | } | 280 | } |
| 283 | 281 |
| @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 31 | // current release version | 31 | // current release version |
| 32 | #define VERSION_MAJOR 2 | 32 | #define VERSION_MAJOR 2 |
| 33 | #define VERSION_MINOR 0 | 33 | #define VERSION_MINOR 0 |
| 34 | -#define VERSION_REVISION 46 | 34 | +#define VERSION_REVISION 47 |
| 35 | // server info. | 35 | // server info. |
| 36 | #define RTMP_SIG_SRS_KEY "SRS" | 36 | #define RTMP_SIG_SRS_KEY "SRS" |
| 37 | #define RTMP_SIG_SRS_ROLE "origin/edge server" | 37 | #define RTMP_SIG_SRS_ROLE "origin/edge server" |
-
请 注册 或 登录 后发表评论