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