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