⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spdispatcher.hpp

📁 spserver 是一个实现了半同步/半异步(Half-Sync/Half-Async)和领导者/追随者(Leader/Follower) 模式的服务器框架
💻 HPP
字号:
/* * Copyright 2007 Stephen Liu * For license terms, see the file COPYING along with this library. */#ifndef __spdispatcher_hpp__#define __spdispatcher_hpp__#include <sys/time.h>class SP_CompletionHandler;class SP_Handler;class SP_Message;class SP_BlockingQueue;class SP_TimerHandler;class SP_IOChannel;class SP_EventArg;class SP_Dispatcher {public:	SP_Dispatcher( SP_CompletionHandler * completionHandler, int maxThreads = 64 );	~SP_Dispatcher();	void setTimeout( int timeout );	int getSessionCount();	int getReqQueueLength();	void shutdown();	int isRunning();	/**	 * @brief  create a thread to run event loop	 * @return 0 : OK, -1 : Fail, cannot create thread	 */	int dispatch();	/**	 * @brief register a fd into dispatcher	 * @param needStart : 1 - call handler::start, 0 - don't call handler::start	 * @return 0 : OK, -1 : Fail, invalid fd	 * @note  handler will be deleted by dispatcher when the session is close	 */	int push( int fd, SP_Handler * handler, int needStart = 1 );	int push( int fd, SP_Handler * handler, SP_IOChannel * ioChannel, int needStart = 1 );	/**	 * @brief register a timer into dispatcher	 * @param timeout : the interval for the timer	 * @note  handler will be deleted by dispatcher when the timer is terminated	 */	int push( const struct timeval * timeout, SP_TimerHandler * handler );private:	int mIsShutdown;	int mIsRunning;	int mMaxThreads;	SP_EventArg * mEventArg;	SP_CompletionHandler * mCompletionHandler;	void * mPushQueue;	int start();	static void * eventLoop( void * arg );	static void onPush( void * queueData, void * arg );	static void outputCompleted( void * arg );	static void onTimer( int, short, void * arg );	static void timer( void * arg );};#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -