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