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