winlin

refine the colorful log for srs. remove the log when client close.

@@ -197,7 +197,9 @@ int SrsClient::service_cycle() @@ -197,7 +197,9 @@ int SrsClient::service_cycle()
197 197
198 // when not system control error, fatal error, return. 198 // when not system control error, fatal error, return.
199 if (!srs_is_system_control_error(ret)) { 199 if (!srs_is_system_control_error(ret)) {
200 - srs_error("stream service cycle failed. ret=%d", ret); 200 + if (ret != ERROR_SOCKET_TIMEOUT && !srs_is_client_gracefully_close(ret)) {
  201 + srs_error("stream service cycle failed. ret=%d", ret);
  202 + }
201 return ret; 203 return ret;
202 } 204 }
203 205
@@ -409,7 +411,9 @@ int SrsClient::playing(SrsSource* source) @@ -409,7 +411,9 @@ int SrsClient::playing(SrsSource* source)
409 411
410 srs_verbose("play loop recv message. ret=%d", ret); 412 srs_verbose("play loop recv message. ret=%d", ret);
411 if (ret != ERROR_SUCCESS && ret != ERROR_SOCKET_TIMEOUT) { 413 if (ret != ERROR_SUCCESS && ret != ERROR_SOCKET_TIMEOUT) {
412 - srs_error("recv client control message failed. ret=%d", ret); 414 + if (ret != ERROR_SOCKET_TIMEOUT && !srs_is_client_gracefully_close(ret)) {
  415 + srs_error("recv client control message failed. ret=%d", ret);
  416 + }
413 return ret; 417 return ret;
414 } 418 }
415 if ((ret = process_play_control_msg(consumer, msg)) != ERROR_SUCCESS) { 419 if ((ret = process_play_control_msg(consumer, msg)) != ERROR_SUCCESS) {
@@ -63,7 +63,7 @@ void SrsConnection::cycle() @@ -63,7 +63,7 @@ void SrsConnection::cycle()
63 ret = do_cycle(); 63 ret = do_cycle();
64 64
65 // if socket io error, set to closed. 65 // if socket io error, set to closed.
66 - if (ret == ERROR_SOCKET_READ || ret == ERROR_SOCKET_READ_FULLY || ret == ERROR_SOCKET_WRITE) { 66 + if (srs_is_client_gracefully_close(ret)) {
67 ret = ERROR_SOCKET_CLOSED; 67 ret = ERROR_SOCKET_CLOSED;
68 } 68 }
69 69
@@ -74,7 +74,7 @@ void SrsConnection::cycle() @@ -74,7 +74,7 @@ void SrsConnection::cycle()
74 74
75 // client close peer. 75 // client close peer.
76 if (ret == ERROR_SOCKET_CLOSED) { 76 if (ret == ERROR_SOCKET_CLOSED) {
77 - srs_trace("client disconnect peer. ret=%d", ret); 77 + srs_warn("client disconnect peer. ret=%d", ret);
78 } 78 }
79 79
80 server->remove(this); 80 server->remove(this);
@@ -218,11 +218,15 @@ void SrsFastLog::write_log(char *str_log, int size, int _level) @@ -218,11 +218,15 @@ void SrsFastLog::write_log(char *str_log, int size, int _level)
218 log_data[size++] = 0; 218 log_data[size++] = 0;
219 219
220 // if is error msg, then print color msg. 220 // if is error msg, then print color msg.
221 - // \033[1;31m : red text code in shell  
222 - // \033[1;31m : normal text code  
223 - if (_level == SrsLogLevel::Error) {  
224 - printf("\033[1;31m%s\033[0m", str_log);  
225 - } else { 221 + // \033[31m : red text code in shell
  222 + // \033[32m : green text code in shell
  223 + // \033[33m : yellow text code in shell
  224 + // \033[0m : normal text code
  225 + if (_level <= SrsLogLevel::Trace) {
226 printf("%s", str_log); 226 printf("%s", str_log);
  227 + } else if (_level == SrsLogLevel::Warn) {
  228 + printf("\033[33m%s\033[0m", str_log);
  229 + } else{
  230 + printf("\033[31m%s\033[0m", str_log);
227 } 231 }
228 } 232 }
@@ -29,3 +29,9 @@ bool srs_is_system_control_error(int error_code) @@ -29,3 +29,9 @@ bool srs_is_system_control_error(int error_code)
29 || error_code == ERROR_CONTROL_REPUBLISH; 29 || error_code == ERROR_CONTROL_REPUBLISH;
30 } 30 }
31 31
  32 +bool srs_is_client_gracefully_close(int error_code)
  33 +{
  34 + return error_code == ERROR_SOCKET_READ
  35 + || error_code == ERROR_SOCKET_READ_FULLY
  36 + || error_code == ERROR_SOCKET_WRITE;
  37 +}
@@ -162,5 +162,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -162,5 +162,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
162 * whether the error code is an system control error. 162 * whether the error code is an system control error.
163 */ 163 */
164 extern bool srs_is_system_control_error(int error_code); 164 extern bool srs_is_system_control_error(int error_code);
  165 +extern bool srs_is_client_gracefully_close(int error_code);
165 166
166 #endif 167 #endif
@@ -371,7 +371,7 @@ int SrsProtocol::recv_message(SrsCommonMessage** pmsg) @@ -371,7 +371,7 @@ int SrsProtocol::recv_message(SrsCommonMessage** pmsg)
371 SrsCommonMessage* msg = NULL; 371 SrsCommonMessage* msg = NULL;
372 372
373 if ((ret = recv_interlaced_message(&msg)) != ERROR_SUCCESS) { 373 if ((ret = recv_interlaced_message(&msg)) != ERROR_SUCCESS) {
374 - if (ret != ERROR_SOCKET_TIMEOUT) { 374 + if (ret != ERROR_SOCKET_TIMEOUT && !srs_is_client_gracefully_close(ret)) {
375 srs_error("recv interlaced message failed. ret=%d", ret); 375 srs_error("recv interlaced message failed. ret=%d", ret);
376 } 376 }
377 return ret; 377 return ret;
@@ -712,7 +712,7 @@ int SrsProtocol::recv_interlaced_message(SrsCommonMessage** pmsg) @@ -712,7 +712,7 @@ int SrsProtocol::recv_interlaced_message(SrsCommonMessage** pmsg)
712 int cid = 0; 712 int cid = 0;
713 int bh_size = 0; 713 int bh_size = 0;
714 if ((ret = read_basic_header(fmt, cid, bh_size)) != ERROR_SUCCESS) { 714 if ((ret = read_basic_header(fmt, cid, bh_size)) != ERROR_SUCCESS) {
715 - if (ret != ERROR_SOCKET_TIMEOUT) { 715 + if (ret != ERROR_SOCKET_TIMEOUT && !srs_is_client_gracefully_close(ret)) {
716 srs_error("read basic header failed. ret=%d", ret); 716 srs_error("read basic header failed. ret=%d", ret);
717 } 717 }
718 return ret; 718 return ret;
@@ -749,7 +749,7 @@ int SrsProtocol::recv_interlaced_message(SrsCommonMessage** pmsg) @@ -749,7 +749,7 @@ int SrsProtocol::recv_interlaced_message(SrsCommonMessage** pmsg)
749 // chunk stream message header 749 // chunk stream message header
750 int mh_size = 0; 750 int mh_size = 0;
751 if ((ret = read_message_header(chunk, fmt, bh_size, mh_size)) != ERROR_SUCCESS) { 751 if ((ret = read_message_header(chunk, fmt, bh_size, mh_size)) != ERROR_SUCCESS) {
752 - if (ret != ERROR_SOCKET_TIMEOUT) { 752 + if (ret != ERROR_SOCKET_TIMEOUT && !srs_is_client_gracefully_close(ret)) {
753 srs_error("read message header failed. ret=%d", ret); 753 srs_error("read message header failed. ret=%d", ret);
754 } 754 }
755 return ret; 755 return ret;
@@ -763,7 +763,7 @@ int SrsProtocol::recv_interlaced_message(SrsCommonMessage** pmsg) @@ -763,7 +763,7 @@ int SrsProtocol::recv_interlaced_message(SrsCommonMessage** pmsg)
763 SrsCommonMessage* msg = NULL; 763 SrsCommonMessage* msg = NULL;
764 int payload_size = 0; 764 int payload_size = 0;
765 if ((ret = read_message_payload(chunk, bh_size, mh_size, payload_size, &msg)) != ERROR_SUCCESS) { 765 if ((ret = read_message_payload(chunk, bh_size, mh_size, payload_size, &msg)) != ERROR_SUCCESS) {
766 - if (ret != ERROR_SOCKET_TIMEOUT) { 766 + if (ret != ERROR_SOCKET_TIMEOUT && !srs_is_client_gracefully_close(ret)) {
767 srs_error("read message payload failed. ret=%d", ret); 767 srs_error("read message payload failed. ret=%d", ret);
768 } 768 }
769 return ret; 769 return ret;
@@ -797,7 +797,7 @@ int SrsProtocol::read_basic_header(char& fmt, int& cid, int& bh_size) @@ -797,7 +797,7 @@ int SrsProtocol::read_basic_header(char& fmt, int& cid, int& bh_size)
797 797
798 int required_size = 1; 798 int required_size = 1;
799 if ((ret = buffer->ensure_buffer_bytes(skt, required_size)) != ERROR_SUCCESS) { 799 if ((ret = buffer->ensure_buffer_bytes(skt, required_size)) != ERROR_SUCCESS) {
800 - if (ret != ERROR_SOCKET_TIMEOUT) { 800 + if (ret != ERROR_SOCKET_TIMEOUT && !srs_is_client_gracefully_close(ret)) {
801 srs_error("read 1bytes basic header failed. required_size=%d, ret=%d", required_size, ret); 801 srs_error("read 1bytes basic header failed. required_size=%d, ret=%d", required_size, ret);
802 } 802 }
803 return ret; 803 return ret;
@@ -817,7 +817,7 @@ int SrsProtocol::read_basic_header(char& fmt, int& cid, int& bh_size) @@ -817,7 +817,7 @@ int SrsProtocol::read_basic_header(char& fmt, int& cid, int& bh_size)
817 if (cid == 0) { 817 if (cid == 0) {
818 required_size = 2; 818 required_size = 2;
819 if ((ret = buffer->ensure_buffer_bytes(skt, required_size)) != ERROR_SUCCESS) { 819 if ((ret = buffer->ensure_buffer_bytes(skt, required_size)) != ERROR_SUCCESS) {
820 - if (ret != ERROR_SOCKET_TIMEOUT) { 820 + if (ret != ERROR_SOCKET_TIMEOUT && !srs_is_client_gracefully_close(ret)) {
821 srs_error("read 2bytes basic header failed. required_size=%d, ret=%d", required_size, ret); 821 srs_error("read 2bytes basic header failed. required_size=%d, ret=%d", required_size, ret);
822 } 822 }
823 return ret; 823 return ret;
@@ -830,7 +830,7 @@ int SrsProtocol::read_basic_header(char& fmt, int& cid, int& bh_size) @@ -830,7 +830,7 @@ int SrsProtocol::read_basic_header(char& fmt, int& cid, int& bh_size)
830 } else if (cid == 1) { 830 } else if (cid == 1) {
831 required_size = 3; 831 required_size = 3;
832 if ((ret = buffer->ensure_buffer_bytes(skt, 3)) != ERROR_SUCCESS) { 832 if ((ret = buffer->ensure_buffer_bytes(skt, 3)) != ERROR_SUCCESS) {
833 - if (ret != ERROR_SOCKET_TIMEOUT) { 833 + if (ret != ERROR_SOCKET_TIMEOUT && !srs_is_client_gracefully_close(ret)) {
834 srs_error("read 3bytes basic header failed. required_size=%d, ret=%d", required_size, ret); 834 srs_error("read 3bytes basic header failed. required_size=%d, ret=%d", required_size, ret);
835 } 835 }
836 return ret; 836 return ret;
@@ -908,7 +908,7 @@ int SrsProtocol::read_message_header(SrsChunkStream* chunk, char fmt, int bh_siz @@ -908,7 +908,7 @@ int SrsProtocol::read_message_header(SrsChunkStream* chunk, char fmt, int bh_siz
908 908
909 int required_size = bh_size + mh_size; 909 int required_size = bh_size + mh_size;
910 if ((ret = buffer->ensure_buffer_bytes(skt, required_size)) != ERROR_SUCCESS) { 910 if ((ret = buffer->ensure_buffer_bytes(skt, required_size)) != ERROR_SUCCESS) {
911 - if (ret != ERROR_SOCKET_TIMEOUT) { 911 + if (ret != ERROR_SOCKET_TIMEOUT && !srs_is_client_gracefully_close(ret)) {
912 srs_error("read %dbytes message header failed. required_size=%d, ret=%d", mh_size, required_size, ret); 912 srs_error("read %dbytes message header failed. required_size=%d, ret=%d", mh_size, required_size, ret);
913 } 913 }
914 return ret; 914 return ret;
@@ -1017,7 +1017,7 @@ int SrsProtocol::read_message_header(SrsChunkStream* chunk, char fmt, int bh_siz @@ -1017,7 +1017,7 @@ int SrsProtocol::read_message_header(SrsChunkStream* chunk, char fmt, int bh_siz
1017 required_size = bh_size + mh_size; 1017 required_size = bh_size + mh_size;
1018 srs_verbose("read header ext time. fmt=%d, ext_time=%d, mh_size=%d", fmt, chunk->extended_timestamp, mh_size); 1018 srs_verbose("read header ext time. fmt=%d, ext_time=%d, mh_size=%d", fmt, chunk->extended_timestamp, mh_size);
1019 if ((ret = buffer->ensure_buffer_bytes(skt, required_size)) != ERROR_SUCCESS) { 1019 if ((ret = buffer->ensure_buffer_bytes(skt, required_size)) != ERROR_SUCCESS) {
1020 - if (ret != ERROR_SOCKET_TIMEOUT) { 1020 + if (ret != ERROR_SOCKET_TIMEOUT && !srs_is_client_gracefully_close(ret)) {
1021 srs_error("read %dbytes message header failed. required_size=%d, ret=%d", mh_size, required_size, ret); 1021 srs_error("read %dbytes message header failed. required_size=%d, ret=%d", mh_size, required_size, ret);
1022 } 1022 }
1023 return ret; 1023 return ret;
@@ -1119,7 +1119,7 @@ int SrsProtocol::read_message_payload(SrsChunkStream* chunk, int bh_size, int mh @@ -1119,7 +1119,7 @@ int SrsProtocol::read_message_payload(SrsChunkStream* chunk, int bh_size, int mh
1119 // read payload to buffer 1119 // read payload to buffer
1120 int required_size = bh_size + mh_size + payload_size; 1120 int required_size = bh_size + mh_size + payload_size;
1121 if ((ret = buffer->ensure_buffer_bytes(skt, required_size)) != ERROR_SUCCESS) { 1121 if ((ret = buffer->ensure_buffer_bytes(skt, required_size)) != ERROR_SUCCESS) {
1122 - if (ret != ERROR_SOCKET_TIMEOUT) { 1122 + if (ret != ERROR_SOCKET_TIMEOUT && !srs_is_client_gracefully_close(ret)) {
1123 srs_error("read payload failed. required_size=%d, ret=%d", required_size, ret); 1123 srs_error("read payload failed. required_size=%d, ret=%d", required_size, ret);
1124 } 1124 }
1125 return ret; 1125 return ret;