int start_mock_dvr(smts_tcp_server_t *tcp_server, uv_loop_t *loop, int port) { int r = 0; r = init_tcp_server(tcp_server, loop, port); r = start_tcp_server(tcp_server, NULL, on_mock_dvr_connect_cb); CL_INFO("start mock dvr on port:%d.\n", port); return r; }
/** * inherit from {@link tcp_client_connect_cb} */ static void mock_dvr_close_cb(abstract_tcp_client_t *aclient, int status) { test_mock_dvr_t *dvr = (test_mock_dvr_t*) aclient; FREE(dvr->iframe_bin.base); FREE(dvr->frame_bin.base); FREE(aclient); CL_INFO("mock dvr stop.\n"); }
/** * will just printf to console log when uv_loop is not run. */ void test_css_logger_console_log() { // test log. CL_DEBUG("test logger %s %d.\n", __FUNCTION__, 1); CL_DEBUG("test logger \n"); css_logger_set_level(2); CL_DEBUG("test logger %s %d.\n", __FUNCTION__, 2); CL_INFO("test logger %s %d.\n", __FUNCTION__, 3); CL_WARN("test logger \n"); // printf("%s %d %s.\n",strstr(__FILE__,"src"),__LINE__,__FUNCTION__); }
int stop_smts_client(smts_client_t *c, int status) { if (c != NULL) { if (c->status != SMTS_CLIENT_ON_STOP) { c->status = SMTS_CLIENT_ON_STOP; CL_INFO("stop smts_client fd:%d,status:%d.\n", c->socket.io_watcher.fd, status); if (c->session != NULL) { media_client_stop_preview(c->session, c); } close_abstract_tcp_client((abstract_tcp_client_t*) c, socket_close_cb); } } return 0; }
void css_destory_ini_file() { int i = 0, j = 0; CL_INFO("destory config file.\n"); for (; i < css_config_count; i++) { // printf("%d section : %s , keys : %d \n", i, // m_css_config[i].setctionName, m_css_config[i].keyCount); for (j = 0; j < m_css_config[i].keyCount; j++) { // printf("%d.%d %s : %s \n", i, j, m_css_config[i].config[j].keyName, // m_css_config[i].config[j].value); FREE(m_css_config[i].config[j].keyName); FREE(m_css_config[i].config[j].value); } FREE(m_css_config[i].setctionName); FREE(m_css_config[i].config); } FREE(m_css_config); }
/** * inherit from {@link uv_read_cb} */ static void tcp_client_read_cb(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) { abstract_tcp_client_t *c = (abstract_tcp_client_t*) stream->data; client_read_tmp_buf_t *packet = &c->recv_tmp_buf; // CL_DEBUG("read frame: %ld bytes.\n", nread); if (packet->packet_len == PACKET_INVALID) { CL_ERROR("read packet error.\n"); c->read_packet_cb(c, NULL, DVR_RECV_INVALID_PACKET_ERROR); return; } if (nread < 0) { CL_INFO("fd:%d read cmd data error:%ld,%s\n", c->socket.io_watcher.fd, nread, smts_strerror(nread)); // CL_INFO("fd:%d alloc:%d recv:%d\n", c->socket.io_watcher.fd, packet->offset, packet->packet_len); FREE(packet->buf.base); init_client_read_tmp_buf(packet); if (c->read_packet_cb != NULL) { c->read_packet_cb(c, NULL, nread); } else { CL_WARN("no read packet cb impl when error!.\n"); } return; } if (nread > 0) { if (((nread + packet->offset) == packet->packet_len) && packet->packet_len > PACKET_LEN_FIELD_SIZE) { //read body completed. packet->offset += nread; // CL_DEBUG("read packet:%d\n", packet->offset); if (c->read_packet_cb != NULL) { // warnning: should take care of packet.buf.base buffer in read_pack_cb. c->read_packet_cb(c, &packet->buf, 0); } else { CL_WARN("no read packet cb impl.\n"); FREE(packet->buf.base); } init_client_read_tmp_buf(packet); } else { //continue read. packet->offset += nread; } } }
int tcp_client_read_stop(abstract_tcp_client_t *client) { CL_INFO("stop read of client:%d\n", client->socket.io_watcher.fd); return uv_read_stop((uv_stream_t*) &client->socket); }
int css_load_ini_file(const char* file_path) { FILE* config_file = NULL; int i = 0, secCount = -1, keyCount = 0; char* line = NULL; int sec_tag = 0; css_config_env* m_env; CL_INFO("start loading config file : %s \n", file_path); if ((config_file = fopen(file_path, "r")) == NULL) { CL_ERROR("config file : %s not found!! \n", file_path); return -1; } m_css_config = (css_config*) malloc(MAX_SECMENT_LEN * sizeof(css_config)); memset(m_css_config, 0, MAX_SECMENT_LEN * sizeof(css_config)); while (EOF != readLine(config_file, &line)) { str_trim(line); if (line != NULL && strlen(line) > 0) { if (is_annotate_line(line)) { //nothing to do,ignore. } else if (is_segment_line(line)) { if (sec_tag == 1) { // printf("%d.%d\n", secCount, keyCount); // realloc(m_css_config[secCount].config, // keyCount * sizeof(css_config_env)); // assert(m_css_config[secCount].config!=NULL); m_css_config[secCount].keyCount = keyCount; sec_tag = 0; } secCount++; get_section_name(line, &(m_css_config[secCount].setctionName)); // printf("%d.%s\n",secCount,m_css_config[secCount].setctionName); m_css_config[secCount].config = (css_config_env*) malloc( MAX_KEY_VALUE_OF_SECMENT * sizeof(css_config_env)); memset(m_css_config[secCount].config, 0, MAX_KEY_VALUE_OF_SECMENT * sizeof(css_config_env)); sec_tag = 1; keyCount = 0; } else if (is_keyvalue_line(line)) { m_env = &(m_css_config[secCount].config[keyCount]); get_key_value(line, &(m_env->keyName), &(m_env->value)); // printf("%d.%d %s:%s\n",secCount,keyCount,m_env->keyName,m_env->value); keyCount++; } else { CL_WARN("read unkown line : %s\n", line); } } FREE(line); } if (sec_tag == 1) { // printf("%d.%d\n", secCount, keyCount); // realloc(m_css_config[secCount].config, // keyCount * sizeof(css_config_env)); m_css_config[secCount].keyCount = keyCount; sec_tag = 0; } secCount++; css_config_count = secCount; CL_DEBUG("total read %d sections of config file : %s.\n", secCount, file_path); return 0; }