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