spdispatcher.hpp

来自「spserver 是一个实现了半同步/半异步(Half-Sync/Half-As」· HPP 代码 · 共 80 行

HPP
80
字号
/* * 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 + =
减小字号Ctrl + -
显示快捷键?