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