bool CServer::Start(unsigned short port) { // CConnection or Queue if (pConnect == NULL || p_InMsgQueue == NULL || p_OutMsgQueue == NULL || isStarted) return false; Port = port; isStarted = true; // u must start before create thread or thread will exit soon if (!pConnect->create(port)) { return false; } for (unsigned int i = 0; i < msgthread_num; i++) { int rc = iop_thread_create(&pthread_msg[i], MsgProc, (void *) this, 0); if( rc == 0 ){ iop_usleep(10); #ifdef _DEBUG_INFO_ cout << "Msg Thread start successfully" << endl; #endif } else { isStarted = false; } } for (unsigned int i = 0; i < sendthread_num; i++) { int rc = iop_thread_create(&pthread_send[i], SendProc, (void *) this, 0); if (0 == rc) { iop_usleep(10); #ifdef _DEBUG_INFO_ cout << "Send Thread start successfully " << endl; #endif } else { isStarted = false; } } for (unsigned int i = 0; i < recvthread_num; i++) { int rc = iop_thread_create(&pthread_recv[i], RecvProc, (void *) this, 0); if (0 == rc) { iop_usleep(10); #ifdef _DEBUG_INFO_ cout << "Recv Thread start successfully " << endl; #endif } else { isStarted = false; } } return isStarted; }
void CClientNet::startupHeartBeat() { int rc = iop_thread_create(&pthread_hb, HBProc, (void *) this, 0); if (0 == rc) { iop_usleep(10); #ifdef _DEBUG_INFO_ cout << "Heart Beat Thread start successfully " << endl; #endif } else { turnOff(); } }
int iop_log_service_start(const char *path, const char *prefix,char level) { iop_log_service_t *log; if(g_iop_log_service) { return 0; } g_iop_log_service = (iop_log_service_t *)malloc(sizeof(iop_log_service_t)); if(!g_iop_log_service) { return -1; } log = g_iop_log_service; log->log_level = level; log->log_buf_size = 0; log->m_day = -1; log->stop_flag = 0; memset((void *)(log->path), 0, IOP_MAX_LOG_PATH+1); memset((void *)(log->prefix), 0, IOP_MAX_LOG_PATH+1); if(path) { int path_len = strlen(path); #ifdef WIN32 strcpy_s((char *)(log->path),IOP_MAX_LOG_PATH-1,path); #else strncpy((char *)(log->path), path,IOP_MAX_LOG_PATH); #endif if(path_len == 0) { log->path[0] = '/'; log->path[1] = 0; } else { if((log->path)[path_len-1] != '/') { log->path[path_len] = '/'; log->path[path_len+1] = 0; } } } else { #ifdef WIN32 strcpy_s((char *)(log->path),IOP_MAX_LOG_PATH, "./"); #else strncpy((char *)(log->path), "./",IOP_MAX_LOG_PATH); #endif } if(prefix) { #ifdef WIN32 strcpy_s((char *)(log->prefix), IOP_MAX_LOG_PATH,prefix); #else strncpy((char *)(log->prefix), prefix,IOP_MAX_LOG_PATH); #endif } log->fp = (FILE *)0; iop_lock_init(&(log->lock)); __iop_log_reopen(log); iop_thread_create(&(log->tid), __log_service_start_routine, (void *)log, 1024*1024); return 0; }