165c497a3SShuo Chen#include "Acceptor.h" 265c497a3SShuo Chen#include "EventLoop.h" 365c497a3SShuo Chen#include "InetAddress.h" 465c497a3SShuo Chen#include "SocketsOps.h" 565c497a3SShuo Chen#include <stdio.h> 665c497a3SShuo Chen 765c497a3SShuo Chenvoid newConnection(int sockfd, const muduo::InetAddress& peerAddr) 865c497a3SShuo Chen{ 965c497a3SShuo Chen printf("newConnection(): accepted a new connection from %s\n", 1065c497a3SShuo Chen peerAddr.toHostPort().c_str()); 1165c497a3SShuo Chen ::write(sockfd, "How are you?\n", 13); 1265c497a3SShuo Chen muduo::sockets::close(sockfd); 1365c497a3SShuo Chen} 1465c497a3SShuo Chen 1565c497a3SShuo Chenint main() 1665c497a3SShuo Chen{ 1765c497a3SShuo Chen printf("main(): pid = %d\n", getpid()); 1865c497a3SShuo Chen 1965c497a3SShuo Chen muduo::InetAddress listenAddr(9981); 2065c497a3SShuo Chen muduo::EventLoop loop; 2165c497a3SShuo Chen 2265c497a3SShuo Chen muduo::Acceptor acceptor(&loop, listenAddr); 2365c497a3SShuo Chen acceptor.setNewConnectionCallback(newConnection); 2465c497a3SShuo Chen acceptor.listen(); 2565c497a3SShuo Chen 2665c497a3SShuo Chen loop.loop(); 2765c497a3SShuo Chen} 28