Acceptor.h revision e2512892
1efbfdb0cSShuo Chen#pragma once 2efbfdb0cSShuo Chen#include "Common.h" 3efbfdb0cSShuo Chen#include "Socket.h" 4efbfdb0cSShuo Chen 5efbfdb0cSShuo Chen#include <memory> 6efbfdb0cSShuo Chen 7efbfdb0cSShuo Chenclass InetAddress; 8efbfdb0cSShuo Chen 9efbfdb0cSShuo Chenclass TcpStream; 10efbfdb0cSShuo Chentypedef std::unique_ptr<TcpStream> TcpStreamPtr; 11efbfdb0cSShuo Chen 12efbfdb0cSShuo Chenclass Acceptor : noncopyable 13efbfdb0cSShuo Chen{ 14efbfdb0cSShuo Chen public: 15efbfdb0cSShuo Chen explicit Acceptor(const InetAddress& listenAddr); 16efbfdb0cSShuo Chen 17efbfdb0cSShuo Chen ~Acceptor() = default; 18efbfdb0cSShuo Chen Acceptor(Acceptor&&) = default; 19efbfdb0cSShuo Chen Acceptor& operator=(Acceptor&&) = default; 20efbfdb0cSShuo Chen 21355c2bf7SShuo Chen // thread safe 22efbfdb0cSShuo Chen TcpStreamPtr accept(); 23e2512892SShuo Chen Socket acceptSocketOrDie(); 24efbfdb0cSShuo Chen 25efbfdb0cSShuo Chen private: 26efbfdb0cSShuo Chen Socket listenSock_; 27efbfdb0cSShuo Chen}; 28efbfdb0cSShuo Chen 29efbfdb0cSShuo Chen 30