140161064SShuo Chen// excerpts from http://code.google.com/p/muduo/ 240161064SShuo Chen// 340161064SShuo Chen// Use of this source code is governed by a BSD-style license 440161064SShuo Chen// that can be found in the License file. 540161064SShuo Chen// 640161064SShuo Chen// Author: Shuo Chen (chenshuo at chenshuo dot com) 740161064SShuo Chen 840161064SShuo Chen#ifndef MUDUO_NET_ACCEPTOR_H 940161064SShuo Chen#define MUDUO_NET_ACCEPTOR_H 1040161064SShuo Chen 1140161064SShuo Chen#include <boost/function.hpp> 1240161064SShuo Chen#include <boost/noncopyable.hpp> 1340161064SShuo Chen 1440161064SShuo Chen#include "Channel.h" 1540161064SShuo Chen#include "Socket.h" 1640161064SShuo Chen 1740161064SShuo Chennamespace muduo 1840161064SShuo Chen{ 1940161064SShuo Chen 2040161064SShuo Chenclass EventLoop; 2140161064SShuo Chenclass InetAddress; 2240161064SShuo Chen 2340161064SShuo Chen/// 2440161064SShuo Chen/// Acceptor of incoming TCP connections. 2540161064SShuo Chen/// 2640161064SShuo Chenclass Acceptor : boost::noncopyable 2740161064SShuo Chen{ 2840161064SShuo Chen public: 2940161064SShuo Chen typedef boost::function<void (int sockfd, 3040161064SShuo Chen const InetAddress&)> NewConnectionCallback; 3140161064SShuo Chen 3240161064SShuo Chen Acceptor(EventLoop* loop, const InetAddress& listenAddr); 3340161064SShuo Chen 3440161064SShuo Chen void setNewConnectionCallback(const NewConnectionCallback& cb) 3540161064SShuo Chen { newConnectionCallback_ = cb; } 3640161064SShuo Chen 3740161064SShuo Chen bool listenning() const { return listenning_; } 3840161064SShuo Chen void listen(); 3940161064SShuo Chen 4040161064SShuo Chen private: 4140161064SShuo Chen void handleRead(); 4240161064SShuo Chen 4340161064SShuo Chen EventLoop* loop_; 4440161064SShuo Chen Socket acceptSocket_; 4540161064SShuo Chen Channel acceptChannel_; 4640161064SShuo Chen NewConnectionCallback newConnectionCallback_; 4740161064SShuo Chen bool listenning_; 4840161064SShuo Chen}; 4940161064SShuo Chen 5040161064SShuo Chen} 5140161064SShuo Chen 5240161064SShuo Chen#endif // MUDUO_NET_ACCEPTOR_H 53