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