git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@129 270642c3-0616-0410...
[senf.git] / Socket / FileHandle.ih
1 // $Id$
2 //
3 // Copyright (C) 2006 
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 #ifndef IH_FileHandle_
24 #define IH_FileHandle_ 1
25
26 // Custom includes
27 #include <boost/intrusive_ptr.hpp>
28 #include "Utils/intrusive_refcount.hh"
29
30 ///////////////////////////////ih.p////////////////////////////////////////
31
32 namespace satcom {
33 namespace lib {
34
35     /** \brief
36       */
37     class FileBody
38         : public satcom::lib::intrusive_refcount
39     {
40     public:
41         ///////////////////////////////////////////////////////////////////////////
42         // Types
43         
44         typedef boost::intrusive_ptr<FileBody> ptr;
45
46         ///////////////////////////////////////////////////////////////////////////
47         ///\name Structors and default members
48         ///@{
49         
50         explicit FileBody(int fd=-1);
51         virtual ~FileBody();
52
53         // no copy
54         // no conversion constructors
55
56         ///@}
57         ///////////////////////////////////////////////////////////////////////////
58
59         int fd() const;
60         void fd(int fd);
61
62         void close();
63         void terminate();
64
65         bool readable() const;
66         void waitReadable() const;
67         bool writeable() const;
68         void waitWriteable() const;
69
70         bool blocking() const;
71         void blocking(bool status);
72
73         bool eof() const;
74         bool valid() const;
75         
76     private:
77         ///////////////////////////////////////////////////////////////////////////
78         // Virtual interface for subclasses to override
79
80         virtual void v_close();
81         virtual void v_terminate();
82         virtual bool v_eof() const;
83         virtual bool v_valid() const;
84         
85
86     protected:
87         
88     private:
89         bool pollCheck(int fd, bool incoming, bool block=false) const;
90
91         int fd_;
92     };
93
94 }}
95
96 ///////////////////////////////ih.e////////////////////////////////////////
97 #endif
98
99 \f
100 // Local Variables:
101 // mode: c++
102 // c-file-style: "satcom"
103 // End: