00001 // $Id: FileHandle.ih 1742 2010-11-04 14:51:56Z g0dil $ 00002 // 00003 // Copyright (C) 2006 00004 // Fraunhofer (FOKUS) 00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY 00006 // Stefan Bund <g0dil@berlios.de> 00007 // 00008 // This program is free software; you can redistribute it and/or modify 00009 // it under the terms of the GNU General Public License as published by 00010 // the Free Software Foundation; either version 2 of the License, or 00011 // (at your option) any later version. 00012 // 00013 // This program is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 // GNU General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU General Public License 00019 // along with this program; if not, write to the 00020 // Free Software Foundation, Inc., 00021 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00022 00027 #ifndef IH_SENF_Socket_FileHandle_ 00028 #define IH_SENF_Socket_FileHandle_ 1 00029 00030 // Custom includes 00031 #include <boost/intrusive_ptr.hpp> 00032 #include <senf/Utils/intrusive_refcount.hh> 00033 #include <senf/Utils/pool_alloc_mixin.hh> 00034 00035 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00036 00037 namespace senf { 00038 00039 class FileHandle; 00040 00067 class FileBody 00068 : public senf::intrusive_refcount, 00069 public senf::pool_alloc_mixin<FileBody> 00070 { 00071 public: 00072 //-///////////////////////////////////////////////////////////////////////////////////////// 00073 // Types 00074 00075 typedef boost::intrusive_ptr<FileBody> ptr; 00076 00077 //-///////////////////////////////////////////////////////////////////////////////////////// 00079 //\{ 00080 00081 explicit FileBody(int fd=-1); 00082 00086 virtual ~FileBody(); 00087 00088 // NO DESTRUCTOR HERE (that is, only an empty virtual destructor) - destructors and virtual 00089 // functions don't mix. What would be in the the destructor is in 'destroyClose()' which is 00090 // called from FileHandle::~FileHandle() *before* the last handle dies. 00091 00092 // no copy 00093 // no conversion constructors 00094 00095 //\} 00096 //-///////////////////////////////////////////////////////////////////////////////////////// 00097 00098 FileHandle handle(); 00099 00100 int fd() const; 00101 void fd(int fd); 00102 00103 void close(); 00104 void terminate(); 00105 void destroyClose(); 00106 00107 bool readable() const; 00108 bool waitReadable(senf::ClockService::clock_type timeout) const; 00109 bool writeable() const; 00110 bool waitWriteable(senf::ClockService::clock_type timeout) const; 00111 bool oobReadable() const; 00112 bool waitOOBReadable(senf::ClockService::clock_type timeout) const; 00113 00114 bool blocking() const; 00115 void blocking(bool status); 00116 00117 bool eof() const; 00118 bool valid() const; 00119 00120 private: 00121 //-///////////////////////////////////////////////////////////////////////////////////////// 00122 // Virtual interface for subclasses to override 00123 00124 virtual void v_close(); 00125 00132 virtual void v_terminate(); 00133 00137 virtual bool v_eof() const; 00138 virtual bool v_valid() const; 00139 00142 protected: 00143 00144 private: 00145 bool pollCheck(int fd, bool incoming, int timeout, bool oob=false) const; 00146 00147 int fd_; 00148 }; 00149 00150 } 00151 00152 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00153 #endif 00154 00155 00156 // Local Variables: 00157 // mode: c++ 00158 // fill-column: 100 00159 // c-file-style: "senf" 00160 // indent-tabs-mode: nil 00161 // ispell-local-dictionary: "american" 00162 // compile-command: "scons -u test" 00163 // comment-column: 40 00164 // End: