void ThreadPool::start(int numThreads) { if (running_) return; running_ = true; assert(threads_.empty()); threads_.reserve(numThreads); for (int i = 0; i < numThreads; ++i) { char id[32]; ZL_SNPRINTF(id, sizeof id, "%d", i); threads_.push_back(new Thread(std::bind(&ThreadPool::executeThread, this), name_ + id)); } }
const char* LogFile::makeLogFilePath() { ::memset(currLogFileName_, '\0', MAX_FILE_PATH_LEN); ZL_SNPRINTF(currLogFileName_, MAX_FILE_PATH_LEN, "%s/%s-%d.log", logDir_, logFileName_, curFileIndex_); return currLogFileName_; }
std::string Socket::getHost() { char host[256], ip[256]; ZL_SNPRINTF(host, 256, "%s:%d", inet_ntop(AF_INET, &sockaddr_.sin_addr, ip, 256), ntohs(sockaddr_.sin_port)); return std::string(host); }
std::string Socket::getHostIP() { char ip[256], tmp[256]; ZL_SNPRINTF(ip, 128, "%s", inet_ntop(AF_INET, &sockaddr_.sin_addr, tmp, 256)); return std::string(ip); }
short Socket::getHostPort() { char buf[16]; ZL_SNPRINTF(buf, 16, "%d", ntohs(sockaddr_.sin_port)); return ::atoi(buf); }