12a18e699SShuo Chen// excerpts from http://code.google.com/p/muduo/
22a18e699SShuo Chen//
32a18e699SShuo Chen// Use of this source code is governed by a BSD-style license
42a18e699SShuo Chen// that can be found in the License file.
52a18e699SShuo Chen//
62a18e699SShuo Chen// Author: Shuo Chen (chenshuo at chenshuo dot com)
72a18e699SShuo Chen
82a18e699SShuo Chen#ifndef MUDUO_NET_ACCEPTOR_H
92a18e699SShuo Chen#define MUDUO_NET_ACCEPTOR_H
102a18e699SShuo Chen
112a18e699SShuo Chen#include <boost/function.hpp>
122a18e699SShuo Chen#include <boost/noncopyable.hpp>
132a18e699SShuo Chen
142a18e699SShuo Chen#include "Channel.h"
152a18e699SShuo Chen#include "Socket.h"
162a18e699SShuo Chen
172a18e699SShuo Chennamespace muduo
182a18e699SShuo Chen{
192a18e699SShuo Chen
202a18e699SShuo Chenclass EventLoop;
212a18e699SShuo Chenclass InetAddress;
222a18e699SShuo Chen
232a18e699SShuo Chen///
242a18e699SShuo Chen/// Acceptor of incoming TCP connections.
252a18e699SShuo Chen///
262a18e699SShuo Chenclass Acceptor : boost::noncopyable
272a18e699SShuo Chen{
282a18e699SShuo Chen public:
292a18e699SShuo Chen  typedef boost::function<void (int sockfd,
302a18e699SShuo Chen                                const InetAddress&)> NewConnectionCallback;
312a18e699SShuo Chen
322a18e699SShuo Chen  Acceptor(EventLoop* loop, const InetAddress& listenAddr);
332a18e699SShuo Chen
342a18e699SShuo Chen  void setNewConnectionCallback(const NewConnectionCallback& cb)
352a18e699SShuo Chen  { newConnectionCallback_ = cb; }
362a18e699SShuo Chen
372a18e699SShuo Chen  bool listenning() const { return listenning_; }
382a18e699SShuo Chen  void listen();
392a18e699SShuo Chen
402a18e699SShuo Chen private:
412a18e699SShuo Chen  void handleRead();
422a18e699SShuo Chen
432a18e699SShuo Chen  EventLoop* loop_;
442a18e699SShuo Chen  Socket acceptSocket_;
452a18e699SShuo Chen  Channel acceptChannel_;
462a18e699SShuo Chen  NewConnectionCallback newConnectionCallback_;
472a18e699SShuo Chen  bool listenning_;
482a18e699SShuo Chen};
492a18e699SShuo Chen
502a18e699SShuo Chen}
512a18e699SShuo Chen
522a18e699SShuo Chen#endif  // MUDUO_NET_ACCEPTOR_H
53