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