165c497a3SShuo Chen// excerpts from http://code.google.com/p/muduo/
265c497a3SShuo Chen//
365c497a3SShuo Chen// Use of this source code is governed by a BSD-style license
465c497a3SShuo Chen// that can be found in the License file.
565c497a3SShuo Chen//
665c497a3SShuo Chen// Author: Shuo Chen (chenshuo at chenshuo dot com)
765c497a3SShuo Chen
865c497a3SShuo Chen#ifndef MUDUO_NET_ACCEPTOR_H
965c497a3SShuo Chen#define MUDUO_NET_ACCEPTOR_H
1065c497a3SShuo Chen
1165c497a3SShuo Chen#include <boost/function.hpp>
1265c497a3SShuo Chen#include <boost/noncopyable.hpp>
1365c497a3SShuo Chen
1465c497a3SShuo Chen#include "Channel.h"
1565c497a3SShuo Chen#include "Socket.h"
1665c497a3SShuo Chen
1765c497a3SShuo Chennamespace muduo
1865c497a3SShuo Chen{
1965c497a3SShuo Chen
2065c497a3SShuo Chenclass EventLoop;
2165c497a3SShuo Chenclass InetAddress;
2265c497a3SShuo Chen
2365c497a3SShuo Chen///
2465c497a3SShuo Chen/// Acceptor of incoming TCP connections.
2565c497a3SShuo Chen///
2665c497a3SShuo Chenclass Acceptor : boost::noncopyable
2765c497a3SShuo Chen{
2865c497a3SShuo Chen public:
2965c497a3SShuo Chen  typedef boost::function<void (int sockfd,
3065c497a3SShuo Chen                                const InetAddress&)> NewConnectionCallback;
3165c497a3SShuo Chen
3265c497a3SShuo Chen  Acceptor(EventLoop* loop, const InetAddress& listenAddr);
3365c497a3SShuo Chen
3465c497a3SShuo Chen  void setNewConnectionCallback(const NewConnectionCallback& cb)
3565c497a3SShuo Chen  { newConnectionCallback_ = cb; }
3665c497a3SShuo Chen
3765c497a3SShuo Chen  bool listenning() const { return listenning_; }
3865c497a3SShuo Chen  void listen();
3965c497a3SShuo Chen
4065c497a3SShuo Chen private:
4165c497a3SShuo Chen  void handleRead();
4265c497a3SShuo Chen
4365c497a3SShuo Chen  EventLoop* loop_;
4465c497a3SShuo Chen  Socket acceptSocket_;
4565c497a3SShuo Chen  Channel acceptChannel_;
4665c497a3SShuo Chen  NewConnectionCallback newConnectionCallback_;
4765c497a3SShuo Chen  bool listenning_;
4865c497a3SShuo Chen};
4965c497a3SShuo Chen
5065c497a3SShuo Chen}
5165c497a3SShuo Chen
5265c497a3SShuo Chen#endif  // MUDUO_NET_ACCEPTOR_H
53