Line data Source code
1 : //
2 : // Author: Vladimir Migashko <migashko@gmail.com>, (C) 2012
3 : //
4 : // Copyright: See COPYING file that comes with this distribution
5 : //
6 :
7 : #ifndef VSET_VSET_BUFFER_PERSISTENT_FILE_AD_CLOSE_FILE_HPP
8 : #define VSET_VSET_BUFFER_PERSISTENT_FILE_AD_CLOSE_FILE_HPP
9 :
10 : #include <vset/buffer/tags.hpp>
11 : #include <vset/buffer/persistent/tags.hpp>
12 :
13 : #include <fcntl.h>
14 : #include <unistd.h>
15 : #include <stdexcept>
16 : #include <errno.h>
17 : #include <string.h>
18 :
19 : namespace vset { namespace buffer { namespace persistent{ namespace file{
20 :
21 12 : struct ad_close_file
22 : {
23 : template<typename T>
24 48 : void operator()( T& t )
25 : {
26 48 : if ( t.get_aspect().template get<_descriptor_>() == 0 )
27 12 : t.get_aspect().template get<_descriptor_>() = -1;
28 :
29 48 : if ( t.get_aspect().template get<_descriptor_>() != -1 )
30 : {
31 19 : int result = ::close( t.get_aspect().template get<_descriptor_>() );
32 19 : t.get_aspect().template get<_descriptor_>() = -1;
33 19 : t.get_aspect().template get<_file_status_>() = false;
34 19 : if ( result == -1 )
35 0 : throw std::runtime_error(strerror(errno));
36 : }
37 48 : }
38 :
39 : };
40 :
41 : }}}}
42 :
43 : #endif
|