Skip to content

zhangke96/TcpServer

Repository files navigation

TcpServer Build Status

TcpServer only work with epoll.

Usage:

OnConnectOperation connection(const Connection *connection, void *data);
void onReadHandler(const Connection *, const char *, size_t , void *);
void onPeerShutdownHandler(const Connection *, void *);

TcpServer server;
server.setAddressPort("0.0.0.0", 80);
server.onConnect(connectHandler);	// TcpServer will callback when new connection
server.onNewData(onReadHandler);	// TcpServer will callbakck when new data read
server.onShutdown(onPeerShutdownHandler);	// TcpServer will callback when client shutdown the connection

std::thread t(server.runServer(false));	// TcpServer will run and create a thread
t.join();

std::vector<std::pair<int, EpollChangeOperation>> change {};
server.notifyChangeEpoll(change);	// User can notify server to add write or close connection

WriteMeta toWrite(buffer, length);
server.notifyCanWrite(fd, toWrite);	// User can notify server to write content to client

Sample can run.

Demo:

A Http Server use this TcpServer.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published