// excerpts from http://code.google.com/p/muduo/ // // Use of this source code is governed by a BSD-style license // that can be found in the License file. // // Author: Shuo Chen (chenshuo at chenshuo dot com) #ifndef MUDUO_NET_TCPSERVER_H #define MUDUO_NET_TCPSERVER_H #include "Callbacks.h" #include "TcpConnection.h" #include #include #include namespace muduo { class Acceptor; class EventLoop; class TcpServer : boost::noncopyable { public: TcpServer(EventLoop* loop, const InetAddress& listenAddr); ~TcpServer(); // force out-line dtor, for scoped_ptr members. /// Starts the server if it's not listenning. /// /// It's harmless to call it multiple times. /// Thread safe. void start(); /// Set connection callback. /// Not thread safe. void setConnectionCallback(const ConnectionCallback& cb) { connectionCallback_ = cb; } /// Set message callback. /// Not thread safe. void setMessageCallback(const MessageCallback& cb) { messageCallback_ = cb; } + /// Set write complete callback. + /// Not thread safe. + void setWriteCompleteCallback(const WriteCompleteCallback& cb) + { writeCompleteCallback_ = cb; } + private: /// Not thread safe, but in loop void newConnection(int sockfd, const InetAddress& peerAddr); void removeConnection(const TcpConnectionPtr& conn); typedef std::map ConnectionMap; EventLoop* loop_; // the acceptor loop const std::string name_; boost::scoped_ptr acceptor_; // avoid revealing Acceptor ConnectionCallback connectionCallback_; MessageCallback messageCallback_; + WriteCompleteCallback writeCompleteCallback_; bool started_; int nextConnId_; // always in loop thread ConnectionMap connections_; }; } #endif // MUDUO_NET_TCPSERVER_H