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