test7.cc revision 40161064
140161064SShuo Chen#include "Acceptor.h" 240161064SShuo Chen#include "EventLoop.h" 340161064SShuo Chen#include "InetAddress.h" 440161064SShuo Chen#include "SocketsOps.h" 540161064SShuo Chen#include <stdio.h> 640161064SShuo Chen 740161064SShuo Chenvoid newConnection(int sockfd, const muduo::InetAddress& peerAddr) 840161064SShuo Chen{ 940161064SShuo Chen printf("newConnection(): accepted a new connection from %s\n", 1040161064SShuo Chen peerAddr.toHostPort().c_str()); 1140161064SShuo Chen ::write(sockfd, "How are you?\n", 13); 1240161064SShuo Chen muduo::sockets::close(sockfd); 1340161064SShuo Chen} 1440161064SShuo Chen 1540161064SShuo Chenint main() 1640161064SShuo Chen{ 1740161064SShuo Chen printf("main(): pid = %d\n", getpid()); 1840161064SShuo Chen 1940161064SShuo Chen muduo::InetAddress listenAddr(9981); 2040161064SShuo Chen muduo::EventLoop loop; 2140161064SShuo Chen 2240161064SShuo Chen muduo::Acceptor acceptor(&loop, listenAddr); 2340161064SShuo Chen acceptor.setNewConnectionCallback(newConnection); 2440161064SShuo Chen acceptor.listen(); 2540161064SShuo Chen 2640161064SShuo Chen loop.loop(); 2740161064SShuo Chen} 28