1354280cfSShuo Chen// excerpts from http://code.google.com/p/muduo/
2354280cfSShuo Chen//
3354280cfSShuo Chen// Use of this source code is governed by a BSD-style license
4354280cfSShuo Chen// that can be found in the License file.
5354280cfSShuo Chen//
6354280cfSShuo Chen// Author: Shuo Chen (chenshuo at chenshuo dot com)
7354280cfSShuo Chen
8354280cfSShuo Chen#ifndef MUDUO_NET_ACCEPTOR_H
9354280cfSShuo Chen#define MUDUO_NET_ACCEPTOR_H
10354280cfSShuo Chen
11354280cfSShuo Chen#include <boost/function.hpp>
12354280cfSShuo Chen#include <boost/noncopyable.hpp>
13354280cfSShuo Chen
14354280cfSShuo Chen#include "Channel.h"
15354280cfSShuo Chen#include "Socket.h"
16354280cfSShuo Chen
17354280cfSShuo Chennamespace muduo
18354280cfSShuo Chen{
19354280cfSShuo Chen
20354280cfSShuo Chenclass EventLoop;
21354280cfSShuo Chenclass InetAddress;
22354280cfSShuo Chen
23354280cfSShuo Chen///
24354280cfSShuo Chen/// Acceptor of incoming TCP connections.
25354280cfSShuo Chen///
26354280cfSShuo Chenclass Acceptor : boost::noncopyable
27354280cfSShuo Chen{
28354280cfSShuo Chen public:
29354280cfSShuo Chen  typedef boost::function<void (int sockfd,
30354280cfSShuo Chen                                const InetAddress&)> NewConnectionCallback;
31354280cfSShuo Chen
32354280cfSShuo Chen  Acceptor(EventLoop* loop, const InetAddress& listenAddr);
33354280cfSShuo Chen
34354280cfSShuo Chen  void setNewConnectionCallback(const NewConnectionCallback& cb)
35354280cfSShuo Chen  { newConnectionCallback_ = cb; }
36354280cfSShuo Chen
37354280cfSShuo Chen  bool listenning() const { return listenning_; }
38354280cfSShuo Chen  void listen();
39354280cfSShuo Chen
40354280cfSShuo Chen private:
41354280cfSShuo Chen  void handleRead();
42354280cfSShuo Chen
43354280cfSShuo Chen  EventLoop* loop_;
44354280cfSShuo Chen  Socket acceptSocket_;
45354280cfSShuo Chen  Channel acceptChannel_;
46354280cfSShuo Chen  NewConnectionCallback newConnectionCallback_;
47354280cfSShuo Chen  bool listenning_;
48354280cfSShuo Chen};
49354280cfSShuo Chen
50354280cfSShuo Chen}
51354280cfSShuo Chen
52354280cfSShuo Chen#endif  // MUDUO_NET_ACCEPTOR_H
53