Skip to content

libepoll使用epoll基础模型为基础。分离socket与epol具体逻辑。只需关心具体的socket处理流程

Notifications You must be signed in to change notification settings

vaptu/libkepoll

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 

Repository files navigation

libkepoll

Libkepoll use epoll model-based foundation. Separate socket and epol specific logic. Only care about the specific socket processing. Visit the

http://kepoll.vaptu.com/

page and download the open source project

#include <server_kepoll.h>
#include <iostream>
using namespace std;



class MyServer : public ServerKEpoll{
	public:
	MyServer(const string addr, int port):ServerKEpoll(addr, port)
	{
	}
		//standard input 
	bool StdinHandle(int fd){
		char buf[2048] = {0};
		int re = read(fd, buf, 2048);
		if(re <=0)
			return false;

		buf[re] = '\0';
		cout << "stdin : " << buf <<endl;
		return true;
	}

		//client input 
	bool ClientHandle(int fd){
		char buf[2048] = {0};
		int re = read(fd, buf, 2048);
		if(re <=0)
			return false;

		buf[re] = '\0';
		cout << "client : " << buf <<endl;
		return true;

	}
		
        //administrator input
	bool OperaHandle(int fd){
		char buf[2048] = {0};
		int re = read(fd, buf, 2048);
		if(re <=0)
			return false;

		buf[re] = '\0';
		cout << "opera : " << buf <<endl;
		return true;
	}
};

int main()
{
	MyServer server("0.0.0.0", 4455);
    //Capture standard input
	server.SetStdinCatch();
    
    //Administrator listening port
	server.SetAdminer("0.0.0.0", 9999);
    
    //Multi-client port monitoring
	server.SetListener("0.0.0.0", 4444);
    
    //Heartbeat packet transmission interval
	server.SetHeartbeat(1000);

	//Start the message loop
	server.KEpoll_Loop();
}

About

libepoll使用epoll基础模型为基础。分离socket与epol具体逻辑。只需关心具体的socket处理流程

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published