19a1e991dSShuo Chen// excerpts from http://code.google.com/p/muduo/ 29a1e991dSShuo Chen// 39a1e991dSShuo Chen// Use of this source code is governed by a BSD-style license 49a1e991dSShuo Chen// that can be found in the License file. 59a1e991dSShuo Chen// 69a1e991dSShuo Chen// Author: Shuo Chen (chenshuo at chenshuo dot com) 79a1e991dSShuo Chen 89a1e991dSShuo Chen#ifndef MUDUO_NET_ACCEPTOR_H 99a1e991dSShuo Chen#define MUDUO_NET_ACCEPTOR_H 109a1e991dSShuo Chen 119a1e991dSShuo Chen#include <boost/function.hpp> 129a1e991dSShuo Chen#include <boost/noncopyable.hpp> 139a1e991dSShuo Chen 149a1e991dSShuo Chen#include "Channel.h" 159a1e991dSShuo Chen#include "Socket.h" 169a1e991dSShuo Chen 179a1e991dSShuo Chennamespace muduo 189a1e991dSShuo Chen{ 199a1e991dSShuo Chen 209a1e991dSShuo Chenclass EventLoop; 219a1e991dSShuo Chenclass InetAddress; 229a1e991dSShuo Chen 239a1e991dSShuo Chen/// 249a1e991dSShuo Chen/// Acceptor of incoming TCP connections. 259a1e991dSShuo Chen/// 269a1e991dSShuo Chenclass Acceptor : boost::noncopyable 279a1e991dSShuo Chen{ 289a1e991dSShuo Chen public: 299a1e991dSShuo Chen typedef boost::function<void (int sockfd, 309a1e991dSShuo Chen const InetAddress&)> NewConnectionCallback; 319a1e991dSShuo Chen 329a1e991dSShuo Chen Acceptor(EventLoop* loop, const InetAddress& listenAddr); 339a1e991dSShuo Chen 349a1e991dSShuo Chen void setNewConnectionCallback(const NewConnectionCallback& cb) 359a1e991dSShuo Chen { newConnectionCallback_ = cb; } 369a1e991dSShuo Chen 379a1e991dSShuo Chen bool listenning() const { return listenning_; } 389a1e991dSShuo Chen void listen(); 399a1e991dSShuo Chen 409a1e991dSShuo Chen private: 419a1e991dSShuo Chen void handleRead(); 429a1e991dSShuo Chen 439a1e991dSShuo Chen EventLoop* loop_; 449a1e991dSShuo Chen Socket acceptSocket_; 459a1e991dSShuo Chen Channel acceptChannel_; 469a1e991dSShuo Chen NewConnectionCallback newConnectionCallback_; 479a1e991dSShuo Chen bool listenning_; 489a1e991dSShuo Chen}; 499a1e991dSShuo Chen 509a1e991dSShuo Chen} 519a1e991dSShuo Chen 529a1e991dSShuo Chen#endif // MUDUO_NET_ACCEPTOR_H 53