19a1e991dSShuo Chen#include "Acceptor.h" 29a1e991dSShuo Chen#include "EventLoop.h" 39a1e991dSShuo Chen#include "InetAddress.h" 49a1e991dSShuo Chen#include "SocketsOps.h" 59a1e991dSShuo Chen#include <stdio.h> 69a1e991dSShuo Chen 79a1e991dSShuo Chenvoid newConnection(int sockfd, const muduo::InetAddress& peerAddr) 89a1e991dSShuo Chen{ 99a1e991dSShuo Chen printf("newConnection(): accepted a new connection from %s\n", 109a1e991dSShuo Chen peerAddr.toHostPort().c_str()); 119a1e991dSShuo Chen ::write(sockfd, "How are you?\n", 13); 129a1e991dSShuo Chen muduo::sockets::close(sockfd); 139a1e991dSShuo Chen} 149a1e991dSShuo Chen 159a1e991dSShuo Chenint main() 169a1e991dSShuo Chen{ 179a1e991dSShuo Chen printf("main(): pid = %d\n", getpid()); 189a1e991dSShuo Chen 199a1e991dSShuo Chen muduo::InetAddress listenAddr(9981); 209a1e991dSShuo Chen muduo::EventLoop loop; 219a1e991dSShuo Chen 229a1e991dSShuo Chen muduo::Acceptor acceptor(&loop, listenAddr); 239a1e991dSShuo Chen acceptor.setNewConnectionCallback(newConnection); 249a1e991dSShuo Chen acceptor.listen(); 259a1e991dSShuo Chen 269a1e991dSShuo Chen loop.loop(); 279a1e991dSShuo Chen} 28