12a18e699SShuo Chen#include "Acceptor.h" 22a18e699SShuo Chen#include "EventLoop.h" 32a18e699SShuo Chen#include "InetAddress.h" 42a18e699SShuo Chen#include "SocketsOps.h" 52a18e699SShuo Chen#include <stdio.h> 62a18e699SShuo Chen 72a18e699SShuo Chenvoid newConnection(int sockfd, const muduo::InetAddress& peerAddr) 82a18e699SShuo Chen{ 92a18e699SShuo Chen printf("newConnection(): accepted a new connection from %s\n", 102a18e699SShuo Chen peerAddr.toHostPort().c_str()); 112a18e699SShuo Chen ::write(sockfd, "How are you?\n", 13); 122a18e699SShuo Chen muduo::sockets::close(sockfd); 132a18e699SShuo Chen} 142a18e699SShuo Chen 152a18e699SShuo Chenint main() 162a18e699SShuo Chen{ 172a18e699SShuo Chen printf("main(): pid = %d\n", getpid()); 182a18e699SShuo Chen 192a18e699SShuo Chen muduo::InetAddress listenAddr(9981); 202a18e699SShuo Chen muduo::EventLoop loop; 212a18e699SShuo Chen 222a18e699SShuo Chen muduo::Acceptor acceptor(&loop, listenAddr); 232a18e699SShuo Chen acceptor.setNewConnectionCallback(newConnection); 242a18e699SShuo Chen acceptor.listen(); 252a18e699SShuo Chen 262a18e699SShuo Chen loop.loop(); 272a18e699SShuo Chen} 28