1b37003a7SShuo Chen#include "Acceptor.h" 2b37003a7SShuo Chen#include "EventLoop.h" 3b37003a7SShuo Chen#include "InetAddress.h" 4b37003a7SShuo Chen#include "SocketsOps.h" 5b37003a7SShuo Chen#include <stdio.h> 6b37003a7SShuo Chen 7b37003a7SShuo Chenvoid newConnection(int sockfd, const muduo::InetAddress& peerAddr) 8b37003a7SShuo Chen{ 9b37003a7SShuo Chen printf("newConnection(): accepted a new connection from %s\n", 10b37003a7SShuo Chen peerAddr.toHostPort().c_str()); 11b37003a7SShuo Chen ::write(sockfd, "How are you?\n", 13); 12b37003a7SShuo Chen muduo::sockets::close(sockfd); 13b37003a7SShuo Chen} 14b37003a7SShuo Chen 15b37003a7SShuo Chenint main() 16b37003a7SShuo Chen{ 17b37003a7SShuo Chen printf("main(): pid = %d\n", getpid()); 18b37003a7SShuo Chen 19b37003a7SShuo Chen muduo::InetAddress listenAddr(9981); 20b37003a7SShuo Chen muduo::EventLoop loop; 21b37003a7SShuo Chen 22b37003a7SShuo Chen muduo::Acceptor acceptor(&loop, listenAddr); 23b37003a7SShuo Chen acceptor.setNewConnectionCallback(newConnection); 24b37003a7SShuo Chen acceptor.listen(); 25b37003a7SShuo Chen 26b37003a7SShuo Chen loop.loop(); 27b37003a7SShuo Chen} 28