winlin

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

... ... @@ -197,7 +197,9 @@ int SrsClient::service_cycle()
// when not system control error, fatal error, return.
if (!srs_is_system_control_error(ret)) {
if (ret != ERROR_SOCKET_TIMEOUT && !srs_is_client_gracefully_close(ret)) {
srs_error("stream service cycle failed. ret=%d", ret);
}
return ret;
}
... ... @@ -409,7 +411,9 @@ int SrsClient::playing(SrsSource* source)
srs_verbose("play loop recv message. ret=%d", ret);
if (ret != ERROR_SUCCESS && ret != ERROR_SOCKET_TIMEOUT) {
if (ret != ERROR_SOCKET_TIMEOUT && !srs_is_client_gracefully_close(ret)) {
srs_error("recv client control message failed. ret=%d", ret);
}
return ret;
}
if ((ret = process_play_control_msg(consumer, msg)) != ERROR_SUCCESS) {
... ...
... ... @@ -63,7 +63,7 @@ void SrsConnection::cycle()
ret = do_cycle();
// if socket io error, set to closed.
if (ret == ERROR_SOCKET_READ || ret == ERROR_SOCKET_READ_FULLY || ret == ERROR_SOCKET_WRITE) {
if (srs_is_client_gracefully_close(ret)) {
ret = ERROR_SOCKET_CLOSED;
}
... ... @@ -74,7 +74,7 @@ void SrsConnection::cycle()
// client close peer.
if (ret == ERROR_SOCKET_CLOSED) {
srs_trace("client disconnect peer. ret=%d", ret);
srs_warn("client disconnect peer. ret=%d", ret);
}
server->remove(this);
... ...
... ... @@ -218,11 +218,15 @@ void SrsFastLog::write_log(char *str_log, int size, int _level)
log_data[size++] = 0;
// if is error msg, then print color msg.
// \033[1;31m : red text code in shell
// \033[1;31m : normal text code
if (_level == SrsLogLevel::Error) {
printf("\033[1;31m%s\033[0m", str_log);
} else {
// \033[31m : red text code in shell
// \033[32m : green text code in shell
// \033[33m : yellow text code in shell
// \033[0m : normal text code
if (_level <= SrsLogLevel::Trace) {
printf("%s", str_log);
} else if (_level == SrsLogLevel::Warn) {
printf("\033[33m%s\033[0m", str_log);
} else{
printf("\033[31m%s\033[0m", str_log);
}
}
... ...
... ... @@ -29,3 +29,9 @@ bool srs_is_system_control_error(int error_code)
|| error_code == ERROR_CONTROL_REPUBLISH;
}
bool srs_is_client_gracefully_close(int error_code)
{
return error_code == ERROR_SOCKET_READ
|| error_code == ERROR_SOCKET_READ_FULLY
|| error_code == ERROR_SOCKET_WRITE;
}
... ...
... ... @@ -162,5 +162,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* whether the error code is an system control error.
*/
extern bool srs_is_system_control_error(int error_code);
extern bool srs_is_client_gracefully_close(int error_code);
#endif
... ...
... ... @@ -371,7 +371,7 @@ int SrsProtocol::recv_message(SrsCommonMessage** pmsg)
SrsCommonMessage* msg = NULL;
if ((ret = recv_interlaced_message(&msg)) != ERROR_SUCCESS) {
if (ret != ERROR_SOCKET_TIMEOUT) {
if (ret != ERROR_SOCKET_TIMEOUT && !srs_is_client_gracefully_close(ret)) {
srs_error("recv interlaced message failed. ret=%d", ret);
}
return ret;
... ... @@ -712,7 +712,7 @@ int SrsProtocol::recv_interlaced_message(SrsCommonMessage** pmsg)
int cid = 0;
int bh_size = 0;
if ((ret = read_basic_header(fmt, cid, bh_size)) != ERROR_SUCCESS) {
if (ret != ERROR_SOCKET_TIMEOUT) {
if (ret != ERROR_SOCKET_TIMEOUT && !srs_is_client_gracefully_close(ret)) {
srs_error("read basic header failed. ret=%d", ret);
}
return ret;
... ... @@ -749,7 +749,7 @@ int SrsProtocol::recv_interlaced_message(SrsCommonMessage** pmsg)
// chunk stream message header
int mh_size = 0;
if ((ret = read_message_header(chunk, fmt, bh_size, mh_size)) != ERROR_SUCCESS) {
if (ret != ERROR_SOCKET_TIMEOUT) {
if (ret != ERROR_SOCKET_TIMEOUT && !srs_is_client_gracefully_close(ret)) {
srs_error("read message header failed. ret=%d", ret);
}
return ret;
... ... @@ -763,7 +763,7 @@ int SrsProtocol::recv_interlaced_message(SrsCommonMessage** pmsg)
SrsCommonMessage* msg = NULL;
int payload_size = 0;
if ((ret = read_message_payload(chunk, bh_size, mh_size, payload_size, &msg)) != ERROR_SUCCESS) {
if (ret != ERROR_SOCKET_TIMEOUT) {
if (ret != ERROR_SOCKET_TIMEOUT && !srs_is_client_gracefully_close(ret)) {
srs_error("read message payload failed. ret=%d", ret);
}
return ret;
... ... @@ -797,7 +797,7 @@ int SrsProtocol::read_basic_header(char& fmt, int& cid, int& bh_size)
int required_size = 1;
if ((ret = buffer->ensure_buffer_bytes(skt, required_size)) != ERROR_SUCCESS) {
if (ret != ERROR_SOCKET_TIMEOUT) {
if (ret != ERROR_SOCKET_TIMEOUT && !srs_is_client_gracefully_close(ret)) {
srs_error("read 1bytes basic header failed. required_size=%d, ret=%d", required_size, ret);
}
return ret;
... ... @@ -817,7 +817,7 @@ int SrsProtocol::read_basic_header(char& fmt, int& cid, int& bh_size)
if (cid == 0) {
required_size = 2;
if ((ret = buffer->ensure_buffer_bytes(skt, required_size)) != ERROR_SUCCESS) {
if (ret != ERROR_SOCKET_TIMEOUT) {
if (ret != ERROR_SOCKET_TIMEOUT && !srs_is_client_gracefully_close(ret)) {
srs_error("read 2bytes basic header failed. required_size=%d, ret=%d", required_size, ret);
}
return ret;
... ... @@ -830,7 +830,7 @@ int SrsProtocol::read_basic_header(char& fmt, int& cid, int& bh_size)
} else if (cid == 1) {
required_size = 3;
if ((ret = buffer->ensure_buffer_bytes(skt, 3)) != ERROR_SUCCESS) {
if (ret != ERROR_SOCKET_TIMEOUT) {
if (ret != ERROR_SOCKET_TIMEOUT && !srs_is_client_gracefully_close(ret)) {
srs_error("read 3bytes basic header failed. required_size=%d, ret=%d", required_size, ret);
}
return ret;
... ... @@ -908,7 +908,7 @@ int SrsProtocol::read_message_header(SrsChunkStream* chunk, char fmt, int bh_siz
int required_size = bh_size + mh_size;
if ((ret = buffer->ensure_buffer_bytes(skt, required_size)) != ERROR_SUCCESS) {
if (ret != ERROR_SOCKET_TIMEOUT) {
if (ret != ERROR_SOCKET_TIMEOUT && !srs_is_client_gracefully_close(ret)) {
srs_error("read %dbytes message header failed. required_size=%d, ret=%d", mh_size, required_size, ret);
}
return ret;
... ... @@ -1017,7 +1017,7 @@ int SrsProtocol::read_message_header(SrsChunkStream* chunk, char fmt, int bh_siz
required_size = bh_size + mh_size;
srs_verbose("read header ext time. fmt=%d, ext_time=%d, mh_size=%d", fmt, chunk->extended_timestamp, mh_size);
if ((ret = buffer->ensure_buffer_bytes(skt, required_size)) != ERROR_SUCCESS) {
if (ret != ERROR_SOCKET_TIMEOUT) {
if (ret != ERROR_SOCKET_TIMEOUT && !srs_is_client_gracefully_close(ret)) {
srs_error("read %dbytes message header failed. required_size=%d, ret=%d", mh_size, required_size, ret);
}
return ret;
... ... @@ -1119,7 +1119,7 @@ int SrsProtocol::read_message_payload(SrsChunkStream* chunk, int bh_size, int mh
// read payload to buffer
int required_size = bh_size + mh_size + payload_size;
if ((ret = buffer->ensure_buffer_bytes(skt, required_size)) != ERROR_SUCCESS) {
if (ret != ERROR_SOCKET_TIMEOUT) {
if (ret != ERROR_SOCKET_TIMEOUT && !srs_is_client_gracefully_close(ret)) {
srs_error("read payload failed. required_size=%d, ret=%d", required_size, ret);
}
return ret;
... ...