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