1b37003a7SShuo Chen// excerpts from http://code.google.com/p/muduo/ 2b37003a7SShuo Chen// 3b37003a7SShuo Chen// Use of this source code is governed by a BSD-style license 4b37003a7SShuo Chen// that can be found in the License file. 5b37003a7SShuo Chen// 6b37003a7SShuo Chen// Author: Shuo Chen (chenshuo at chenshuo dot com) 7b37003a7SShuo Chen 8b37003a7SShuo Chen#ifndef MUDUO_NET_ACCEPTOR_H 9b37003a7SShuo Chen#define MUDUO_NET_ACCEPTOR_H 10b37003a7SShuo Chen 11b37003a7SShuo Chen#include <boost/function.hpp> 12b37003a7SShuo Chen#include <boost/noncopyable.hpp> 13b37003a7SShuo Chen 14b37003a7SShuo Chen#include "Channel.h" 15b37003a7SShuo Chen#include "Socket.h" 16b37003a7SShuo Chen 17b37003a7SShuo Chennamespace muduo 18b37003a7SShuo Chen{ 19b37003a7SShuo Chen 20b37003a7SShuo Chenclass EventLoop; 21b37003a7SShuo Chenclass InetAddress; 22b37003a7SShuo Chen 23b37003a7SShuo Chen/// 24b37003a7SShuo Chen/// Acceptor of incoming TCP connections. 25b37003a7SShuo Chen/// 26b37003a7SShuo Chenclass Acceptor : boost::noncopyable 27b37003a7SShuo Chen{ 28b37003a7SShuo Chen public: 29b37003a7SShuo Chen typedef boost::function<void (int sockfd, 30b37003a7SShuo Chen const InetAddress&)> NewConnectionCallback; 31b37003a7SShuo Chen 32b37003a7SShuo Chen Acceptor(EventLoop* loop, const InetAddress& listenAddr); 33b37003a7SShuo Chen 34b37003a7SShuo Chen void setNewConnectionCallback(const NewConnectionCallback& cb) 35b37003a7SShuo Chen { newConnectionCallback_ = cb; } 36b37003a7SShuo Chen 37b37003a7SShuo Chen bool listenning() const { return listenning_; } 38b37003a7SShuo Chen void listen(); 39b37003a7SShuo Chen 40b37003a7SShuo Chen private: 41b37003a7SShuo Chen void handleRead(); 42b37003a7SShuo Chen 43b37003a7SShuo Chen EventLoop* loop_; 44b37003a7SShuo Chen Socket acceptSocket_; 45b37003a7SShuo Chen Channel acceptChannel_; 46b37003a7SShuo Chen NewConnectionCallback newConnectionCallback_; 47b37003a7SShuo Chen bool listenning_; 48b37003a7SShuo Chen}; 49b37003a7SShuo Chen 50b37003a7SShuo Chen} 51b37003a7SShuo Chen 52b37003a7SShuo Chen#endif // MUDUO_NET_ACCEPTOR_H 53