int session_manage::add_session(std::string sessionid, STU_SESSION_INFO *psession ) { if (psession == NULL || m_predis_client == NULL) { return -1; } std::string key; std::string value; sessioninfo2json(value, psession); key = key+SESSION_INFO_PREFIX+sessionid; MYLOG_DEBUG("addsession, key=%s, value=%s",key.c_str(), value.c_str()); int result; result = m_predis_client->set_value(key, value); if (result == -1) { MYLOG_ERROR("failed to set sessioninfo to redis, sessionid=%s", sessionid.c_str()); return -1; } result = m_predis_client->set_expire(key); if (result == -1) { MYLOG_ERROR("failed to set expire to sessionid, sessionid=%s", sessionid.c_str()); return -1; } return 0; }
MY_NAMESPACE_BEGIN bool CHttpTranslator::translate(IProtocolParser* protocol_parser, IResponsor* request_responsor) { CHttpResponsor* responsor = (CHttpResponsor *)request_responsor; CHttpRequester* requster = (CHttpRequester *)protocol_parser; const CHttpHeader* header = requster->get_http_event()->get_http_header(); uint16_t domain_name_length; const char* domain_name = header->get_domain_name(domain_name_length); const CVirtualHost* host = CHostManager::get_singleton()->find_host(domain_name, domain_name_length); if (NULL == host) { MYLOG_ERROR("Can not find host for %.*s.\n", domain_name_length, domain_name); return false; } uint16_t url_length; char full_filename[FILENAME_MAX]; const char* url = header->get_url(url_length); int full_filename_length = host->get_full_filename(url, url_length, full_filename, sizeof(full_filename)-1); if (0 == full_filename_length) { MYLOG_ERROR("Can not find file for %.*s/%.*s.\n", domain_name_length, domain_name, url_length, url); return false; } MYLOG_DEBUG("GET %.*s:%s.\n", domain_name_length, domain_name, full_filename); responsor->set_filename(full_filename, full_filename_length); return true; }
sys::DBConnection* CConfigLoader::do_init_db_connection(int index) const { const struct DbInfo* _db_info = _db_info_array[index]; sys::DBConnection* db_connection = new sys::CMySQLConnection; if (NULL == db_connection) { MYLOG_ERROR("can not create MySQL connection by 'mysql_connection'\n"); } else { db_connection->set_host(_db_info->host, (uint16_t)_db_info->port); db_connection->set_user(_db_info->user, _db_info->password); db_connection->set_db_name(_db_info->name); db_connection->set_charset(_db_info->charset); db_connection->enable_auto_reconnect(); try { db_connection->open(); } catch (sys::CDBException& db_ex) { MYLOG_ERROR("connect %s failed: %s\n", _db_info->str().c_str(), db_ex.str().c_str()); delete db_connection; db_connection = NULL; } } return db_connection; }
void CDbProxyHandler::query(DBTable& _return, const std::string& sign, const int32_t seq, const int32_t query_index, const std::vector<std::string> & tokens, const int32_t limit, const int32_t limit_start) { CConfigLoader* config_loader = CConfigLoader::get_singleton(); struct QueryInfo query_info; if (check_token(seq, tokens)) { throw apache::thrift::TApplicationException("invalid parameter"); } if (!config_loader->get_query_info(query_index, &query_info)) { MYLOG_ERROR("query_index[%d] not exists\n", query_index); throw apache::thrift::TApplicationException("query_index not exists"); } if (sign != query_info.sign) { MYLOG_ERROR("sign[%s] error: %s\n", sign.c_str(), query_info.sign.c_str()); throw apache::thrift::TApplicationException("sign error"); } try { sys::DBConnection* db_connection = config_loader->get_db_connection(query_info.database_index); if (NULL == db_connection) { MYLOG_ERROR("database_index[%d] not exists\n", query_info.database_index); throw apache::thrift::TApplicationException("database_index not exists"); } else if (tokens.size() > utils::FORMAT_STRING_SIZE) { MYLOG_ERROR("[%d]too big: %d\n", seq, (int)tokens.size()); throw apache::thrift::TApplicationException("tokens too many"); } else { std::string sql = utils::format_string(query_info.sql_template.c_str(), tokens); MYLOG_DEBUG("%s LIMIT %d,%d\n", sql.c_str(), limit_start, limit); if (limit_start > 0) db_connection->query(_return, "%s LIMIT %d,%d", sql.c_str(), limit_start, limit); else db_connection->query(_return, "%s LIMIT %d", sql.c_str(), limit); } } catch (sys::CDBException& db_ex) { MYLOG_ERROR("[%d]%s\n", seq, db_ex.str().c_str()); throw apache::thrift::TApplicationException(db_ex.str()); } }
std::string CSqlLogger::get_log_filepath() { std::string log_filepath; MOOON_ASSERT(!_dbinfo->alias.empty()); if (_dbinfo->alias.empty()) { MYLOG_ERROR("alias empty: %s\n", _dbinfo->str().c_str()); } else { const std::string& log_dirpath = get_log_dirpath(_dbinfo->alias); if (!sys::CDirUtils::exist(log_dirpath)) { MYLOG_INFO("to create sqllog dir[%s]: %s\n", log_dirpath.c_str(), _dbinfo->str().c_str()); sys::CDirUtils::create_directory_recursive(log_dirpath.c_str(), DIRECTORY_DEFAULT_PERM); } const time_t now = time(NULL); if (now == _log_file_timestamp) { ++_log_file_suffix; } else { _log_file_suffix = 0; _log_file_timestamp = now; } log_filepath = utils::CStringUtils::format_string("%s/sql.%013" PRId64".%06d", log_dirpath.c_str(), static_cast<int64_t>(now), _log_file_suffix); } return log_filepath; }
int zmq_client::init_zmq_client( std::string ip, int port,std::string client_identity, zmq_client_callback func ) { srand(time(NULL)+(m_id_inc++)); std::string random_addr=SDUtility::format((uint64_t)random()); m_ipc_addr=m_ipc_addr+"ipc:///tmp/"+random_addr; m_router_ip = ip; m_router_port = port; if (client_identity.empty()) { uint64_t myrand =random(); std::string str_random; str_random = SDUtility::format(myrand); m_client_ientity = str_random; } else { m_client_ientity = client_identity; } if (func== NULL) { return -1; } m_callback_notify = func; pthread_t thrreadid; int result; result = pthread_create(&thrreadid, NULL, zmq_client::reactor_proc, this); if (result == -1) { MYLOG_ERROR("failed to start thread zmq_client::reactor_proc"); return -1; } result = pthread_create(&thrreadid, NULL, zmq_client::send_msg_proc, this); if (result == -1) { MYLOG_ERROR("failed to start thread zmq_client::send_msg_proc"); return -1; } return 0; }
bool CConfigLoader::add_db_info(struct DbInfo* db_info, struct DbInfo* db_info_array[]) { int index = db_info->index; if (index >= MAX_DB_CONNECTION) { MYLOG_ERROR("index[%d] greater or equal %d of %s\n", index, MAX_DB_CONNECTION, db_info->str().c_str()); return false; } if (db_info_array[index] != NULL) { MYLOG_ERROR("index[%d] repeat: %s => %s\n", index, db_info->str().c_str(), db_info_array[index]->str().c_str()); return false; } db_info_array[index] = db_info; return true; }
bool CConfigLoader::add_query_info(struct QueryInfo* query_info, struct QueryInfo* query_info_array[]) { int index = query_info->index; if (index >= MAX_SQL_TEMPLATE) { MYLOG_ERROR("index[%d] greater or equal %d of %s\n", index, MAX_SQL_TEMPLATE, query_info->str().c_str()); return false; } if (query_info_array[index] != NULL) { MYLOG_ERROR("index[%d] repeat: %s => %s\n", index, query_info->str().c_str(), query_info_array[index]->str().c_str()); return false; } query_info_array[index] = query_info; return true; }
bool CConfigLoader::add_update_info(struct UpdateInfo* update_info, struct UpdateInfo* update_info_array[]) { int index = update_info->index; if (index >= MAX_SQL_TEMPLATE) { MYLOG_ERROR("index[%d] greater or equal %d of %s\n", index, MAX_SQL_TEMPLATE, update_info->str().c_str()); return false; } if (update_info_array[index] != NULL) { MYLOG_ERROR("index[%d] repeat: %s => %s\n", index, update_info->str().c_str(), update_info_array[index]->str().c_str()); return false; } update_info_array[index] = update_info; return true; }
int CDbProxyHandler::update(const std::string& sign, const int32_t seq, const int32_t update_index, const std::vector<std::string>& tokens) { CConfigLoader* config_loader = CConfigLoader::get_singleton(); struct UpdateInfo update_info; if (check_token(seq, tokens)) { throw apache::thrift::TApplicationException("invalid parameter"); } if (!config_loader->get_update_info(update_index, &update_info)) { MYLOG_ERROR("[%d]update_index[%d] not exists\n", seq, update_index); throw apache::thrift::TApplicationException("update_index not exists"); } try { sys::DBConnection* db_connection = config_loader->get_db_connection(update_info.database_index); if (NULL == db_connection) { MYLOG_ERROR("[%d]database_index[%d] not exists\n", seq, update_info.database_index); throw apache::thrift::TApplicationException("database_index not exists"); } else if (tokens.size() > utils::FORMAT_STRING_SIZE) { MYLOG_ERROR("[%d]too big: %d\n", seq, (int)tokens.size()); throw apache::thrift::TApplicationException("tokens too many"); } else { std::string sql = utils::format_string(update_info.sql_template.c_str(), tokens); MYLOG_DEBUG("%s\n", sql.c_str()); int affected_rows = db_connection->update("%s", sql.c_str()); return affected_rows; } } catch (sys::CDBException& db_ex) { MYLOG_ERROR("[%d]%s\n", seq, db_ex.str().c_str()); throw apache::thrift::TApplicationException(db_ex.str()); } }
void CSqlLogger::rotate_log() { if (_log_fd != -1) { if (-1 == fsync(_log_fd)) { const int errcode = errno; MYLOG_ERROR("fsync %s error: (%d)%s\n", _log_filepath.c_str(), errcode, sys::Error::to_string(errcode).c_str()); } close(_log_fd); _log_fd = -1; } if (_log_filepath.empty()) { _log_filepath = get_last_log_filepath(); MYLOG_INFO("%s\n", _log_filepath.c_str()); } else { _log_filepath = get_log_filepath(); MYLOG_INFO("%s\n", _log_filepath.c_str()); } if (_log_filepath.empty()) { } else { _log_fd = open(_log_filepath.c_str(), O_WRONLY|O_CREAT|O_APPEND, FILE_DEFAULT_PERM); // O_EXCL if (-1 == _log_fd) { MYLOG_ERROR("[%s] create %s error: %s\n", _dbinfo->str().c_str(), _log_filepath.c_str(), sys::Error::to_string().c_str()); } else { int log_file_size = static_cast<int>(sys::CFileUtils::get_file_size(_log_fd)); MYLOG_INFO("[%s] create %s ok: %d\n", _dbinfo->str().c_str(), _log_filepath.c_str(), log_file_size); } } }
void * zmq_client::reactor_proc( void *param ) { if (param == NULL) { return (void *)NULL; } zmq_client *pthis=(zmq_client *)param; pthis->reactor_doit(); MYLOG_ERROR("zmq_client::reactor_proc terminiated"); return (void *)NULL; }
void * zmq_client::send_msg_proc( void *param ) { if (param == NULL) { return (void *)param; } zmq_client *pthis = (zmq_client *)param; pthis->send_msg_doit(); MYLOG_ERROR("zmq_client::send_msg_proc terminated"); return (void *)NULL; }
void * threadpoll_manager::general_thread_proc( void *param ) { if (param == NULL) { return (void *)0; } threadpoll_manager *pthis = (threadpoll_manager *)param; pthis->general_thread_doit(); MYLOG_ERROR("thread threadpoll_manager::general_thread_proc terminated"); return (void *)0; }
void HttpRequestPacket::generate_client_ip( void ) { //LOGDEBUG(); std::map<std::string, std::string>::iterator iter; iter = mapHead.find("X-REAL-IP"); if (iter != mapHead.end()) { //LOG4CPLUS_DEBUG(logger,"set clientip="<<iter->second<<" from header X-Real-IP"); m_str_clientip = iter->second; boost::trim(m_str_clientip); return; } if (m_str_clientip.empty()) { char peerip[18]={0}; struct sockaddr_in peeraddr; memset(&peeraddr, 0, sizeof(sockaddr_in)); socklen_t len=sizeof(sockaddr_in); int ret = getpeername(m_clientfd, (struct sockaddr *)&peeraddr, &len); if (ret != 0) { m_str_clientip = "127.0.0.1"; MYLOG_ERROR( "fail to get client ip from fd"); return; } const char *ret1 = inet_ntop(AF_INET, (void *)&peeraddr.sin_addr, (char *)peerip, sizeof(peerip)); if (ret1 == NULL) { m_str_clientip = "127.0.0.1"; //LOG4CPLUS_ERROR(logger,"fail to get client ip from fd"); MYLOG_ERROR("fail to get client ip from fd"); return; } m_str_clientip = peerip; //LOG4CPLUS_DEBUG(logger,"clientip from fd="<<m_str_clientip); } }
void * adapter_manager::adapter_reply_proc( void *param ) { if (param == NULL) { return (void *)NULL; } adapter_manager *pthis=(adapter_manager *)param; pthis->adapter_reply_doit(); MYLOG_ERROR("thread adapter_reply_proc terminated"); return (void *)NULL; }
bool CSqlLogger::write_log(const std::string& sql) { try { int32_t length = static_cast<int32_t>(sql.size()); sys::LockHelper<sys::CLock> lock_helper(_lock); if ((-1 == _log_fd) || need_rotate()) { rotate_log(); } if (-1 == _log_fd) { return false; } struct iovec iov[2]; iov[0].iov_base = &length; iov[0].iov_len = sizeof(length); iov[1].iov_base = const_cast<char*>(sql.data()); iov[1].iov_len = sql.size(); ssize_t bytes_written = writev(_log_fd, iov, sizeof(iov)/sizeof(iov[0])); if (bytes_written != static_cast<int>(iov[0].iov_len+iov[1].iov_len)) { const int errcode = errno; THROW_SYSCALL_EXCEPTION(utils::CStringUtils::format_string("writev %s error: %s", _log_filepath.c_str(), sys::Error::to_string(errcode).c_str()), errcode, "writev"); } // 计数 ++_total_lines; const int32_t lines = argument::lines->value(); if ((lines > 0) && (++_num_lines >= lines)) { _num_lines = 0; if (-1 == fdatasync(_log_fd)) { const int errcode = errno; THROW_SYSCALL_EXCEPTION(utils::CStringUtils::format_string("fdatasync %s error: %s", _log_filepath.c_str(), sys::Error::to_string(errcode).c_str()), errno, "fdatasync"); } } return true; } catch (sys::CSyscallException& ex) { MYLOG_ERROR("[%s] write [%s] to [%s] failed: %s\n", _dbinfo->str().c_str(), sql.c_str(), _log_filepath.c_str(), ex.str().c_str()); return false; } }
/* 返回值: -1: 错误发生 0: 所有待发送的数据都已经提交到协议栈缓冲区 >0: 还有n字节的数据尚未提交到缓冲区,即:当前缓冲区处于满的状态,可能是网络速度较慢或者对端接收较慢 需要将尚未提交到缓冲区的数据放入对应的应用层buffer中缓存起来,在下一次可写事件发生时,继续发送 */ int tcpserver::send_internal( STU_EPOLL_RTN *pstu_epoll_rtn ) { int result; if (pstu_epoll_rtn == NULL) { return -1; } m_array_epoll_data[pstu_epoll_rtn->clientfd]->updatetime = time(NULL); if (m_array_epoll_data[pstu_epoll_rtn->clientfd]->str_data_write.empty()) { // 应用层缓冲区内没有需要待发送的数据 result = send(pstu_epoll_rtn->clientfd, pstu_epoll_rtn->str_data_send.c_str(), pstu_epoll_rtn->str_data_send.size(), 0); if (result == -1) { return -1; } // 返回还有多少需要发送 return pstu_epoll_rtn->str_data_send.size()-result; } else { m_array_epoll_data[pstu_epoll_rtn->clientfd]->str_data_write = m_array_epoll_data[pstu_epoll_rtn->clientfd]->str_data_write + pstu_epoll_rtn->str_data_send; int buffered_size = m_array_epoll_data[pstu_epoll_rtn->clientfd]->str_data_write.size(); if (buffered_size >= 1024*64) { // 应用层缓存的buffer数太多,认为对端socket有问题,直接关掉该socket,作为保护 MYLOG_ERROR("too much send buffer, should close socket"); return -1; } result = send(pstu_epoll_rtn->clientfd, m_array_epoll_data[pstu_epoll_rtn->clientfd]->str_data_write.c_str(), buffered_size,0); if (result == -1) { return -1; } if (result == buffered_size) { return 0; } std::string buffer_tmp; buffer_tmp = m_array_epoll_data[pstu_epoll_rtn->clientfd]->str_data_write.substr(result); m_array_epoll_data[pstu_epoll_rtn->clientfd]->str_data_write = buffer_tmp; return buffer_tmp.size(); } }
int tcpserver::set_nonblocking( int socketfd ) { int flags, s; flags = fcntl (socketfd, F_GETFL, 0); if (flags == -1) { //perror ("fcntl"); MYLOG_ERROR("failed to get socket non blocking"); return -1; } flags |= O_NONBLOCK; s = fcntl (socketfd, F_SETFL, flags); if (s == -1) { MYLOG_ERROR("failed to set socket non blocking"); return -1; } return 0; }
bool CHttpEvent::on_name_value_pair(const char* name_begin, const char* name_end ,const char* value_begin, const char* value_end) { MYLOG_DEBUG("Name: %.*s, Value: %.*s.\n", (int)(name_end-name_begin), name_begin, (int)(value_end-value_begin), value_begin); size_t name_len = name_end - name_begin; size_t value_len = value_end - value_begin; if ((name_len < 3) || (name_len>sizeof(_on_name_value_pair_xxx)/sizeof(on_name_value_pair_xxx))) { MYLOG_ERROR("Error NV - %.*s: %.*s.\n", (int)name_len, name_begin, (int)value_len, value_begin); return false; } if (NULL == _on_name_value_pair_xxx[name_len]) return true; return (this->*_on_name_value_pair_xxx[name_len])(name_begin, name_len, value_begin, value_len); }
MOOON_NAMESPACE_USE static void foo() { for (int i=0; i<100000; ++i) { MYLOG_DEBUG("[%d]MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM", i); MYLOG_DETAIL("[%d]KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK", i+1); MYLOG_INFO("[%d]BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", i+2); MYLOG_ERROR("[%d]TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT", i+3); MYLOG_WARN("[%d]PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP", i+4); MYLOG_TRACE("[%d]AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", i+5); MYLOG_STATE("[%d]ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ", i+6); //sys::CUtils::millisleep(10); } }
int HttpRequestPacket::decode_get( string& sHttpHead ) { //LOG4CPLUS_DEBUG(logger, "http head: " << sHttpHead); //get first line, GET /xx?xxx string::size_type requestPos = sHttpHead.find("\r\n"); if ( requestPos == string::npos ) { // unfinished recv data, need more MYLOG_ERROR( "error http request : %s" , sHttpHead.c_str()); return -1; } //ready to parse param string sRequestLine = sHttpHead.substr(0, requestPos); string::size_type pos1 = sRequestLine.find("/"); if ( pos1 == string::npos ) { MYLOG_DEBUG( "can't find /"); return -1; } string::size_type pos2 = sRequestLine.find(" ", pos1);//find space if ( pos2 == string::npos ) { MYLOG_DEBUG( "can't find space"); return -1; } m_str_GetRequest = sRequestLine.substr(pos1, pos2-pos1); ParseParam(m_str_GetRequest); //LOG4CPLUS_DEBUG(logger, "m_str_GetRequest: " << m_str_GetRequest); ParseHead(sHttpHead); /*std::map<std::string, std::string>::iterator iter; for (iter = mapHead.begin(); iter!= mapHead.end(); iter++) { LOG4CPLUS_DEBUG(logger, "key="<<iter->first<<" value="<<iter->second); }*/ //ready to parse cookie string sCookie = GetLine("COOKIE", sHttpHead); ParseCookie(sCookie); return 0; }
void threadpoll_manager::init_thread_poll( void ) { const SDConfiguration& config = SDConfigurationSingleton::get_instance()->get_config(); int thread_count = config.getInt("threadpoll_thread_count",10); for (int i=0;i<thread_count; i++) { pthread_t threadid; int result = pthread_create(&threadid, NULL, threadpoll_manager::general_thread_proc, this); if (result == -1) { MYLOG_ERROR("failed to create thread threadpoll_manager::general_thread_proc, exit"); sleep(1); exit(0); } } }
bool ISMGManager::UpdateISMGInfo() { std::list<ISMGInfo *> lst; if (true == m_dbService->getAllISMGInfo(lst)) { for (std::list<ISMGInfo *>::iterator it = lst.begin(); it != lst.end(); ++it) { ISMGInfo *pInfo = *it; if (NULL != pInfo) { m_mapISMG.insert(std::make_pair(pInfo->SP_Id, pInfo)); } } MYLOG_INFO("Update ISMGInfo success"); return true; } else { MYLOG_ERROR("Update ISMGParam failed"); return false; } }
int tcpserver::send_data( int fd, uint64_t unify_tag, std::string &str_data ) { boost::shared_ptr<STU_EPOLL_RTN> stu_epoll_rtn(new STU_EPOLL_RTN); stu_epoll_rtn->clientfd = fd; stu_epoll_rtn->fd_unify_tag = unify_tag; stu_epoll_rtn->cmd_type = PIPE_CMD_SEND; stu_epoll_rtn->str_data_send = str_data; m_queue_send.add_queue(stu_epoll_rtn); int result; char chardata[3]={0}; result = write(m_pipe_write,(void *)chardata,1); if (result == -1) { MYLOG_ERROR("failed to add senddata cmd to pipe write, errno=%d, errstr=%s",errno, strerror(errno)); return -1; } return 0; }
static bool check_token(int32_t seq, const std::vector<std::string>& tokens) { return true; for (std::vector<std::string>::size_type i=0; i<tokens.size(); ++i) { const std::string& token = tokens[i]; for (std::string::size_type j=0; j<token.size(); ++j) { if ((token[i] == ',') || (token[i] == '(') || (token[i] == ')')) { MYLOG_ERROR("[%d]invalid token[%d:%d:%s]\n", seq, (int)i, (int)j, token.c_str()); return false; } } } return true; }
void zmq_client::send_msg_doit( void ) { MYLOG_DEBUG("send_msg_doit thread start"); int result; sleep(1); zmq::context_t *pcontext = new zmq::context_t(1); zmq::socket_t *psocket_cmd = new zmq::socket_t(*pcontext, ZMQ_DEALER); result = psocket_cmd->connect(m_ipc_addr.c_str()); if (result == -1) { MYLOG_ERROR("failed to connect to ipc, addr=%s",m_ipc_addr.c_str()); return; } while (true) { boost::shared_ptr<STU_ZMQ_CLIENT_MSG> pstu; result = m_queue_send.dequeue_expand(pstu); if (result != 1) { continue; } //MY_LOGDEBUG("recv msg from m_queue_send, data="<<pstu->data<<" dst="<<pstu->destination); m_queue_ipc.add_queue(pstu); STU_ZMQ_INFO stu; stu.cmd_type=ZMQ_CMD_TYPE_DATA; stu.data = pstu->data; stu.destination = pstu->destination; socket_wrapper wrapper; wrapper.send_pack(psocket_cmd, &stu); } }
void tcpserver::close_socket_internal( int clientfd ) { epoll_event event; event.data.fd = 0; event.events = 0; int del_result = epoll_ctl(m_epoll_fd, EPOLL_CTL_DEL, clientfd, &event); if (del_result == -1) { MYLOG_ERROR("failed to del client fd from epoll fd"); } close(clientfd); m_clientcount--; m_array_epoll_data[clientfd]->status = enum_socket_close; m_array_epoll_data[clientfd]->str_data_recved.clear(); m_array_epoll_data[clientfd]->str_data_write.clear(); m_notify_callback(enum_sock_close, NULL, 0, m_array_epoll_data[clientfd]); }
bool ISMGManager::UpdateISMGParam() { std::list<ISMGParam *> lst; if (true == m_dbService->getAllISMGParam(lst)) { for (std::list<ISMGParam *>::iterator it = lst.begin(); it != lst.end(); ++it) { ISMGParam *pParam = *it; if (NULL != pParam) { ISMGInfo *pInfo = getISMGInfo(pParam->SP_Id); if (NULL != pInfo) { pInfo->UpdateParam(pParam); } else { delete pParam; } } } MYLOG_INFO("Update ISMGParam success"); return true; } else { MYLOG_ERROR("Update ISMGParam failed"); return false; } }
int HttpRequestPacket::decode_post( string& sHttpHead ) { string::size_type requestPos = sHttpHead.find("\r\n"); if ( requestPos == string::npos ) { // unfinished recv data, need more MYLOG_ERROR("error http request :%s " ,sHttpHead.c_str()); return -1; } //ready to parse param string sRequestLine = sHttpHead.substr(0, requestPos); string::size_type pos1 = sRequestLine.find("/"); if ( pos1 == string::npos ) { MYLOG_DEBUG( "can't find /"); return -1; } string::size_type pos2 = sRequestLine.find(" ", pos1);//find space if ( pos2 == string::npos ) { MYLOG_DEBUG( "can't find space"); return -1; } m_str_GetRequest = sRequestLine.substr(pos1, pos2-pos1); ParseParam(m_str_GetRequest); //LOG4CPLUS_DEBUG(logger, "m_str_GetRequest: " << m_str_GetRequest); ParseHead(sHttpHead); std::map<std::string, std::string>::iterator iter; iter = mapHead.find("CONTENT-LENGTH"); if (iter == mapHead.end()) { MYLOG_DEBUG( "failed to find CONTENT-LENGTH from headers"); return -1; } std::string str_length = iter->second; boost::trim(str_length); int intlength = SDUtility::atouint32(str_length); if (sHttpHead.size() < intlength) { return -1; } std::string str_params; str_params = sHttpHead.substr(sHttpHead.length()-intlength, intlength); string2map(str_params, mapParam); return 0; /*std::map<std::string, std::string>::iterator iter; for (iter = mapHead.begin(); iter!= mapHead.end(); iter++) { LOG4CPLUS_DEBUG(logger, "key="<<iter->first<<" value="<<iter->second); }*/ //ready to parse cookie //string sCookie = GetLine("COOKIE", sHttpHead); //ParseCookie(sCookie); }