int main(int argc,char **argv) { LOG_INFO << "pid = " <<getpid(); if(argc > 2) { EventLoopThread loopThread; uint16_t port = static_cast<uint16_t>(atoi(argv[2])); InetAddress serverAddr(argv[1],port); ChatClient client(loopThread.startLoop(),serverAddr); client.connect(); std::string line; while(std::getline(std::cin,line)) { client.write(line); } client.disconnect(); CurrentThread::sleepUsec(1000*1000); } else { printf("Usage:%s host_ip port\n",argv[0]); } return 0; }
bool EventLoopThreadPool::Start(uint threadCount, const StringRef& pollerName) { HeapString threadName; FOR_EACH_SIZE(i, threadCount) { threadName.Format("EventLoopThread-{}", i); EventLoopThread* thread = new EventLoopThread(threadName, pollerName); mThreads.Add(thread); thread->Start(); }
int main(int argc, char **argv) { std::string threadName = "thread01"; EventLoopThread *pthread = new EventLoopThread(threadName); pthread->startRun(); delete pthread; return 0; }
int main() { printf("main(): pid = %d, tid = %d\n", ::getpid(), CurrentThread::GetTid()); EventLoopThread evtLoopThread; EventLoop* pLoop = evtLoopThread.StartLoop(); pLoop->RunInLoop(runInThread); ::sleep(1); pLoop->RunAfter(2, runInThread); ::sleep(2); pLoop->Quit(); printf("exit main().\n"); }
void CTcpServer::listenCallback(struct evconnlistener* listener, evutil_socket_t fd, struct sockaddr* addr, int socklen, void* data) { if (!data) { return; } fprintf(stdout, "new connection is comming...\n"); CTcpServer* p = reinterpret_cast<CTcpServer*>(data); EventLoopThread* loop = p->eventPool_.getNextLoop(); Channel* channel = new Channel(loop->startLoop(), fd); loop->runInLoop(std::bind(&Channel::start, channel)); fprintf(stdout, "currentThreadID:%d\n", ::GetCurrentThreadId()); }
void EventLoopThreadGroup::Start() { assert(!startFlag_); baseLoop_->AssertInLoopThreadOrDie(); for (auto i = 0; i < numThreads_; i++) { EventLoopThread* loopThread = new EventLoopThread(); loopThreads_.push_back(loopThread); auto loop = loopThread->StartLoopThread(); assert(loop); loops_.push_back(loop); } startFlag_ = true; }
void EventLoopThreadPool::start() { assert(!started_); baseLoop_->assertInLoopThread(); started_ = true; for (int i = 0; i < numThreads_; ++i) { char buf[name_.size() + 32]; snprintf(buf, sizeof buf, "%s%d", name_.c_str(), i); EventLoopThread* t = new EventLoopThread(buf); threads_.push_back(t); loops_.push_back(t->startLoop()); } }
int main(int argc, char* argv[]) { Logger::setLogLevel(Logger::DEBUG); EventLoopThread loopThread; { EventLoop* loop = loopThread.startLoop(); AddrInet serverAddr("127.0.0.1", 22); // should succeed TcpClient client(loop, serverAddr, "TcpClient"); client.connect(); Thread::sleep(1000*1000);// wait for connect client.disconnect(); //Thread::sleep(1000 * 1000); } Thread::sleep(1000 * 1000); }
Context *RedisProxy::createContextObject(void) { ClientPacket* packet = new ClientPacket; EventLoop* loop; if (m_eventLoopThreadPool) { int threadCount = m_eventLoopThreadPool->size(); EventLoopThread* loopThread = m_eventLoopThreadPool->thread(m_threadPoolRefCount % threadCount); ++m_threadPoolRefCount; loop = loopThread->eventLoop(); } else { loop = eventLoop(); } packet->eventLoop = loop; return packet; }
void EventLoopThreadPool::start(const ThreadInitCallback& cb) { assert(!started_); started_ = true; for (int i = 0; i < numThreads_; ++ i) { char buf[name_.size() + 32]; snprintf(buf, sizeof buf, "%s%d", name_.c_str(), i); EventLoopThread* t = new EventLoopThread(cd, buf); threads_.push_back(t); loops_.push_back(t->startLoop()); } if (numThreads_ == 0 && cb) { cb(baseLoop); } }
int main(int argc, char* argv[]) { printf("main:tid:%d\n", CurrentThread::tid()); EventLoopThread loopThread; EventLoop* loop = loopThread.startLoop(); loop->runInLoop(runInThread); sleep(1); loop->runAfter(2, runInThread); loop->quit(); printf("exit main\n"); }
void EventLoopThreadPool::start(const ThreadInitCallback& cb) { assert(!started_); baseLoop_->assertInLoopThread(); started_ = true; for (int i = 0; i < numThreads_; i++) { EventLoopThread* t = new EventLoopThread(cb); threads_.push_back(t); loops_.push_back(t->startLoop()); } if (numThreads_ == 0 && cb) { cb(baseLoop_); } }