s08-s07-Socket.h.diff revision 1bc8a9df
11bc8a9dfSShuo Chen // Copyright 2010, Shuo Chen. All rights reserved. 21bc8a9dfSShuo Chen // http://code.google.com/p/muduo/ 31bc8a9dfSShuo Chen // 41bc8a9dfSShuo Chen // Use of this source code is governed by a BSD-style license 51bc8a9dfSShuo Chen // that can be found in the License file. 61bc8a9dfSShuo Chen 71bc8a9dfSShuo Chen // Author: Shuo Chen (chenshuo at chenshuo dot com) 81bc8a9dfSShuo Chen // 91bc8a9dfSShuo Chen // This is an internal header file, you should not include this. 101bc8a9dfSShuo Chen 111bc8a9dfSShuo Chen #ifndef MUDUO_NET_SOCKET_H 121bc8a9dfSShuo Chen #define MUDUO_NET_SOCKET_H 131bc8a9dfSShuo Chen 141bc8a9dfSShuo Chen #include <boost/noncopyable.hpp> 151bc8a9dfSShuo Chen 161bc8a9dfSShuo Chen namespace muduo 171bc8a9dfSShuo Chen { 181bc8a9dfSShuo Chen 191bc8a9dfSShuo Chen class InetAddress; 201bc8a9dfSShuo Chen 211bc8a9dfSShuo Chen /// 221bc8a9dfSShuo Chen /// Wrapper of socket file descriptor. 231bc8a9dfSShuo Chen /// 241bc8a9dfSShuo Chen /// It closes the sockfd when desctructs. 251bc8a9dfSShuo Chen /// It's thread safe, all operations are delagated to OS. 261bc8a9dfSShuo Chen class Socket : boost::noncopyable 271bc8a9dfSShuo Chen { 281bc8a9dfSShuo Chen public: 291bc8a9dfSShuo Chen explicit Socket(int sockfd) 301bc8a9dfSShuo Chen : sockfd_(sockfd) 311bc8a9dfSShuo Chen { } 321bc8a9dfSShuo Chen 331bc8a9dfSShuo Chen ~Socket(); 341bc8a9dfSShuo Chen 351bc8a9dfSShuo Chen int fd() const { return sockfd_; } 361bc8a9dfSShuo Chen 371bc8a9dfSShuo Chen /// abort if address in use 381bc8a9dfSShuo Chen void bindAddress(const InetAddress& localaddr); 391bc8a9dfSShuo Chen /// abort if address in use 401bc8a9dfSShuo Chen void listen(); 411bc8a9dfSShuo Chen 421bc8a9dfSShuo Chen /// On success, returns a non-negative integer that is 431bc8a9dfSShuo Chen /// a descriptor for the accepted socket, which has been 441bc8a9dfSShuo Chen /// set to non-blocking and close-on-exec. *peeraddr is assigned. 451bc8a9dfSShuo Chen /// On error, -1 is returned, and *peeraddr is untouched. 461bc8a9dfSShuo Chen int accept(InetAddress* peeraddr); 471bc8a9dfSShuo Chen 481bc8a9dfSShuo Chen /// 491bc8a9dfSShuo Chen /// Enable/disable SO_REUSEADDR 501bc8a9dfSShuo Chen /// 511bc8a9dfSShuo Chen void setReuseAddr(bool on); 521bc8a9dfSShuo Chen 531bc8a9dfSShuo Chen+ void shutdownWrite(); 541bc8a9dfSShuo Chen+ 551bc8a9dfSShuo Chen+ /// 561bc8a9dfSShuo Chen+ /// Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm). 571bc8a9dfSShuo Chen+ /// 581bc8a9dfSShuo Chen+ void setTcpNoDelay(bool on); 591bc8a9dfSShuo Chen+ 601bc8a9dfSShuo Chen private: 611bc8a9dfSShuo Chen const int sockfd_; 621bc8a9dfSShuo Chen }; 631bc8a9dfSShuo Chen 641bc8a9dfSShuo Chen } 651bc8a9dfSShuo Chen #endif // MUDUO_NET_SOCKET_H 66