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

📄 testechos.cpp

📁 spserver 是一个实现了半同步/半异步(Half-Sync/Half-Async)和领导者/追随者(Leader/Follower) 模式的服务器框架
💻 CPP
字号:
/* * Copyright 2007 Stephen Liu * For license terms, see the file COPYING along with this library. */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <syslog.h>#include <signal.h>#include <unistd.h>#include "spmsgdecoder.hpp"#include "spbuffer.hpp"#include "spserver.hpp"#include "sphandler.hpp"#include "spresponse.hpp"#include "sprequest.hpp"#include "spmatrixssl.hpp"class SP_EchoHandler : public SP_Handler {public:	SP_EchoHandler(){}	virtual ~SP_EchoHandler(){}	// return -1 : terminate session, 0 : continue	virtual int start( SP_Request * request, SP_Response * response ) {		request->setMsgDecoder( new SP_LineMsgDecoder() );		response->getReply()->getMsg()->append(			"Welcome to line echo server, enter 'quit' to quit.\r\n" );		return 0;	}	// return -1 : terminate session, 0 : continue	virtual int handle( SP_Request * request, SP_Response * response ) {		SP_LineMsgDecoder * decoder = (SP_LineMsgDecoder*)request->getMsgDecoder();		if( 0 != strcasecmp( (char*)decoder->getMsg(), "quit" ) ) {			response->getReply()->getMsg()->append( (char*)decoder->getMsg() );			response->getReply()->getMsg()->append( "\r\n" );			return 0;		} else {			response->getReply()->getMsg()->append( "Byebye\r\n" );			return -1;		}	}	virtual void error( SP_Response * response ) {}	virtual void timeout( SP_Response * response ) {}	virtual void close() {}};class SP_EchoHandlerFactory : public SP_HandlerFactory {public:	SP_EchoHandlerFactory() {}	virtual ~SP_EchoHandlerFactory() {}	virtual SP_Handler * create() const {		return new SP_EchoHandler();	}};//---------------------------------------------------------int main( int argc, char * argv[] ){#ifdef LOG_PERROR	openlog( "testechos", LOG_CONS | LOG_PID | LOG_PERROR, LOG_USER );#else	openlog( "testechos", LOG_CONS | LOG_PID, LOG_USER );#endif	int port = 1995;	SP_Server server( "", port, new SP_EchoHandlerFactory() );	SP_MatrixsslChannelFactory * matrixsslFactory = new SP_MatrixsslChannelFactory();	matrixsslFactory->init( "demo.crt", "demo.key" );	server.setIOChannelFactory( matrixsslFactory );	server.runForever();	return 0;}

⌨️ 快捷键说明

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