text: // Copyright 2010, Shuo Chen.  All rights reserved.
  // http://code.google.com/p/muduo/
  //
  // Use of this source code is governed by a BSD-style license
  // that can be found in the License file.
  
  // Author: Shuo Chen (chenshuo at chenshuo dot com)
  //
  // This is an internal header file, you should not include this.
  
  #ifndef MUDUO_NET_ACCEPTOR_H
  #define MUDUO_NET_ACCEPTOR_H
  
  #include <functional>
  
  #include "muduo/net/Channel.h"
  #include "muduo/net/Socket.h"
  
  namespace muduo
  {
    namespace net
    {
  
      class EventLoop;
      class InetAddress;
  
      ///
      /// Acceptor of incoming TCP connections.
      ///
      class Acceptor : noncopyable
      {
      public:
        typedef std::function<void(int sockfd, const InetAddress &)> NewConnectionCallback;
  
        Acceptor(EventLoop *loop, const InetAddress &listenAddr, bool reuseport);
        ~Acceptor();
  
        void setNewConnectionCallback(const NewConnectionCallback &cb)
        {
          newConnectionCallback_ = cb;
        }
  
        void listen();
  
        bool listening() const { return listening_; }
  
        // Deprecated, use the correct spelling one above.
        // Leave the wrong spelling here in case one needs to grep it for error messages.
        // bool listenning() const { return listening(); }
  
      private:
        void handleRead();
  
        EventLoop *loop_;
        Socket acceptSocket_;   // listening socket（RAII 封装的 socket）
        Channel acceptChannel_; // 用来监听 listening socket 的 readable 事件，并回调 Acceptor::handleRead()，后者会调用 accept(2) 来接收新的连接，并回调用户callback
        NewConnectionCallback newConnectionCallback_;
        bool listening_;
        int idleFd_;
      };
  
    } // namespace net
  } // namespace muduo
  
  #endif // MUDUO_NET_ACCEPTOR_H
  