/** * 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; } } }
void on_tcp_client_connect_cb(uv_connect_t* req, int status) { client_connect_req_t *creq = (client_connect_req_t*) req->data; if (creq->cb != NULL) { creq->cb(creq->client, status); } else { CL_WARN("no connect cb.\n"); } FREE(creq); }
/** * 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 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; }