test7.cc revision 354280cf
1354280cfSShuo Chen#include "Acceptor.h" 2354280cfSShuo Chen#include "EventLoop.h" 3354280cfSShuo Chen#include "InetAddress.h" 4354280cfSShuo Chen#include "SocketsOps.h" 5354280cfSShuo Chen#include <stdio.h> 6354280cfSShuo Chen 7354280cfSShuo Chenvoid newConnection(int sockfd, const muduo::InetAddress& peerAddr) 8354280cfSShuo Chen{ 9354280cfSShuo Chen printf("newConnection(): accepted a new connection from %s\n", 10354280cfSShuo Chen peerAddr.toHostPort().c_str()); 11354280cfSShuo Chen ::write(sockfd, "How are you?\n", 13); 12354280cfSShuo Chen muduo::sockets::close(sockfd); 13354280cfSShuo Chen} 14354280cfSShuo Chen 15354280cfSShuo Chenint main() 16354280cfSShuo Chen{ 17354280cfSShuo Chen printf("main(): pid = %d\n", getpid()); 18354280cfSShuo Chen 19354280cfSShuo Chen muduo::InetAddress listenAddr(9981); 20354280cfSShuo Chen muduo::EventLoop loop; 21354280cfSShuo Chen 22354280cfSShuo Chen muduo::Acceptor acceptor(&loop, listenAddr); 23354280cfSShuo Chen acceptor.setNewConnectionCallback(newConnection); 24354280cfSShuo Chen acceptor.listen(); 25354280cfSShuo Chen 26354280cfSShuo Chen loop.loop(); 27354280cfSShuo Chen} 28